Modbus TCP Client: Socket get disconected

A

Thread Starter

Atul

I am creating a Modbus TCP client which can read th values from the ModbusTcp slave devices using C# language. Using the Socket class from .net library. I am able to connect to Modbus Slave device using Socket and get responce from slave for first transaction but it get disconnected when try to send the next request.
 
F

Frank Prendergast

Are you getting a RST or FIN coming back from your slave?

My guess is that your slave device requires
communication every so often or it times out the connection and forces it closed.

That timeout period can vary from device to device. I have seen most be about 1 second.
So when you don't communicate to it for at least one second it closes the socket.
 
You should check the slave behaviour before you look into your program. There are Modbus TCP/IP slaves on the market that will close the socket after they have sent the response and this would generate the error you are seeing. Normally these slaves will disconnect the socket after a timeout period.

You can view the prefered behaviour in the Modbus TCP/IP Implementation Guide on http://www.modbus.org
 
L

Lynn August Linse

One idea: Use a network sniffer & make sure you're NOT sending 1 or 2 bytes too many.

For example, if you send bytes: <00 01 00 00 00 06 01 03 00 00 00 00 00>, which is a 6-byte header, a 6-byte Modbus command, and 1 extra null.

The slave will read the 6-byte header, see to read 6 more bytes of data - see total 12 bytes and IGNORE for the moment the extra byte. It will answer you, then see 1 more byte which it thinks is the start of a new request, but then will timeout because the rest of a valid header didn't show up. Being out of sync, the easiest fix is to close the socket to force the client to
open a new socket.

That's one suggestion - plus the network sniff (like http://www.ethereal.com/) will tell you which end is closing the socket. That's also useful info for you to know.

Best regards

Lynn August Linse, LynnL(AT)digi.com
IA Firmware Specialist, Digi Int'l (www.digi.com)
Board Member, The Modbus Organization (www.modbus.org)
26741 Portola Pkwy, Suite 1E #242
Foothill Ranch CA 92610-1743 USA
Ph/Fx: 949-916-1524 or 949-212-5802
 
Top