Author Topic: ModBus RTU does not work  (Read 11135 times)

Paul

  • Guest
ModBus RTU does not work
« on: September 04, 2006, 08:21:20 AM »
Hello,  I have had my T100MD for several days now.  Everything seems to work great except the ModBus RTU stuff.  I am using setbaud 3,13 to set 9600baud 8 data bits 2 stop bits and no parity on first scan.  Then I use a differentiated function <DM[1] = getmodbus(13,3,109) >also tried many addresses.  I also used <if status(2) A$= " Modbus read OK" Else A$="Modbus read failed" Endif>.  Not only do I not get any thing in DM[1] A$ is Modbus read failed.  I have changed the jumper on my Auto485 to RTS and the red & greed leds blink bright when the read is executed.  When in Auto the red & Green LEDs blink dim or half lit.  

I eliminated the Serial cable to my equipment by plugging the auto485 directly to the serial port using a male to male gender changer.  Still no luck.  I am trying to get data from a Morningstarcorp.com TriStar charge controller.  I used their program to set the address to 3 from the 1 default.  Their software talks to it fine, but I wanted to get the data to put on my web page.  Their serial port specification is downloadable from their web page "TS_Modbus.pdf" It says 9600 Baud PARITY NONE dATA BITS 8 sTOP BITS 2 fLOW CONTROL NONE and all addresses are for request PDU.  What is PDU?  Then the address I was trying to get is listed as 0x0008, Logical Address 9.  Now why can I not get any Data?  Any suggestions?

I am thinking I must have a bad Auto485.

Paul@SolarKitchenSE.com

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:ModBus RTU does not work
« Reply #1 on: September 04, 2006, 10:31:40 AM »
1) For 9600, 8,n,2, it should be SETBAUD 3, &H13  - it is hexadecimal, not decimal.

2) Why address 109 when you are trying to read from binary 0x0008?

   DM[1] = READMODBUS (13,3,8)

3) Is it RS485 between T100MD+ and your device? If you use an Auto485 to monitor, only the red LED should blink since Auto485 is always in receive mode. The green LED only blink when you send data from RS232 from the PC. Make sure that you dont send any thing from the PC when the PLC is talking to your device as you will disrupt the communications.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Paul

  • Guest
Re:ModBus RTU does not work
« Reply #2 on: September 04, 2006, 11:59:20 AM »
My device is RS232.   I am using port 3 to an auto485 and have the DB9 plugged into the DB9of my device with a male to male genger changer.  When the red light on the auto 485 blinks, so does the green light blink but they are only half lit (dim).  I am suspecting a problem now with the auto485.  I can switch the jumper to RTS and the LEDs blink but are very bright.  Neither works as far as getting data.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:ModBus RTU does not work
« Reply #3 on: September 04, 2006, 04:39:49 PM »
The PLC does not support the RTS control line, so if you are using COMM3 to talk to an Auto485, the Auto485 must be in Auto mode. The LEDs will not be very brightly lit unless there are continuous data exchanges between the PLC and the device via the COMM3 port.  If the device is not responding to command from the PLC, then only red LED will be lit and green LED should be off.

The fact that you saw both red and green LED brightly lead may suggest a wrong connection. Note that male-to-male gender changer may not change the device type correctly (DCE or DTE). I think you need a null modem or make a cable yourself such that:

   Auto485           Device
    2                       3
    3                       2
    5                       5

You can test if the Auto485 works by using it for programming/online monitoring via a PC. Of course you can only do so if the PLC is not sending data out of the COMM3 port. You can stop the PLC from using COMM3 port by turning ON DIP switch #4 and reset. For COMM3, after reset with DIP switch #4 on, the default settings is 38,400,8,1,n and you can then use TLServer to talk to the PLC. If you can use TLServer to talk to the PLC and you are able to perform online monitoring of the PLC, then Auto485 is functioning perfectly.

There were problems in your settings as stated in the original reply to your first post. Do modify your settings and it should work.

« Last Edit: September 04, 2006, 04:45:45 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Paul

  • Guest
Re:ModBus RTU does not work
« Reply #4 on: September 05, 2006, 03:53:40 PM »
Hey thanks!  It works great when you get the correct cable.  I had to get a null modem cable w/ DB9 ends.  
NOW I get my data but I lost my decimal place.  I would like to see 2 decimals.  Here is the code I used.
DM[1] = READMODBUS(13,3,8)
IF Status(2) Z$="ModBus Read OK"
  Else Z$ = "ModBus Read Failed"
EndIf
A$=STR$(DM[1])
B = Val(A$)*(96+(2/3))
C=(B/32768)
My device documentation says "SCALING" HEX1007 > Decimal 4103  then (4103 x 96.667) / 32768 = 12.1V
Any sugestions as my math is poor   poor.  I am seeing a whole number for C.
Paul

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:ModBus RTU does not work
« Reply #5 on: September 05, 2006, 04:28:04 PM »
Of course, all variables A to Z are integer only so they don't support floating point. But you can get around by boosting the number by a 100 times so that each digit represent 0.01 instead of 1.

Also no need to change DM[1] to string using STR$ and then back to number using VAL. It is a waste of CPU time.

C = DM[1]*9667/32768

The end result will be 1210 for DM[1] =4103, which means 12.1V.

You can display decimal point on LCD as follow:

   SETLCD 1,1,  STR$(C/100) + "." + STR$(C MOD 100)+ "V"



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