lovelive淘宝推荐:C#串行通信(数据包的打包与解包)

来源:百度文库 编辑:偶看新闻 时间:2024/04/29 06:37:55

    Control.CheckForIllegalCrossThreadCalls = false;//防止出现所谓的“线程”错误

    int bytes = serialPort1.BytesToRead;//buffer中数据的长度

    byte[] buffer = new byte[bytes];//定义一个长度为bytes的字节数组

    serialPort1.Read(buffer, 0, bytes);      //读取buffer中的数据  

    for (i = 0; i < bytes; i++)

    {

       Dispose(buffer[i]);

    }