Search code examples
c#serial-portasciimodbusplc

NModbus4 read TXT from PLC


I'm programming a Click PLC with a C# application with NModbus4. (RS232)

Now i'm trying to read and write TXT data.

This is the code and result: enter image description here

When I check the Click PLC software I can see that for each two chars one Modbus address is used.

enter image description here

How can I get the text saved in the PLC? Someone got an idea?
The text stored in the PLC is "Dit is tekst"


Solution

  • A Modbus register is 16-bit wide, so it can store two chars. This is why each two chars share the same address.

    That said, you need to infer the byte order used: how are the two chars stuffed into the register? Which one goes to the most significant byte?

    Take your example text, it has 12 chars, so reading 6 registers is enough (436865-436870). From your debug picture, address 436865 stores value 26948, 0x6944 when converted to hex. Find a ASCII table and look for codes 0x69 and 0x44. These are the codes for chars 'i' and 'D'. The text in the PLC begins with "Di". We can infer that the for each pair of chars stored in a register, the second char is placed in the most significant byte.

    You can then get the text from the PLC by swapping the bytes in each register and converting to a char using a ASCII table.