0

I first say that I'm new to modbus world and I never heard before of it. I've been asked to interface to a Modbus.Slave (which simulates a real modbus environment) using ModBus.Net.Modbus/Modbus.Net.

The first thing I'm unable to do is to connect to the Slave. I've read the docs and put the following code

private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        if (machine == null)
        {
            machine = new ModbusMachine(ModbusType.Tcp, "127.0.0.1:504", new List<AddressUnit>()
            {

                new AddressUnit()
                {
                    Id = "1",
                    Area = "4X",
                    Address = 1,
                    CommunicationTag = "Add1",
                    DataType = typeof(ushort),
                    Zoom = 1,
                    DecimalPos = 0
                }
            }, 2, 0);


        }


        machine.KeepConnect = true;
        machine.Connect();
        var resultFormat = (await machine.GetDatasAsync(MachineGetDataType.CommunicationTag))
            .MapGetValuesToSetValues();
    }

Now ModBus.Slave is running on localhost on port 504, in the way I've tried (since I've found no Port property) it never connects.

Anyone is using such a library and can help me spotting how to setup connection? Thanks

advapi
  • 3,661
  • 4
  • 38
  • 73
  • What do you mean by "never connects"? Hangs? Socket error? Do you see the port in `netstat`? – Kit Jul 18 '18 at 16:39
  • it returns IsConnected = false after the connect...no error at all...I've not tried with netstat – advapi Jul 18 '18 at 16:45

0 Answers0