Jump to content

Tips on detecting and handling comm error


Recommended Posts

  • MVP 2023

I wonder if any wise programmers might have some helpful hints. I've been programming for awhile, but I'm still a bit sketchy about networking. When I have two v570 PLCs communicating with each other, it's important to know (and potentially correct automatically) when a communications error occurs. I'm attaching a subroutine example in the master PLC where I communicate with the slave and detect a comm error by looking for a change in the count of data received to the socket (SDW21, for Socket 3) - ladder rungs 5-7. Currently I initiate communication every 250ms and if I go for 2 sec without the RXD count increasing then I alarm. This seems to work well, but is there a better way?

Also, when a comm error is detected, what is the best procedure for making an attempt to re-establish communication automatically?

Thanks.

By the way, I'm using VisiLogic 9.4.0, if it matters, and communicating by MODBUS IP over Ethernet.

Link to comment
Share on other sites

In my programming world I am 100% serial connections and not Ethernet, but looking at your nets it looks to me that you have the same status integer that a serial modbus connection would have, so just compare that if the MI296 or 297 = 5 then you will know that communication has timed out and stopped. This communication will auto resume since it tries to execute the net on every scan (provided you pres your read/write bit you have in the top line of your net)

If you were wanting to press the button once and then periodically retry automatically until a connection was made then auto re-execute your read/write then I would make a couple of nets that say:

If MI296 = 5 then start a timer and put in that the line is only active while the timer is not true (use a set bit on this timer)(example once every 2 seconds). Every time the timer becomes true then re-execute net 4 in your program (bypass MB126) also every time the net executes also reset the timer. If the com has not been restored then the cycle will repeat with the timer becoming true again in 2 seconds. The timer will time out again and again until such time as MI296 no longer equals 5. In this way you will allow your main program 2 seconds of unburdend scans (skiping the timeouts of failed communication), but will retry once every two second until the comm is restored. Ultimately, reading your data automaticaly while not slowing down your scan times on every scan but a single scan once every 2 seconds.

Rinse and repeat for MI297 and the write command line.

Keith

Link to comment
Share on other sites

  • MVP 2014

In general I would say you are on the right track, using the sessions and acknowlegement counters, and the Status MI as Keith suggests.

Also when you lose comms, check your SB150 - 3 Socket Connected. This is one main difference between Modbus Serial and ModbusTCP. If the connection has dropped out, then you need to re-connect your TCP socket before you can re-try the Modbus command.

Link to comment
Share on other sites

  • MVP 2023

Thanks for the helpful suggestions. Here is what I ended up with for the "Master" PLC. Perhaps this is a bit unwieldy, but it seems to work well. I broke the comm error up into two parts. If the Socket (3) isn't initialized, I re-initialize the ethernet card and socket then try to connect the socket. If the socket is initialized, but not connected, then I skip the initialization step and just try to reconnect the socket. For each, I re-attempt every 2 seconds. This seems to handle the varying circumstances well - if both PLCs are connected to a hub or switch, then where the loss of communications occurs results in different situations. The MB125 "Comm Error" bit is the same logic as I showed in my initial post, above.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...