초보의 아웅다웅 설계하기/비주얼 C#

Uart 데이터 Byte 입력상의 입력 사이즈 초기화

로망와니 2018. 8. 28. 08:52

C#에서 입력 Uart 처리 

입력 사이즈를 확인하였던 intRecSize를 초기화해 주지 않으니 0x00의 비어있는 값이 버퍼에 쌓이는 경우가 있었습니다.



      private void ComPort_DataReceived(object sender, SerialDataReceivedEventArgs e)

        {

            if (rbAscii.Checked == true)

            {

                InputData = ComPort.ReadExisting();

                if (InputData != String.Empty)

                {

                    this.BeginInvoke(new SetTextCallback(SetText), new object[] { InputData });

                }

            }

            else

            {

  /* 입력된 데이터 량 */

                int intRecSize = ComPort.BytesToRead;


                while (intRecSize != 0)

                {

                    TimerCnt = 0;

                    byte[] buff = new byte[intRecSize];


                    ComPort.Read(buff, 0, intRecSize); 

                    

                    /* 입력된 데이터 처리 */



 intRecSize = 0;        

 }

   }

}