Author Topic: How to read 32bit data from Modbus Registers?  (Read 19607 times)

Prayuktibid

  • Newbie
  • Posts: 15
  • I am Prayuktibid
    • View Profile
How to read 32bit data from Modbus Registers?
« on: August 24, 2017, 09:23:46 PM »
Hello Folks,
I am using Trilogi PLC FDMD88-10 model and I am using it for Industrial purpose. My question is how to read 32 bit data from modbus register also how can I configure my code for Big-endian and Little-endian data fromat while read or write any data in modbus register?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:How to read 32bit data from Modbus Registers?
« Reply #1 on: August 24, 2017, 11:44:36 PM »
Is the FMD88-10 the master to read 32-bit data from a slave device?

All Modbus registers are accessed in 16-bit only. To access 32-bit data you normally would need to read two adjacent Modbus registers into two DM16[] and access them as a DM32[] variable.

The PLC handles number in Big Endian. If the slave (server) arrange the data in Little Endian you will need to use TBASIC to swap the two adjacent DMs so that the are arranged in  Big Endian.

Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Prayuktibid

  • Newbie
  • Posts: 15
  • I am Prayuktibid
    • View Profile
Re:How to read 32bit data from Modbus Registers?
« Reply #2 on: August 25, 2017, 02:29:31 AM »
Thanks for your reply

Is the FMD88-10 the master to read 32-bit data from a slave device?
Yes, FMD88-10 is Master device and I want to read/write data from a cluster Controller(Slave Device).

All Modbus registers are accessed in 16-bit only. To access 32-bit data you normally would need to read two adjacent Modbus registers into two DM16[] and access them as a DM32[] variable.
I have tried in this way before.

The PLC handles number in Big Endian. If the slave (server) arrange the data in Little Endian you will need to use TBASIC to swap the two adjacent DMs so that the are arranged in  Big Endian.
okay, Thank you.

I was trying to read from SMA Cluster Controller's INPUT Register(register number 30005, datatype U32) which contain Serial number of this device but PLC is unable to do that. I have attached my TBASIC code along with SMA cluster controller's Modbus data manager with this reply. please find the attachments and please help me to solve this problem

Prayuktibid

  • Newbie
  • Posts: 15
  • I am Prayuktibid
    • View Profile
Re:How to read 32bit data from Modbus Registers?
« Reply #3 on: August 25, 2017, 02:30:56 AM »
Here The TBASIC Code.
« Last Edit: August 25, 2017, 02:31:54 AM by Prayuktibid »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:How to read 32bit data from Modbus Registers?
« Reply #4 on: September 04, 2017, 12:06:42 PM »
Did you get a successful connection before you run the WRITEMODBUS command?

Also I think the device is using the Modicon convention to represent the Modbus registers.

Modicon Convention is as follow:

30001 to 39999  - can only be read using Modbus function 04 and the binary address = Modicon address - 30001

So to read anything in the 30001 to 3999 you use SETSYSTEM 4.4 to change to read the input register, then subtract the given address by 30001

E.g. Version number at address 30001

so  READMODBUS should read from binary address = 30001 - 30001 = 0

Similarly,

40001 to 49999 can only be read using Modbus Function 03 and the binary address =( Modicon address - 40001)

So if you want to write to Modicon address 40493 you should be writing to 40493-40001 = 492.

Give that a try and see if it works for you.

[Edit] - For 40001 to 49999 can only be read using Modbus Function 03 (it was wrongly written as 04 initially).
« Last Edit: September 05, 2017, 03:52:08 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Prayuktibid

  • Newbie
  • Posts: 15
  • I am Prayuktibid
    • View Profile
Re:How to read 32bit data from Modbus Registers?
« Reply #5 on: September 04, 2017, 08:54:18 PM »
Did you get a successful connection before you run the WRITEMODBUS command?
 Yes
30001 to 39999  - can only be read using Modbus function 04 and the binary address = Modicon address - 30001
So to read anything in the 30001 to 3999 you use SETSYSTEM 4.4 to change to read the input register, then subtract the given address by 30001
E.g. Version number at address 30001
so  READMODBUS should read from binary address = 30001 - 30001 = 0

I am now able to read data from Input registers.

40001 to 49999 can only be read using Modbus Function 04 and the binary address =( Modicon address - 40001)

So if you want to write to Modicon address 40493 you should be writing to 40493-40001 = 492.

While I am trying this as per my code it gives "writing failure" by checking the STATUS(2) function.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:How to read 32bit data from Modbus Registers?
« Reply #6 on: September 05, 2017, 04:07:54 AM »
Try using a PC based Modbus software to test the communication with your device and see if the address and data wrtten is acceptable. That gives you better visibility of what's going on between the Modbus client and the Modbus server. Once you can confirm that the address or data is valid you can then use the same function, address and data to send from the PLC to the device.

One such tool is the Modbus Poll software that you can download from:

http://www.modbustools.com/

They have a free evaluation version that will run for a few minutes and then stop. You can restart it again.

Also try using Modbus function 16 (0x10) to execute the WRITEMODBUS command instead of function 06 in case the device does not support function 06 at this particular address.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Prayuktibid

  • Newbie
  • Posts: 15
  • I am Prayuktibid
    • View Profile
Re:How to read 32bit data from Modbus Registers?
« Reply #7 on: September 12, 2017, 03:57:26 AM »
I'm facing a strange problem now. I was trying to follow your method but it is not giving the right response. The FMD88-10 able to write data for sometimes and sometimes it is unable to write data on same modbus single holding register address that is 40492(16-bit). Also This FMD88-10 is behaving equally for register address 40492.


Also try using Modbus function 16 (0x10) to execute the WRITEMODBUS command instead of function 06 in case the device does not support function 06 at this particular address
I have tried on both modbus function code single register write(0x06) and multiple register write(0x16).

I have attached my code and the modus document of cluster controller with this reply please find it.

(the modbus document has attached in next reply.)


Prayuktibid

  • Newbie
  • Posts: 15
  • I am Prayuktibid
    • View Profile
Re:How to read 32bit data from Modbus Registers?
« Reply #8 on: September 12, 2017, 04:05:16 AM »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3170
    • View Profile
    • Internet Programmable PLCs
Re:How to read 32bit data from Modbus Registers?
« Reply #9 on: September 18, 2017, 10:29:05 PM »
It is unlikely to be a problem with the PLC as the FMD88-10 has no problem working with many third party Modbus RTU slave and Modbus TCP server. You may want to test the communication between the PC (using the Modbus Poll software that was mentioned in this earlier thread) and communicate your Modbus slave controller to observe if there is any particular issues.

Since you are using Modbus TCP your program also must check if the network connection is still valid before executing the WRITEMODBUS command and READMODBUS command. If the connection is lost then the WRITEMODBUS command will fail to run.

Note that the Modbus client has a time out so if the connection is left idle for longer than the time-out settings (see Ethernet & ADC settings in i-TRiLOGI) the connection will close automatically. If the WRITEMODBUS command is executed infrequently then try to increase the time-out so to maintain the connection. Alternatively close the connection when not in use and re-connect only when you need to execute the MODBUS command.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS