Problem with serial port data receive in C#

前端 未结 6 1942
梦谈多话
梦谈多话 2021-01-15 21:40

I have a problem with a C# program. Through the Serial port i Receive a large string about 110 characters. This part works ok, but when i add code to split the string up i r

6条回答
  •  无人及你
    2021-01-15 22:00

    You don't check what you have enough data before processing. SerialPort.ReadExisting Method just

    Reads all immediately available bytes, based on the encoding, in both the stream and the input buffer of the SerialPort object.

    Your device maybe just don't have time to pass all data. So you need rewrite your logic to concatenate incoming data and process it after receiving enough data.

提交回复
热议问题