Author Topic: RS485 communication issue  (Read 10410 times)

wia

  • Newbie
  • Posts: 2
  • I'm a llama!
    • View Profile
RS485 communication issue
« on: December 06, 2005, 01:10:36 AM »
I am having some issue with RS485 communication.
I am using three H series PLC connected via a RS232-RS485 converter from Tri-logi. The converter is set to auto mode and response time has been adjusted to maximum which I found has best result.
I use C++ to program the communication between PC and PLC. Basically this is the sequence I am doing:
1. Turn RTS on.
2. Put data to transmit buffer and wait for data to be sent out completely.
3. After data is sent out completely, wait for a period of time, 110 ms.
4. Turn RTS off and read the input buffer.

The issue I am facing now is that quite frequently I will read back some garbage string. For example, if I send a command "@03RR0000"plus start and CR, most time I can read back correctly, but some time I will read back something not started with ""@03RR" at all.

Can you help on this? Thanks a lot.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:RS485 communication issue
« Reply #1 on: December 06, 2005, 10:32:45 AM »
Unlike the M-series or the E10+ PLCs, the H-series PLC does not add a 10ms delay before responding to a host link command (the 10ms delay was to ensure that the Auto485 adapter has enough time to turnaround the RS485 driver). This means that when using Auto485 adapter with H-series PLC, you should only use the Auto485 adapter in ?RTS? control mode and not the ?Auto? mode. You have to write your C++ program to switch OFF the RTS line when the last bit of the command string has been transmitted.

Due to historical reason, the H-series PLCs were designed at the time when there was no Auto485 adapter and most RS232-to-RS485 adapter on the markets were ?RTS-controlled? type. Hence it was assumed that the host PC can accurately control the RS485 transmitter by controlled the RTS line of the RS232 port. Since a H-series PLC does not have a serial buffer, the CPU processes the host link command immediately as the command message is being received and almost immediately start to send its response string back to the host after it has received the completed command string. So if the host did not switch the RS485 driver back to receive mode in time, there will be a brief period that the characters sent out from the slave PLC is lost. This is what happen when you use the Auto485 adapter in ?Auto? mode. Since the adapter is not controlled by RTS line when in ?Auto? mode, what happens is that the Auto485 will wait for a brief delay period (approx. 0.5-1.5ms)  after the last stop bit has been transmitted. So if the slave H-series PLC starts to send response string during this delay then the first few characters will be lost. This explains why some of the received string does not start with ?@? sign.

Thus the only way is to use the adapter in RTS-controlled mode and write your program to switch off the RTS line immediately when the last stop bit has been sent. However, note that unlike DOS or other Real Time Operating Systems (RTOS), Windows is not 100% deterministic, which means that Windows will not guarantee that it will turn off the RTS line at the exact moment when the last stop bit is transmitted. Windows will try to do it as fast as possible but it is not its highest priorities. This means that once in a while you may still experience lost characters. Hence it is important that you check the response header (first five characters)  to see if it matches the command header and also verify the FCS to be sure that the response string you have received is valid. Re-send the command string if an error has occurred.

Note: In your program, you would have worsened it by adding a 110ms delay before switching off the RTS line. But fortunately since your adapter was in Auto mode the RTS line was ignored and it was the Auto turnaround that was giving trouble.
« Last Edit: December 06, 2005, 11:30:36 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

wia

  • Newbie
  • Posts: 2
  • I'm a llama!
    • View Profile
Re:RS485 communication issue
« Reply #2 on: December 06, 2005, 06:48:25 PM »
thanks a lot. I will try it out.