Author Topic: FX2424 Modbus RTU  (Read 6326 times)

jurg1505

  • Newbie
  • *
  • Posts: 10
  • I'm a llama!
    • View Profile
FX2424 Modbus RTU
« on: May 26, 2019, 02:38:05 AM »
I want to read data from a Epever solar charger the Tracer2210AN.

The Tracer2210AN modbus settings are;
Code: [Select]
controller supports RTU mode only.
16bit MODBUS addresses (per the modbus.org spec)
The serial communication parameters are
ï‚ž ï‚  BPS:115200 baud
ï‚ž ï‚  Parity: None
ï‚ž ï‚  Data bits: 8
ï‚ž ï‚  Stop bits:1
ï‚ž ï‚  Flow control: None

Example code from Epever
Code: [Select]
Read real-time battery voltage
Device ID:0x01
Function code: 0x04
Register Address: 0x3104
Register count: 0x0001
Send command: 01 04 31 04 00 01 7E F7
Receive command: 01 04 02 04 CE 3A 64
Read Holding Register Value: 0x04CE
0x04CE (hex) = 1230 (dec)
1230 / 100 = 12.3 volt


Code: [Select]
Z = READMODBUS (13,1,3104)i get 4 values one after the other
How can i put the first value in DM[51], second in DM[52] ....

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:FX2424 Modbus RTU
« Reply #1 on: May 26, 2019, 11:35:36 AM »
I am not answering the question that you asked. You cannot get 4 values from the READMODBUS function, just one.

Your code:

Z = READMODBUS (13,1,3104)

The READMODBUS function returns a single 16-bit value. You assigned this value to the 32-bit variable Z.  Where are the other 3 values that you said that you were getting?

The 3rd argument to READMODBUS should have been &h3104 (hexadecimal not 3104 (decimal).  It is a good bet that your Modbus device rejected this modbus query. Your Modbus device probably returned an error status and not the value of some register.

You must check the value from Status(2) to determine if the READMODBUS function completed without error and the value that was returned has any meaning.  

Your test code uses the Modbus function code of 4.  The READMODBUS function uses the Modbus function code of 3.  These two function codes are different and your Modbus may return values from different registers based on the function code that you  used.

You can force READMODBUS to use the function code 4 instead of 3 with this statement:

   Setsystem 6,4



Gary D*ckinson
« Last Edit: May 26, 2019, 05:24:01 PM by garysdickinson »