ornl-epics / etherip

Java lib. for Ethernet/IP (AllenBradley ControlLogix, Compact Logix PLCs)
Eclipse Public License 1.0
112 stars 69 forks source link

Issues with getting an array from a tag. #6

Closed PlzDontKillDave closed 7 years ago

PlzDontKillDave commented 8 years ago

Hello

I have tried to get an array of Real or DINT by doing this:

CIPData cip = plc.readTag("Cycle_Data_Time[1]");

and it gives me this `Exception in thread "main" java.lang.NullPointerException at etherip.protocol.CIPReadDataProtocol.decode(CIPReadDataProtocol.java:43) at etherip.protocol.MessageRouterProtocol.decode(MessageRouterProtocol.java:103) at etherip.protocol.UnconnectedSendProtocol.decode(UnconnectedSendProtocol.java:92) at etherip.protocol.SendRRDataProtocol.decode(SendRRDataProtocol.java:94) at etherip.protocol.Encapsulation.decode(Encapsulation.java:190) at etherip.protocol.Connection.read(Connection.java:142) at etherip.protocol.Connection.execute(Connection.java:158) at etherip.EtherNetIP.readTag(EtherNetIP.java:153) at data_collection.Data_Collection.(Data_Collection.java:27)

It works fine when i do not use the brackets and it only gives me the first item in the array.

Am i missing something?

kasemir commented 8 years ago

I fixed that NPE but would need to test with actual array data to properly implement it. The "C"-based implementation that provided the information for this driver did read individual array elements via "Cycle_Data_Time[1]" as you tried, so I'm somewhat surprised that it doesn't work in the Java version.

Still, access to the whole array is about as fast as an individual array element, so the ideally just reading "Cycle_Data_Time" should return the complete array, and you then pick the elements that you want. .. but again reading arrays has not been tested with this version.

PlzDontKillDave commented 8 years ago

Now I get a null output when i try to do Cycle_Data_Time[1]. But I still only get the first element in the array when calling Cycle_Data_Time. In my plc Cycle_Data_Time is a DINT[65535] and in the example below Cycle_Data_Servo_Loc is a Real[65535]

CODE:

        EtherNetIP test = new EtherNetIP("10.90.119.128", 0);
        test.connect();

        CIPData cip = test.readTag("Cycle_Data_Servo_Loc");
        System.out.println(cip);
        System.out.println(cip.getElementCount());

        test.close();

OUTPUT:

          Jun 07, 2016 8:16:46 AM etherip.protocol.Connection <init>
          INFO: Connecting to 10.90.119.128:0xAF12
          Jun 07, 2016 8:16:46 AM etherip.EtherNetIP getDeviceInfo
          INFO: Device vendor=0x1, device_type=0xE, revision=0xC1C, serial=0xF940, name='1756-L85E/B'
          CIP_REAL (0x00CA): [0.002523]
          1

I have a different library that im using to read the PLC, but I like your method of returning data.

kasemir commented 8 years ago

You got the NPE and now the null value because the PLC returns an error code. Increase the log level to FINEST to see the complete protocol dump, including the error detail. Somewhat like this where the PLC returns CIP_ReadData_Reply .. status 0x4 Unknown tag or Path error:

Jun 06, 2016 5:24:35 PM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 42
UDINT session           : 0x1202D9D6
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Send RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0x00
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 26
MR Request
USINT service           : CM_Unconnected_Send (0x52)
USINT path              : Path (2 el) Class(0x20) 0x6 (ConnectionManager), instance(0x24) 1
CM_Unconnected_Send
USINT tick_time         : 10
USINT ticks             : -16
UINT message size       : 12
  \/\/\/ embedded message \/\/\/ (12 bytes)
MR Request
USINT service           : CIP_ReadData (0x4C)
USINT path              : Path Symbol(0x91) 'kay_ao'
USINT elements          : 1
  /\/\/\ embedded message /\/\/\
USINT path size         : 1 words
USINT reserved          : 0
USINT port 1, slot 0

Jun 06, 2016 5:24:35 PM etherip.protocol.Connection write
FINEST: Data sent (66 bytes):
0000 - 6F 00 2A 00 D6 D9 02 12 00 00 00 00 46 75 6E 73 - o.*.........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 1A 00 52 02 20 06 24 01 0A F0 - ........R. .$...
0030 - 0C 00 4C 04 91 06 6B 61 79 5F 61 6F 01 00 01 00 - ..L...kay_ao....
0040 - 01 00                                           - ..              

Jun 06, 2016 5:24:35 PM etherip.protocol.Connection read
FINEST: Data read (46 bytes):
0000 - 6F 00 16 00 D6 D9 02 12 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 06 00 CC 00 04 01 00 00       - ..............  

Jun 06, 2016 5:24:35 PM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 22
UDINT session           : 0x1202D9D6
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Received RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 6
MR Response
USINT service           : CIP_ReadData_Reply (0xCC)
USINT reserved          : 0x0
USINT status            : 0x4 (Unknown tag or Path error)
USINT ext. stat. size   : 0x1
USINT ext status        : 0x0 (<unknown>)
USINT type, data        : - nothing-

I somewhat suspect that your error will be 0x06: Buffer too small, partial data only. The PLC has an internal buffer limit around 500 bytes for this protocol, so reading a complete DINT[65535] won't be possible. See "PLC Buffer Limit" in https://github.com/EPICSTools/ether_ip/blob/master/ether_ipApp/doc/readme.txt for more on that.

PlzDontKillDave commented 8 years ago

Using the same code i had before heres the dump.

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection <init>
INFO: Connecting to 10.90.119.128:0xAF12
Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : ListServices (0x0004)
UINT  length            : 0
UDINT session           : 0x00000000
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (24 bytes):
0000 - 04 00 00 00 00 00 00 00 00 00 00 00 46 75 6E 73 - ............Funs
0010 - 74 75 66 66 00 00 00 00                         - tuff....        

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (50 bytes):
0000 - 04 00 1A 00 00 00 00 00 00 00 00 00 46 75 6E 73 - ............Funs
0010 - 74 75 66 66 00 00 00 00 01 00 00 01 14 00 01 00 - tuff............
0020 - 20 01 43 6F 6D 6D 75 6E 69 63 61 74 69 6F 6E 73 -  .Communications
0030 - 00 00                                           - ..              

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : ListServices (0x0004)
UINT  length            : 26
UDINT session           : 0x00000000
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
ListServices Reply
UINT count      : 1
Service 0:
UINT type       : 0x0100
UINT length     : 20
UINT version    : 0x0001
UINT flags      : 0x0120
UINT name[]     : Communications..

Jun 07, 2016 9:17:06 AM etherip.EtherNetIP listServices
FINE: Service: Communications..
Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : RegisterSession (0x0065)
UINT  length            : 4
UDINT session           : 0x00000000
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
USINT protocol  : 1
USINT options   : 0

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (28 bytes):
0000 - 65 00 04 00 00 00 00 00 00 00 00 00 46 75 6E 73 - e...........Funs
0010 - 74 75 66 66 00 00 00 00 01 00 00 00             - tuff........    

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (28 bytes):
0000 - 65 00 04 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - e...........Funs
0010 - 74 75 66 66 00 00 00 00 01 00 00 00             - tuff........    

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : RegisterSession (0x0065)
UINT  length            : 4
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 24
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Send RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0x00
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 8
MR Request
USINT service           : Get_Attribute_Single (0x0E)
USINT path              : Path (3 el) Class(0x20) 0x1 (Identity), instance(0x24) 1, attrib.(0x30) 0x1

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (48 bytes):
0000 - 6F 00 18 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 08 00 0E 03 20 01 24 01 30 01 - .......... .$.0.

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (46 bytes):
0000 - 6F 00 16 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 06 00 8E 00 00 00 01 00       - ..............  

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 22
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Received RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 6
MR Response
USINT service           : Get_Attribute_Single_Reply (0x8E)
USINT reserved          : 0x0
USINT status            : 0x0 (Ok)
USINT ext. stat. size   : 0x0
UINT value      : 1

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 24
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Send RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0x00
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 8
MR Request
USINT service           : Get_Attribute_Single (0x0E)
USINT path              : Path (3 el) Class(0x20) 0x1 (Identity), instance(0x24) 1, attrib.(0x30) 0x2

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (48 bytes):
0000 - 6F 00 18 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 08 00 0E 03 20 01 24 01 30 02 - .......... .$.0.

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (46 bytes):
0000 - 6F 00 16 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 06 00 8E 00 00 00 0E 00       - ..............  

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 22
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Received RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 6
MR Response
USINT service           : Get_Attribute_Single_Reply (0x8E)
USINT reserved          : 0x0
USINT status            : 0x0 (Ok)
USINT ext. stat. size   : 0x0
UINT value      : 14

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 24
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Send RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0x00
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 8
MR Request
USINT service           : Get_Attribute_Single (0x0E)
USINT path              : Path (3 el) Class(0x20) 0x1 (Identity), instance(0x24) 1, attrib.(0x30) 0x4

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (48 bytes):
0000 - 6F 00 18 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 08 00 0E 03 20 01 24 01 30 04 - .......... .$.0.

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (46 bytes):
0000 - 6F 00 16 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 06 00 8E 00 00 00 1C 0C       - ..............  

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 22
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Received RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 6
MR Response
USINT service           : Get_Attribute_Single_Reply (0x8E)
USINT reserved          : 0x0
USINT status            : 0x0 (Ok)
USINT ext. stat. size   : 0x0
UINT value      : 3100

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 24
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Send RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0x00
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 8
MR Request
USINT service           : Get_Attribute_Single (0x0E)
USINT path              : Path (3 el) Class(0x20) 0x1 (Identity), instance(0x24) 1, attrib.(0x30) 0x6

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (48 bytes):
0000 - 6F 00 18 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 08 00 0E 03 20 01 24 01 30 06 - .......... .$.0.

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (48 bytes):
0000 - 6F 00 18 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 08 00 8E 00 00 00 40 F9 CA 00 - ............@...

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 24
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Received RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 8
MR Response
USINT service           : Get_Attribute_Single_Reply (0x8E)
USINT reserved          : 0x0
USINT status            : 0x0 (Ok)
USINT ext. stat. size   : 0x0
UINT value      : -1728

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 24
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Send RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0x00
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 8
MR Request
USINT service           : Get_Attribute_Single (0x0E)
USINT path              : Path (3 el) Class(0x20) 0x1 (Identity), instance(0x24) 1, attrib.(0x30) 0x7

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (48 bytes):
0000 - 6F 00 18 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 08 00 0E 03 20 01 24 01 30 07 - .......... .$.0.

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (56 bytes):
0000 - 6F 00 20 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o. .........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 10 00 8E 00 00 00 0B 31 37 35 - .............175
0030 - 36 2D 4C 38 35 45 2F 42                         - 6-L85E/B        

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 32
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Received RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 16
MR Response
USINT service           : Get_Attribute_Single_Reply (0x8E)
USINT reserved          : 0x0
USINT status            : 0x0 (Ok)
USINT ext. stat. size   : 0x0
String value      : 1756-L85E/B

Jun 07, 2016 9:17:06 AM etherip.EtherNetIP getDeviceInfo
INFO: Device vendor=0x1, device_type=0xE, revision=0xC1C, serial=0xF940, name='1756-L85E/B'
Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 58
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Send RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0x00
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 42
MR Request
USINT service           : CM_Unconnected_Send (0x52)
USINT path              : Path (2 el) Class(0x20) 0x6 (ConnectionManager), instance(0x24) 1
CM_Unconnected_Send
USINT tick_time         : 10
USINT ticks             : -16
UINT message size       : 28
  \/\/\/ embedded message \/\/\/ (28 bytes)
MR Request
USINT service           : CIP_ReadData (0x4C)
USINT path              : Path Symbol(0x91) 'Cycle_Data_Servo_Loc_A'
USINT elements          : 1
  /\/\/\ embedded message /\/\/\
USINT path size         : 1 words
USINT reserved          : 0
USINT port 1, slot 0

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (82 bytes):
0000 - 6F 00 3A 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o.:.........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 2A 00 52 02 20 06 24 01 0A F0 - ......*.R. .$...
0030 - 1C 00 4C 0C 91 16 43 79 63 6C 65 5F 44 61 74 61 - ..L...Cycle_Data
0040 - 5F 53 65 72 76 6F 5F 4C 6F 63 5F 41 01 00 01 00 - _Servo_Loc_A....
0050 - 01 00                                           - ..              

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINEST: Data read (50 bytes):
0000 - 6F 00 1A 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - o...........Funs
0010 - 74 75 66 66 00 00 00 00 00 00 00 00 00 00 02 00 - tuff............
0020 - 00 00 00 00 B2 00 0A 00 CC 00 00 00 CA 00 EA 58 - ...............X
0030 - 25 3B                                           - %;              

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection read
FINER: Protocol Decoding
Encapsulation Header
UINT  command           : SendRRData (0x006F)
UINT  length            : 26
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000 (OK)
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000
Received RR Data
UDINT interface handle  : 0
UINT timeout            : 0
UINT count (addr., data): 2
UINT address type       : 0x0 (UCMM)
UINT address length     : 0
UINT data type          : 0xB2 (Unconnected Message)
UINT data length        : 10
MR Response
USINT service           : CIP_ReadData_Reply (0xCC)
USINT reserved          : 0x0
USINT status            : 0x0 (Ok)
USINT ext. stat. size   : 0x0
USINT type, data        : CIP_REAL (0x00CA): [0.002523]

CIP_REAL (0x00CA): [0.002523]
1
Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINER: Protocol Encoding
Encapsulation Header
UINT  command           : UnRegisterSession (0x0066)
UINT  length            : 0
UDINT session           : 0x00AF001B
UDINT status            : 0x00000000
USINT context[8]        : 'Funstuff'
UDINT options           : 0x00000000

Jun 07, 2016 9:17:06 AM etherip.protocol.Connection write
FINEST: Data sent (24 bytes):
0000 - 66 00 00 00 1B 00 AF 00 00 00 00 00 46 75 6E 73 - f...........Funs
0010 - 74 75 66 66 00 00 00 00                         - tuff....     
kasemir commented 8 years ago

OK, sorry, I see now why reading the complete array tag only returns the first element.

Check the code for EtherNetIP.readTag(String tag). It calls MRChipReadProtocol which calls CIPReadDataProtocol to construct the read request.

In CIPReadDataProtocol.encode() you'll find

        buf.putShort((short) 1); // elements

That's why it's always just reading one array element.

There needs to be a version of EtherNetIP.readTag(String tag) that has an additional , int elements parameter for the number of array elements to read, where the elements' are passed down so thatCIPReadDataProtocol.encode()` can then put something other than 1 into the read request.

--> Then you could read arrays, at least up to the ~500 byte buffer limit.

I believe the decoding already works, because CIPData has determineElementCount() to check how many array elements it received.

Feel free to add a EtherNetIP.readTag(String tag, int elements) and submit a pull request that I can merge.

Compared to the C version of this software, I'd still expect reading any single element via a tag name like "MyTag[42]" to work, so there you'd again need to check the error message.

kasemir commented 7 years ago

11 adds API for fetching more than just the first array element, for example MRChipReadProtocol(final String tag, short count)