Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!, I need to use this code made in C# to .Net [^] . I have a PLC connected to a PC through Modbus RTU (RS485). Between PLC and PC I have a RS485-RS232-USB converter.

I'd like to know how this program could read and write memory registers of 4 bytes (2 words) size. I need to handle memory registers with float data type and others with negative values. I have a PLC with the next registers (PLC REGISTERS LINK) that I need to read and write, so I'll be very pleased if you could give me some help with this.

This is the link with the PLC registers [^]

I need to read and write this registers from PLC:
Data Registers D0000-D4095 (as you see in the PLC) = 450001 – 454096 (Modbus address)

Thanks!.
Posted

What you can do, using the article's program 'as is', is reading the pair of registers and then convert yourself the return values into the meaningful value. For instance, assume you read a register pair
reg[n] = 0x4128 and register reg[n+1] =0x0000

then, if the PLC uses the big endian representation, you obtain the int value 0x41280000 whose conversion to float gives eventually 10.5 (see "IEEE 754 Converter"[^]).

Of course a better way would be modifying the original code to make it perform the required conversions for you.
 
Share this answer
 
Comments
cadiazran 8-Oct-15 9:26am    
Thanks CPallini, but how I could do that in code?, could you open the code in C#?, I'll appreciate your help!
I recommend trying AdvancedHMI. It has a ModbusRTU driver that supports float over Modbus by preceding the address with a F. For example, you would use F450001. To do this in code with AdvancedHMI:

Dim MyValue as string= ModbusRTUCom1.Read("F450001")
 
Share this answer
 
Try NModbus[^], with great manual[^]
See last page for the data type conversion you need.
Some deeper theory about modbus rtu dta representation: http://www.chipkin.com/how-real-floating-point-and-32-bit-data-is-encoded-in-modbus-rtu-messages/[^]

But before you try to do it from code (which is quite simple), make sure your connection is really working.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900