plc4x icon indicating copy to clipboard operation
plc4x copied to clipboard

[Bug]: EIP only working with variables with an odd character count (in second path segment)

Open luedi128 opened this issue 1 year ago • 1 comments

What happened?

We have a Rockwell function block that is offering the following variables, that we want to read out.

The following request with eight variables showed that only one of them is working - the other caused INTERNAL_ERROR responses from the Rockwell PLC.

  readRequestBuilder = plcConnection.readRequestBuilder();
  readRequestBuilder.addTagAddress("v1", "xxx1.timestamp_xxxxxxx_OFF");   // ok - working
  readRequestBuilder.addTagAddress("v2", "xxx1.timestamp_xxxxxxx_ON"); // INTERNAL_ERROR

We have had a look at the CIP packages on network level and it looks like the size of the second path segment was wrongly calculated - the following part of the CIP with slot/address are not recognized as a valid part of CIP protocol in wireshark (screenshot attached).

For testing we renamed the last variable by adding an additional character at the end (in the FB and in the java code) e.g. xxx1.timestamp_xxxxxxx_ONN then everything worked fine. We have this situations with other variables as well (8 variables in our test - only have of them (the once with an even character count) are working - the others result in INTERNAL_ERRORs)

We have been able to fix the problem by changing org.apache.plc4x.java.eip.base.protocol.EipProtocolLogic.class in line 692 to: newSegment = new DataSegment(new AnsiExtendedSymbolSegment(identifier, (identifier.length() % 2 == 0) ? null : (short) 0)); More or less copy & paste from line 696/697.

From out point of view this is a bug in the path segment length calculation only affecting path variables with an odd character count (or second path segments with an odd character count).

Tested on a Rockwell 1769-L18ER/B LOGIX5318ER.

Version

v0.12.0

Programming Languages

  • [X] plc4j
  • [ ] plc4go
  • [ ] plc4c
  • [ ] plc4net

Protocols

  • [ ] AB-Ethernet
  • [ ] ADS /AMS
  • [ ] BACnet/IP
  • [ ] CANopen
  • [ ] DeltaV
  • [ ] DF1
  • [X] EtherNet/IP
  • [ ] Firmata
  • [ ] KNXnet/IP
  • [ ] Modbus
  • [ ] OPC-UA
  • [ ] S7

luedi128 avatar May 16 '24 06:05 luedi128

Wireshark screenshot.

plc4x_second_path_segment

luedi128 avatar May 16 '24 06:05 luedi128

Could you please try with the current SNAPSHOT version ... I am using the driver in my testsuite to talk to a real device and have both variables with and without odd lengths and it's working fine.

chrisdutz avatar Jul 12 '24 13:07 chrisdutz

I will get in touch with the Rockwell developer to provide the test setup again. Will test it then. Still it only happens with a segmented path. What are the names of your test variables?

luedi128 avatar Jul 18 '24 15:07 luedi128

So ... any update? Otherwise I'd close this issue next time I work on it (Probably next Friday)

chrisdutz avatar Jul 26 '24 15:07 chrisdutz

It will take some time until I have the test setup available and can test again (approx. 8 weeks).

What are the names of your test variables?

luedi128 avatar Jul 26 '24 16:07 luedi128

    ```
    ManualEipLogixDriverTest test = new ManualEipLogixDriverTest("logix://192.168.23.40");
    // This is the very limited number of types my controller supports.
    test.addTestCase("hurz_BOOL", new PlcBOOL(true));
    test.addTestCase("hurz_SINT", new PlcSINT(-42));
    test.addTestCase("hurz_INT", new PlcINT(-2424));
    test.addTestCase("hurz_DINT", new PlcDINT(-242442424));
    test.addTestCase("hurz_REAL", new PlcREAL(3.141593F));
    //test.addTestCase("hurz_UDT", new PlcStruct());

    long start = System.currentTimeMillis();
    test.run();
    long end = System.currentTimeMillis();
    System.out.printf("Finished in %d ms", end - start);

chrisdutz avatar Jul 26 '24 17:07 chrisdutz

As you can see, it contains both types of lengths (odd/even)

chrisdutz avatar Jul 26 '24 17:07 chrisdutz

Yes that worked for us as well. The situation only appears with segmented variables (variable names with a dot in the name, like a variable in a function block) xxx1.timestamp_xxxxxxx_ON

luedi128 avatar Jul 26 '24 17:07 luedi128

I think I had a look at this and the main reason is, that I think the version of the driver in the open-source project currently only supports (not sure if this is the right term) Global Variables that are not located in a function block.

However it is generally possible to read them, as I have done a private experiment with a completely rewritten version of the Logix driver and here I have tested this feature. Unfortunately I will not donate this work back without reasonable donations, which I described the reasons for in my last blog post.

chrisdutz avatar Jul 26 '24 17:07 chrisdutz

Now I have the test environment available again. I can still reproduce the situation with these two variables: xxx1.timestamp_xxxxxxx_ON xxx1.timestamp_xxxxxxx_OFF

How can I get a Snapshot-Version? You refer to 0.13.0-SNAPSHOT right? Are there compiled snapshot artifacts available?

luedi128 avatar Aug 15 '24 09:08 luedi128

This should explain hour to use snapshots https://plc4x.apache.org/users/getting-started/using-snapshots.html

chrisdutz avatar Aug 15 '24 09:08 chrisdutz

I just tested again with the current 0.13.0-SNAPSHOT (plc4j-driver-eip-0.13.0-20240814.165428-1.jar). I still see the same issue with the two function block variables with different name length (one odd one even). I can request both variables successful with the change above in the PR.

luedi128 avatar Aug 15 '24 11:08 luedi128

OK ... odd that I have no issues reading on my devices, but will have a look tomorrow afternoon (when I have my 4h of PLC4X for this week)

chrisdutz avatar Aug 15 '24 11:08 chrisdutz

And thanks for submitting a PR ... that's really highly appreciated ;-)

chrisdutz avatar Aug 15 '24 11:08 chrisdutz

Should be closed now after merging the corresponding PR:

chrisdutz avatar Aug 16 '24 11:08 chrisdutz