Operation not allowed on non-connected sockets problem

1,037 views
Skip to first unread message

ernesto

unread,
Jan 14, 2010, 11:44:18 AM1/14/10
to NModbus
Hello, I have just downloaded the framework and started testing and
playing with it using Modbus/TCP, but i always get a "The operation is
not allowed on non-connected sockets." error. It seams like the socket
gets disconnected after every query made to the slave.

This is my code:

private void timer1_Tick(object sender, EventArgs e)
{
using (TcpClient client = new TcpClient("127.0.0.1", 502))
{
ModbusIpMaster master = ModbusIpMaster.CreateIp
(client);
for (ushort i = 0; i < 16; i++)
{
ushort[] value = master.ReadHoldingRegisters(i,
1);
textBoxes[i].Text = Convert.ToString(value[0]);
}
}
}

I know I could read all 16 registers in one message but i'm just
trying features. The thing is I always get that error on the second
execution of the loop. Testing client.Connected and connecting it
again will not work either (I get an error like a connection request
has already been made). Using .Net framework 3.5, windows xp, visual
studio 2008.

Any ideas? Thank you!

ernesto

unread,
Jan 21, 2010, 1:53:56 PM1/21/10
to NModbus
I've just found out that the server was closing the connection after
replying to each message, so that was the problem. After removing that
behaviour, everything goes fine. Too bad that in .net its somewhat
complicated to detect whether the remote peer has remotely ended the
connection.
Reply all
Reply to author
Forward
0 new messages