1

我有一个非常奇怪的问题,我正在传输一个 105 字节 [] 缓冲区,并在另一端不断接收116 字节。

原始数据的最后 2 个字节是CRC16

我用于传输的代码是,它永远循环。

    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();
    }

我在另一边不断得到的是以下 116 个字节(消息以原始CRC字节结尾是多么奇怪??)

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, 

任何帮助将不胜感激,以解决此问题,

谢谢

4

1 回答 1

1

我发现了问题,

似乎在 Tibbo 模块上启用了“带内命令”设置,在禁用它后,它停止用额外的 0xFF 字节“填充”0xFF 字节。

非常奇怪,因为它不会对发送大量 0xFF 字节的原始 modbus 从站执行此操作。

于 2013-02-28T09:29:21.487 回答