Modbus TCP seg fault

  • Thread starter Philip Costigan
  • Start date
P

Thread Starter

Philip Costigan

Hi

I developed a small program that uses Modbus TCP to communicate to PLC's and it works quite well. The only test that I could not get to work was when a TCP socket stops mid cycle. The program seg faults.

The goal is to have the program acknowledge the problem and then try to keep reopening the socket until succesful and then go back to the main task of communicating.

I have put the program at "ftp://pcscada.com.au/pub/pcscada/modbus.tcp.tar.gz":ftp://pcscada.com.au/pub/pcscada/modbus.tcp.tar.gz

If anyone can help debug or enhance this code, it would be much appreciated.

Regards

Phil
 
Hi Philip:

> I developed a small program that uses Modbus TCP to
> communicate to PLC's and it works quite well. The only test that I
> could not get to work was when a TCP socket stops mid cycle.
> The program seg faults.

Not entirely unusual. Are you checking return results from your read/writes? If I recall correctly, a write will return a -1 if it fails. I think reads do as well. I'm not near my references right now so I can't verify this though.

> The goal is to have the program acknowledge the problem and then
> try to keep reopening the socket until succesful and then go back
> to the main task of communicating.
>
> I have put the program at
> ftp://pcscada.com.au/pub/pcscada/modbus.tcp.tar.gz
>
> If anyone can help debug or enhance this code, it would be much
> appreciated.

Look into signal interception. Put in an "#include <signal.h>" and register a routine to handle the signals inside your program. If you
need more specific help with this, e-mail me privately and I'll see what I can do for you.

Ron Gage - Saginaw, MI
([email protected])

P.S. My *nix programming experience is mostly Linux based but should be universal enough to work with most *nix's in the world.
 
Top