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 に答える