System.IO.IOException when polling Siemens Logo device

95 views Asked by At

I am new to Modbus and UWA and i was trying to make an application that read the status of input 1, output 1 and output 2 from my Siemens Logo device (6ED1052-1HB08-0BA0 LOGO! 24RCE). The Logo is running a simple test program. Here is the code i come up with so far.

(other packages)
using EasyModbus;
using System.Net.Sockets;

namespace AC_C_Demo
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>

    public sealed partial class MainPage : Page
    {       
        private ModbusClient modbusClient;

        public MainPage()
        {
            this.InitializeComponent();
            modbusClient = new ModbusClient("192.168.0.3", 502); // Replace with your device's IP address and port
            ReadModbusData_Click();
        }
        private async void ReadModbusData_Click()
        {
                modbusClient.Connect();
                while (true)
                {
                    // Read input 1
                    bool i1Value = modbusClient.ReadDiscreteInputs(0, 1)[0];"I1"
                    // Read output 1
                    bool q1Value = modbusClient.ReadCoils(0, 1)[0];

                    // Read output 1
                    bool q2Value = modbusClient.ReadCoils(1, 1)[0];

                    // Display the values in TextBlocks
                    InputStatusTextBlock.Text = "I1: " + i1Value.ToString();
                    //   Q1ValueTextBlock.Text = "Q1: " + q1Value.ToString();
                    //   Q2ValueTextBlock.Text = "Q2: " + q2Value.ToString();
                }                        
        }
    }
}

however the line bool i1Value = modbusClient.ReadDiscreteInputs(0, 1)[0]; is giving me the following error:

System.IO.IOException: 'Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.'

SocketException: An existing connection was forcibly closed by the remote host

I do not know what is causing it, I have the device connected by Ethernet and have already configured my connection to be in range, and I already tried turning off my firewall and nothing changed.

or is there a better way to do what am trying to achieve?

I tried different Modbus packages and ended with the same issue.

1

There are 1 answers

0
Evgeniy On

I'm not familiar with Siemense PLC ladder. Can recommend to copy your Discrete Input value to Boolean tag. Give this tag an address and read all your data as coils bool q1Value = modbusClient.ReadCoils(0, 3)[3];

enter image description here