SerialPort not receiving any data

前端 未结 3 994
一生所求
一生所求 2020-11-22 11:40

I am developing program which need to interact with COM ports.

By learning from this Q&A: .NET SerialPort DataReceived event not firing, I make my code like that

3条回答
  •  青春惊慌失措
    2020-11-22 12:10

    I have never worked with VSPE so I'm not sure if that causes the problem. I have worked with a COM port before and I looked up my code. The only main difference is the way you declare the event. You have:

    ComPort.DataReceived += OnSerialDataReceived;
    

    I have it like this:

    ComPort.DataReceived += new SerialDataReceivedEventHandler(OnSerialDataReceived);
    

    OnSerialDataReceived is your eventhandler. I'm not sure if this will make any difference, but you can try it. I hope this helps!

提交回复
热议问题