NModbus Response error

1,520 views
Skip to first unread message

Jantje14M

unread,
Jun 2, 2016, 10:36:24 AM6/2/16
to NModbus
Hey,

I am trying to communicate with an array PLC through TCP. But when I want to read something I get the error:
"Response was not of expected transaction ID. Expected 4, received 0."

And when I'm trying to write something:
"Response slave address does not match request. Expected 1, reveived 0."

        TcpClient tcpClient = new TcpClient();

        private void btn_OpenPort_Click(object sender, EventArgs e)
        {
            try
            {
                tcpClient.Connect("192.168.2.35", 502);
                ModbusIpMaster master = ModbusIpMaster.CreateIp(tcpClient);
                
                master.Transport.Retries = 0;

                btn_OpenPort.Text = "Close Port";
                UpdateRTB(comPort.PortName.ToString() + " opened!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        // Read
        private void btn_Read_Click(object sender, EventArgs e)
        {
            // Read inputs
            try
            {
                byte slaveID = 1;           // PLC address
                ushort startAddress = 256;  // Starting address
                ushort numOfPoints = 1;     // Number of coils to read

                bool[] status = ModbusIpMaster.CreateIp(tcpClient).ReadCoils(slaveID, startAddress, numOfPoints);
                for (int i = 0; i < numOfPoints; i++)
                {
                    UpdateRTB(startAddress.ToString() + ": " + status[i]);
                    startAddress++;
                }
                // Output:  <input address>: True/False
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "NModbus Error R1", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        // Write
        private void btn_Write_Click(object sender, EventArgs e)
        {
            // Write marker M
            try
            {
                byte slaveID = 1;           // PLC address
                ushort startAddress = 9728;  // Starting address
                bool value = false;     // value to write
                ModbusIpMaster.CreateIp(tcpClient).WriteSingleCoil(startAddress, value);
                UpdateRTB(startAddress.ToString() + ": " + value.ToString());
                // Output:  <output address>: True/False
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "NModbus Error W1", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

Before I did it with RTU and that worked fine.
I hope someone can catch my fault.

Greetings Jan

Gavin Hill

unread,
Jul 13, 2016, 3:57:52 AM7/13/16
to NModbus
Hi Jan, did you ever find a solution to this problem?  I'm having a similar issue.

Gavin

Umut Nuri KILIÇ

unread,
Oct 18, 2016, 11:03:40 AM10/18/16
to NModbus
Dear Gavin  and Jan,

I am facing same problem and while I am searching any solution for this problem at google, I found this topic. Have you found any solution? If you have, could you please share with me?

2 Haziran 2016 Perşembe 17:36:24 UTC+3 tarihinde Jantje14M yazdı:

Gavin Hill

unread,
Oct 25, 2016, 9:35:33 AM10/25/16
to nmodbus...@googlegroups.com
Umut, I solved my issue by slowing the poll interval and increasing the timeout - it turns out I had a rather slow PLC.


photo
Gavin Hill
Director, Highpeak (Pty) Ltd.
 
Get a signature like this: Click here!

--
You received this message because you are subscribed to a topic in the Google Groups "NModbus" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nmodbus-discuss/o1F9n7kkRTg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nmodbus-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to nmodbus-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/nmodbus-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages