Author Topic: problem with ModBus  (Read 9070 times)

ckane

  • Newbie
  • Posts: 14
    • View Profile
problem with ModBus
« on: August 11, 2011, 06:04:57 AM »
I am using a FD88 and this is my first experience programming any PLC.  I am using the PLC as a ModBus Master RTU and wish to read two MODBUS registers from a Slave and then set those values to the two analog outs.  

I can communicate with the slave via my computer using MODSCAN, so I know the slave has the right baud rate, etc.( 8N1)

All seems to work except the MODBUSREAD.  I am getting no data back.  The LEDS by the 485 port never blink.

Suggestions Please -

Only have two circuits and two cusotm functions as below.

Custom Function INIT - runs on first scan


SETBAUD 3, &H09   ' 115.2K, 8N1
SETSYSTEM 6,4  ' MODBUS RTU
SETSYSTEM 25, &H0101  ' A/O 1 SET TO 5 VOLTS
SETSYSTEM 25, &H0201  'A/O 2 SET TO 5 VOLTS
SETPROTOCOL 3, 1  'PROTOCOL OF COMM3 SET TO MODBUS RTU


Custom Function GetData - runs off timer every 1 second

A=READMODBUS(13,10,11)  'READ DATA ON PORT 3 AS A MASTER RTU SALVE 10 ADDRESS 11
SETDAC 7, A ' SET DAC 7 (A/O 1) TO READ VALUE
SETLCD 1, 1, "Set 1 Gamma = " + STR$(A) ' SHOW VALUE ON DISPLAY
DELAY 200   ' DELAY 200 MS
B=READMODBUS(13,10,12)  'SAME AS ABOVE
SETDAC 8,B
SETLCD 2, 1, "Set 2 Gamma = " + STR$(B)
SETLCD 3, 1, "Date: " + STR$(DATE[2]) + "/" + STR$(DATE[3]) + "/" + STR$(DATE[1])
SETLCD 4, 1, "Time: " + STR$(TIME[1]) + ":" + STR$(TIME[2]) + ":" + STR$(TIME[3])

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:problem with ModBus
« Reply #1 on: August 11, 2011, 08:19:53 AM »
1) The RTU slave address 10 - is it decimal or hexadecimal? If it is hexadecimal then you have to specify it as &H10.

2) Please check that the wiring of the RS485 port to the PLC side is correct.

3) FMD88-10 does not have transmit/receive LED on its RS485 port. On your Modbus RTU slave is there transmit/receive LED? Does the receive LED blink at all?

4) If you have a USB-RS485 adapter you can run a serial monitor program on your PC to monitor activity on the RS485 port.

5) You can also use a USB-RS485 port and TLServer to attempt online monitoring on the PLC's RS485 port just to test if the COMM3 port is working properly (you cannot run SETPROTOCOL on first scan if you intend to test this feature).

Note: If you are only using the COMM3 port as Modbus master and not using it as a slave port or programming port, then it is better to set the COMM3 port to "no protocol". i.e.

SETPROTOCOL 3, 10

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

ckane

  • Newbie
  • Posts: 14
    • View Profile
Re:problem with ModBus
« Reply #2 on: August 11, 2011, 08:41:01 AM »
Slave is decimal 10
changed protocol to 3, 10

I have flipped the wires on the 485 and still no correct data back.  

ckane

  • Newbie
  • Posts: 14
    • View Profile
Re:problem with ModBus
« Reply #3 on: August 11, 2011, 09:07:20 AM »
captured 485 port and this is what I see.

2011-08-11 11:03:04.472 R 0A 04 00 0C 00 01 F0
2011-08-11 11:03:04.488 R B2
2011-08-11 11:03:04.878 R 0A
2011-08-11 11:03:04.894 R 04 00 0C 00 01 F0 B2
2011-08-11 11:03:05.362 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:05.767 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:06.173 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:06.688 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:07.078 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:07.483 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:07.780 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:08.185 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:08.589 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:09.079 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:09.479 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:09.879 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:10.380 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:10.770 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:11.176 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:11.675 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:12.065 R 0A 04 00 0C 00 01 F0
2011-08-11 11:03:12.080 R B2
2011-08-11 11:03:12.486 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:12.798 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:13.188 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:13.594 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:14.093 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:14.483 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:14.888 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:15.388 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:15.778 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:16.183 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:16.682 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:17.072 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:17.478 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:17.806 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:18.196 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:18.601 R 0A 04 00 0B 00 01 "As"

ckane

  • Newbie
  • Posts: 14
    • View Profile
Re:problem with ModBus
« Reply #4 on: August 11, 2011, 09:18:50 AM »
Above message with just the port monitor connected to the 485 on the PLC.  Below I have the port monitor in parrel while tlaking to the slave.

2011-08-11 11:03:04.472 R 0A 04 00 0C 00 01 F0
2011-08-11 11:03:04.488 R B2
2011-08-11 11:03:04.878 R 0A
2011-08-11 11:03:04.894 R 04 00 0C 00 01 F0 B2
2011-08-11 11:03:05.362 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:05.767 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:06.173 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:06.688 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:07.078 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:07.483 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:07.780 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:08.185 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:08.589 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:09.079 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:09.479 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:09.879 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:10.380 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:10.770 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:11.176 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:11.675 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:12.065 R 0A 04 00 0C 00 01 F0
2011-08-11 11:03:12.080 R B2
2011-08-11 11:03:12.486 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:12.798 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:13.188 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:13.594 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:14.093 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:14.483 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:14.888 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:15.388 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:15.778 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:16.183 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:16.682 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:17.072 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:17.478 R 0A 04 00 0C 00 01 F0 B2
2011-08-11 11:03:17.806 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:18.196 R 0A 04 00 0B 00 01 "As"
2011-08-11 11:03:18.601 R 0A 04 00 0B 00 01 "As"
 

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:problem with ModBus
« Reply #5 on: August 11, 2011, 09:28:55 AM »
The captured data are commands sent from the PLC - so it appears that the PLC is indeed sending Modbus command out of the RS485 port. When it doesn't get a response within 0.15s (default) it retries up to 3 times, which shows up on your capture. Your Modbus RTU slave doesn't appear to send response properly.

What is the response time of the Modbus RTU slave? Is it longer than 0.15 second? If so you may have to use SETSYSTEM 1,x to lengthen the wait time for the response from the Modbus RTU slave.


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

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:problem with ModBus
« Reply #6 on: August 11, 2011, 09:49:24 AM »
Note that you can use the STATUS(2) command to test if the first READMODBUS command was successful. If there is a problem it could report it on LCD (even if you don't have the real LCD you could report on the virtual LCD that you can see on the online monitoring screen) and RETURN from the function without proceeding to read from register address 12.
« Last Edit: August 11, 2011, 09:50:16 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

ckane

  • Newbie
  • Posts: 14
    • View Profile
Re:problem with ModBus
« Reply #7 on: August 11, 2011, 10:53:00 AM »
Have increased time, respons is around 200 ms.  

see code mods below.  always getting an error on the first modbus read.   Modscan works, just great with the slave.


INIT FUNCTION
SETBAUD 2, &H09   ' 115.2K, 8N1
SETSYSTEM 6,4  ' MODBUS RTU
SETSYSTEM 25, &H0101  ' A/O 1 SET TO 5 VOLTS
SETSYSTEM 25, &H0201  'A/O 2 SET TO 5 VOLTS
SETPROTOCOL 3, 10  '
SETSYSTEM 1, 4
SETLCD 1,1, "INIT FINISHED"

GETDATA FUNCTION

SETLCD 1,1, "                     "
SETLCD 4, 1, "Time: " + STR$(TIME[1]) + ":" + STR$(TIME[2]) + ":" + STR$(TIME[3])
A=READMODBUS(12,10,11)  'READ DATA ON PORT 3 AS A MASTER RTU SALVE 10 ADDRESS 11
'A = 2048
IF STATUS(2) = 0
SETLCD 3, 1, "ERROR MODBUS"
RETURN
ENDIF
SETDAC 1, A ' SET DAC 1 (A/O 1) TO READ VALUE
SETLCD 1, 1, "Set 1 Gamma = " + STR$(A) ' SHOW VALUE ON DISPLAY
'DELAY 200   ' DELAY 200 MS
B=READMODBUS(12,10,12)  'SAME AS ABOVE
'B= 2048
SETDAC 2,B
SETLCD 2, 1, "Set 2 Gamma = " + STR$(B)

ckane

  • Newbie
  • Posts: 14
    • View Profile
Re:problem with ModBus
« Reply #8 on: August 11, 2011, 12:00:20 PM »
latest capture at 9600 baud

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:problem with ModBus
« Reply #9 on: August 11, 2011, 12:26:38 PM »
Did you manage to capture the RS485 messages from the PLC at 9600 bps? Is it the same as above (when running at 115200). Did you see any response from the slave?

What are the settings that you have used on Modscan? The READMODBUS command uses Modbus Function 03 to read from holding register (default). Can you confirm if the Modscan command is using function 03?

Is there a PDF document of the modbus slave RTU that you are using that we can download to check the command set?
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

ckane

  • Newbie
  • Posts: 14
    • View Profile
Re:problem with ModBus
« Reply #10 on: August 11, 2011, 12:33:54 PM »
2011-08-11 14:32:38.858 ? 0A 10
2011-08-11 14:32:38.874 ? 00 0F 00 01 02 00 00 D5 9F
2011-08-11 14:32:38.905 ? 0A
2011-08-11 14:32:38.920 ? 10 00 0F 00 01 "0" B1
2011-08-11 14:32:39.170 ? 0A 10 00 10 00 01 02 00 00 D7 F0
2011-08-11 14:32:39.217 ? 0A 10 00 10 00 01 01 "w"
2011-08-11 14:32:40.792 ? 0A 04 00 0B 00 01 "As"
2011-08-11 14:32:41.214 ? 0A 04 00 0B 00 01 "As"
2011-08-11 14:32:41.635 ? 0A 04 00 0B 00
2011-08-11 14:32:41.650 ? 01 "As"
2011-08-11 14:32:41.994 ? 0A 03
2011-08-11 14:32:42.009 ? 00 00 00 0E C5 "u" 0A 03 1C ":" 9A
2011-08-11 14:32:42.040 ? 00 AE 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 01 00 03 07 D0 00 00 00 "4" F7 DD
2011-08-11 14:32:51.884 ? 0A
2011-08-11 14:32:51.900 ? 04 00 0B 00 01 "As"
2011-08-11 14:32:52.321 ? 0A 04 00 0B 00 01
2011-08-11 14:32:52.336 ? "As"
2011-08-11 14:32:52.758 ? 0A 04 00 0B 00 01 "As"
2011-08-11 14:33:03.007 ? 0A 04 00 0B 00 01
2011-08-11 14:33:03.022 ? "As"
2011-08-11 14:33:03.444 ? 0A 04 00 0B 00 01 "As"
2011-08-11 14:33:03.865 ? 0A
2011-08-11 14:33:03.880 ? 04 00 0B 00 01 "As"

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:problem with ModBus
« Reply #11 on: August 12, 2011, 10:32:14 AM »
I have received your Modbus RTU device.

I first connected it to the PC using USB-RS485 adapter and ran the Modbus Poll software with Slave ID  = 10, Baud rate = 9600,8,n,1.

Modbus Poll could communicate with the modbus RTU device using 50ms polling rate. But after running for some time the communication seems to stall - could be the high polling rate over running the device buffer? I then changed the polling rate down to 1000ms (1 second) and comm seems OK.

I then copied the code you posted here except changing the statement:

SETBAUD 2,3  ' baudrate = 9600, 8, N, 1

The PLC communicated with your Modbus device just fine. It is running the communication once a second and the screen shot suggest that there was no Modbus error.

I have used a serial port monitor software to monitor the RS485 port and the following were observed:

0A 03 00 0B 00 01 F4 B3
0A 03 02 07 DB 5F EE
0A 03 00 0C 00 01 45 72
0A 03 02 00 0C 1D 80
0A 03 00 0B 00 01 F4 B3
0A 03 02 07 DB 5F EE
0A 03 00 0C 00 01 45 72
0A 03 02 00 0C 1D 80
0A 03 00 0B 00 01 F4 B3
0A 03 02 07 DB 5F EE
0A 03 00 0C 00 01 45 72
0A 03 02 00 0C 1D 80

As you can see the PLC sent the Modbus function 03 to address 11 (0B hex) and your Modbus device responded with the data. It then followed by sending function 03 to address 12 (0C hex) and your device responded with another data. So the communication seems to run OK.

Since I did not have to modify your code to get it working it means that your problem could be entirely hardware related.

1) Is the RS485 wire between the PLC and the Modbus device extended to any other equipment?  

2) The RS485 driver IC on the PLC (75HVD3082) may be partially damaged due to wiring fault during experimentation. It is important to verify that the RS485 port on the PLC is working properly by attempting to perform online monitoring via the TLServer + RS485 port (do not execute SETPROTOCOL 3,10 otherwise it won't respond).  If you can perform sustained online communication with the PLC (observe the RTC running and click on any outputs to turn it on quickly) then the RS485 IC may still be OK.

If you wish to replace the RS485 IC a good drop in replacement chip to use is the LT1785AIN8 (check digikey.com or mouse.com) which can withstand overvoltages up to +/-60V and is recommended for industrial applications in tough environment.

« Last Edit: August 12, 2011, 10:34:09 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS