Thank you for your response, This is what I tried:
public static void Main(string[] args)
{
for (int i = 1; i > 0; i++)
{
ModbusClient modbusClient = new ModbusClient("127.0.0.1", 502);
modbusClient.Connect();
int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 10);
Console.WriteLine("Value of A " + " " + readHoldingRegisters[0].ToString());
Console.WriteLine("Value of B " + " " + readHoldingRegisters[1].ToString());
Console.WriteLine("Value of C " + " " + readHoldingRegisters[2].ToString());
Thread.Sleep(1000);
}
After few minutes it goes:
An IOException was unhandled
Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Please help me with this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I got same error. Everything work fine but suddenly it disconnect and then i can't reconnect and get error Connection time out
my code:
private void timer3_Tick(object sender, EventArgs e)
{
timer3.Enabled = false;
int num = 34;
ModbusClient mb3 = new ModbusClient();
try
{
if (!mb3.Connected)
{
//mb3.Port = 1024;
mb3 = new ModbusClient(dtOmron.Rows[2]["IP"].ToString(), 502);
mb3.ConnectionTimeout = 1000;
mb3.Connect();
lblStatus3.Text = dtOmron.Rows[2]["IP"].ToString() + " Connected";
}
I tried to read registers continously in an infinite loop, but it terminates after a while , is there a way to avoid this??
Hi,
could you attach some sourcecode?
Hello,
Thank you for your response, This is what I tried:
public static void Main(string[] args)
{
for (int i = 1; i > 0; i++)
{
ModbusClient modbusClient = new ModbusClient("127.0.0.1", 502);
modbusClient.Connect();
int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 10);
Console.WriteLine("Value of A " + " " + readHoldingRegisters[0].ToString());
Console.WriteLine("Value of B " + " " + readHoldingRegisters[1].ToString());
Console.WriteLine("Value of C " + " " + readHoldingRegisters[2].ToString());
Thread.Sleep(1000);
}
After few minutes it goes:
An IOException was unhandled
Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Please help me with this.
Hi Samuel,
what you could try is either to call the "connect()" method outside the loop, or after reading the values to disconnect.
somthing like:
public static void Main(string[] args)
{
ModbusClient modbusClient = new ModbusClient("127.0.0.1", 502);
for (int i = 1; i > 0; i++)
{
modbusClient.Connect();
int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 10);
Console.WriteLine("Value of A " + " " + readHoldingRegisters[0].ToString());
Console.WriteLine("Value of B " + " " + readHoldingRegisters[1].ToString());
Console.WriteLine("Value of C " + " " + readHoldingRegisters[2].ToString());
modbusClient.Disconnect();
Thread.Sleep(1000);
}
or
public static void Main(string[] args)
{
ModbusClient modbusClient = new ModbusClient("127.0.0.1", 502);
modbusClient.Connect();
for (int i = 1; i > 0; i++)
{
int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 10);
Console.WriteLine("Value of A " + " " + readHoldingRegisters[0].ToString());
Console.WriteLine("Value of B " + " " + readHoldingRegisters[1].ToString());
Console.WriteLine("Value of C " + " " + readHoldingRegisters[2].ToString());
Thread.Sleep(1000);
}
View and moderate all "General Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hi,
It worked, Thank you so much.
I got same error. Everything work fine but suddenly it disconnect and then i can't reconnect and get error Connection time out
my code:
private void timer3_Tick(object sender, EventArgs e)
{
timer3.Enabled = false;
int num = 34;
ModbusClient mb3 = new ModbusClient();
try
{
if (!mb3.Connected)
{
//mb3.Port = 1024;
mb3 = new ModbusClient(dtOmron.Rows[2]["IP"].ToString(), 502);
mb3.ConnectionTimeout = 1000;
mb3.Connect();
lblStatus3.Text = dtOmron.Rows[2]["IP"].ToString() + " Connected";
}
}