Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am developing .net win app to connect Mitsubishi FX5U PLC through Modbus TCP/IP Communication Protocol.

I need to make communication as PLC as Master & PC as Slave.

Can anybody have prepared such code for Connection, WriteSingleRegister and ReadHoldingRegister?

What I have tried:

I have used EasyModbus DLL and tried following code
C#
EasyModbus.ModbusClient myModbusClient = new EasyModbus.ModbusClient();
myModbusClient.IPAddress = "192.168.3.20";
myModbusClient.Port = 502;
myModbusClient.ConnectionTimeout = 2500;
tRead = new Thread(new ThreadStart(Read));
tRead.Start();
if (myModbusClient.Connected == false)
{
    try
    {
        //myModbusClient.Connect();
        myModbusClient.Connect("192.168.3.20", 502);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Disconnected");
    }
}
But I am getting error "No connection could be made because the target machine actively refused it"
Posted
Updated 18-Oct-22 2:38am
v3

1 solution

The error "the target machine actively refused it" means the remote computer has a firewall which is not configured to allow your machine to talk to it on the specified port.

You need to update the firewall rules on the remote computer (192.168.3.20).
 
Share this answer
 
v2
Comments
Prasad G1982 19-Oct-22 5:01am    
Actually I am trying to Connect PLC (Programmable Logic Controller) which does not contain firewall setting

It has only IP Address and PORT Settings.

And on my laptop firewall is set off.
Richard Deeming 19-Oct-22 6:09am    
Then either the port is wrong, or the IP address you're connecting to isn't the PLC. "Actively refused" means something at the remote end received your connection request and rejected it. That's a different error from what you'd get if there was nothing listening on that port, or nothing using the specified IP address.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900