Question

I have a very strange problem, i am transmitting an 105 byte[] buffer, and constantly receiving 116 bytes on the other side.

The last 2 bytes on the original data is CRC16

The code that I am using for transmission is, its looping forever.

    static SerialPort sp = null;
    static void Main(string[] args)
    {
         //105 bytes send buffer
        byte[] data = new byte[] {0xa,0x03,0x64,0x0e,0x15,0x00,0x01,0x00,
                                  0x01,0x00,0x06,0x00,0x23,0x00,0x5f,0x00,
                                  0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,
                                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                  0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,
                                  0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,
                                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                  0x00,0x00,0x00,0x25,0xb8,0x00,0x05,0xff,
                                  0x23,0x00,0x00,0x00,0x00,0x00,0xa2,0x00,
                                  0x00,0x02,0x20,0x00,0x04,0x00,0x03,0x00,
                                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                  0x01,0x00,0x00,0x00,0x01,0x00,0x1f,0x00,
                                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xae,
                                  0x1f
        };

        Console.WriteLine("Serial Port Test");
        sp = new SerialPort("COM1", 19200);
        sp.Open();
        if (sp.IsOpen)
        {
            Console.WriteLine("Begining to transmit serial data..");
        }
        for (; ; )
        {
            Thread.Sleep(1000);
            sp.Write(data,0,data.Length);
            sp.DiscardOutBuffer();
        }

        Console.WriteLine("End of transmission");
        Console.ReadKey();
    }

What i constantly get on the other side is the following 116 bytes (How strange is it that the message ends with the original CRC bytes??)

0xa, 0x03, 0x64, 0x0e, 0x15, 0x00, 0x01, 0x00,
0x01, 0x00, 0x06, 0x00, 0x23, 0x00, 0x5f, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0xb8, 0x00,
0x05, 0xff, 0xff, 0x23, 0x00, 0x00, 0x00, 0x00,
0x00, 0xa2, 0x00, 0x00, 0x02, 0x20, 0x00, 0x04,
0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xae, 0x1f, 

Any help will be appreciated to fix this issue,

Thank you

Was it helpful?

Solution

I found the issue,

It seems "Inband commands" setting was enabled on the Tibbo module, and after disabling it, it stopped "padding" the 0xFF bytes with extra 0xFF bytes.

Very strange, since it does not do this with the original modbus slave which sends lots of 0xFF bytes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top