Problem with serial port data receive in C#

前端 未结 6 1919
梦谈多话
梦谈多话 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:14

    Try make a length check for each variable assignment like this:

    string acct = (data.length >= 81) ? data.Substring(76, 5) : string.empy;
    

    The data.length could be shorter than the total length of your substring (76 + 5).

提交回复
热议问题