ModbusTCP with Strings

Doing the same as this thread here:

I need to send the following string:
<ID 0><CLR><WIN 0 0 287 31><POS 0 0><LJ><BL N><CS 0><GRN><T>Testing</T>
This needs to be terminated by a carriage return $0D in ascii.

Msg = '<ID 0><CLR><WIN 0 0 287 31><POS 0 0><LJ><BL N><CS 0><GRN><T>Testing2</T>' + chr(13) + chr(13)
length = len(Msg)
system.opc.writeValues('Ignition OPC UA Server',['[Sign]1.HRS11000:'+str(length)],[Msg])

ModbuCapture.pcapng (7.4 KB)

In the Wireshark capture, the characters are reverse byte order, and "Testing2" string does not work, but "Testing" does work. "Testing" is sent with the manufacturers tool running on the same computer as the gateway. "Testing2" is sent with the code above.

Does anyone have any great ideas about what is different in these packets? I see the CC 0D terminating string, but Ignition will not send the packet if I put in a chr(204) + chr(13) as the end of the string.

There's setting for that.

Just use a constant length. Ignition will null-pad.

Characters in jython are not bytes. They are unicode codepoints and will be encoded as bytes. I'm not sure what you need for this, perhaps a byte array.

If you cannot get this work, consider using my driver's system.opc.rawModbus() function.

Yeah this bit has me curious. Wondering if there's some unicode roundtrip stuff going on, since this is a String he's writing to after all.

1 Like