Author Topic: RS485 Modbus RTU Communicating with Autonics  (Read 23338 times)

taufiqsunar

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
RS485 Modbus RTU Communicating with Autonics
« on: March 13, 2012, 12:52:42 AM »
Im a new user on Super PLC. Currently Im using FMD1616-10  to controlling slave device Autonics Temperature Controller TK4M with RS485.

The slave device can communicating with Modbus RTU Protocol.

The slave device ID is 1.

Im trying to access temperature value in that device. The address of present value is 03E8H, with function 04.

Im using the hard code from an example in this forum.

this is my code

Function first_set

Code: [Select]
SETPROTOCOL 3,1

Function read_autonics

Code: [Select]
A = &H03
B = &HE8
N = &H0A

FOR I = 0 TO 1
Z = INCOMM(3)
NEXT

call read_modbus

Function read_modbus

Code: [Select]
'  This function implements MODBUS RTU function 04 using the INCOMM and
'  OUTCOMM commands.
'  The address to be read is in A
'  The number of channel to be read is in N
'  The data are returned in DM[201] to DM[201+N]
'  DM[101] to DM[200] are used by this function

DM[101] = &H01     ' node address of slave
DM[102] = &H04     ' function 04
DM[103] = A    ' upper 8 bit of address
DM[104] = B ' lower 8 bit of address
DM[105] = &H00        ' upper 8 bit of count
DM[106] = N        ' lower 8 bit of count
X = CRC16 (DM[101],6) & &HFFFF  ' compute the CRC16 of DM[101] to DM[106]
DM[107] = X / 256    ' upper 8 bit of CRC16
DM[108] = X & &HFF ' lower 8 bit of CRC16

FOR I = 1 to 8          ' send out the MODBUS RTU command in binary
  OUTCOMM 3, DM[100+I]
NEXT
delay (10)  ' delay for a while to wait for response
DM[111] = 0
TIMERPV[1] = 10         ' if the timer counts down, the loop is exited
WHILE DM[111] <> &H01   ' wait for response and store first byte
 DM[111] = INCOMM (3)
 IF TIMERPV[1] = 0
  SETLCD 4,1, "NO RESPONSE         "
  RETURN
 ENDIF
ENDWHILE

FOR I = 1 to N          ' assuming small number of read data
  DM[111+I] = INCOMM (3)
  IF DM[111+I] < 0 GOTO @5: ENDIF
NEXT

@5 FOR I = 1 to N          ' convert two bytes into one 16-bit word.
  DM[200+I] = DM[112+I*2]*256+DM[113+I*2]
NEXT


in ladder diagram, on first row, there is a normally open button that can be executed once on starting the system, that activating function first_set

on second row, there is clock that triggering read_autonics every 1 second.

but that doesnt work at all. i checked the system with on-line monitoring and DM[111] just contain -1 in decimal and FFFFFFFF in hex.

any suggestion would be accepted! many thanks and regards

Taufiq Sunar
 ???

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:RS485 Modbus RTU Communicating with Autonics
« Reply #1 on: March 13, 2012, 11:22:08 PM »
Note that you can actually run the SETSYSTEM 6,4 statement once and you can then use the READMODBUS and READMB2 to send function 04 to read data from your Modbus slave.  This is simpler than using the TBASIC hardcoded method which is needed for older PLC such as T100MD+ that do not support the Function 04.

Most importantly, what is baud rate settings of your slave device? What is the communication format (7 or 8 data bits, none, even or odd parity, 1 or 2 stop bits). You may need to run the SETBAUD command once to define the PLC's RS485 port to the same baud rate of your Modbus slave.

Alternatively if your Modbus slave can be configured you should set it to the PLC's default baud rate, which is 38,400, 8, 1, n.





« Last Edit: March 13, 2012, 11:22:51 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

taufiqsunar

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Re:RS485 Modbus RTU Communicating with Autonics
« Reply #2 on: March 14, 2012, 11:33:33 AM »
the baudrate of my slave device is just same as of the FMD1616-10, its 38400bps.

ok, so its my new code

Code: [Select]
SETPROTOCOL 3,1
SETSYSTEM 6,4

Code: [Select]
DM[111] = READMODBUS (3, 1, &H03E8)

but still there is no answer

or may I send you the manual by email?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:RS485 Modbus RTU Communicating with Autonics
« Reply #3 on: March 14, 2012, 02:35:12 PM »
If the baud rate of your Modbus slave device is the same as the PLC then your command is correct and you should be able retrieve the data from the device if the address is correct.

Did you use any other Modbus command that run on a PC to test the communication with the Modbus device? E.g. you can download the  Modbus poll software from http://www.modbustools.com/modbus_poll.asp) Using a Modbus master program on a PC give you the visibility of the command sent and received to/from the device. You can also verify if the ID and the register address are correct.

Once you have managed to retrieve data from the PLC you will then have a better idea of the correct parameters to be passed to READMODBUS command to become a Modbus master.

Note: SETPROTOCOL 3,1 is not required since that is only to fix the PLC as Modbus RTU slave. When you are using READMODBUS command the PLC is working as a master. However,  running SETPROTOCOL 3,1 would not affect READMODBUS command.

DId you try an address such as &H03E7 and &H03E9? This is to ensure that you have computed the address using the correct base addressing scheme (i.e. whether it is using 0 based or 1 based addressing)
« Last Edit: March 14, 2012, 02:43:22 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

taufiqsunar

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Re:RS485 Modbus RTU Communicating with Autonics
« Reply #4 on: March 15, 2012, 02:13:20 AM »
I feel sory, but I dont have RS485 to USB converter here. Neither RS485 to RS232.

So the only way that I have is just connecting my slave device with PLC.

I have been trying to use address &H03E7 and &H03E9, but it doesnt work.

I just sent you the user manual for my slave device if you willing to read it.

Many thanks,

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:RS485 Modbus RTU Communicating with Autonics
« Reply #5 on: March 15, 2012, 03:36:07 AM »
It is much more handy to have access from the PC to the RS485 device for troubleshooting communication. So it is good if you can get a USB-RS485 adapter or a RS232-to-RS485 adapter if your PC already has RS232 port. It also help to verify that the RS485 port on both the PLC and the slave device are working. It is also convenient for the PC to tap into the RS485 connection between the devices and use a serial monitor to monitor the communication between the PLC and the device. Right now we don't know if it is a hardware issue, a wiring issue, or a communication setting issues unless there is a way to monitor the communications.

Can you try to read the value of STATUS(2) after readmodbus:

E.g.

DM[111] = READMODBUS (3, 1, &H03E8)
S = STATUS(2)

If S is equals 1 it means that PLC is getting a response from the Modbus RTU slave. If S equals 0 it means it is not getting a response from the Modbus RTU slave and you will need check the settings of your RTU slave.


« Last Edit: March 21, 2012, 09:23:12 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

taufiqsunar

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Re:RS485 Modbus RTU Communicating with Autonics
« Reply #6 on: March 21, 2012, 03:32:13 AM »
its turn out that the problem is on my device. there is a setting that set the communication time between the device and master.

thank you for your attention!

regards,