Sample serial port comms code using Async API in .net 4.5?

前端 未结 3 1167
半阙折子戏
半阙折子戏 2020-12-05 22:09

Can anyone point me to a working example that uses the .net 4.5 Async API (async, await, task<>, ReadAsync, etc) to do serial communications?

I\'ve tried to adapt

3条回答
  •  鱼传尺愫
    2020-12-05 22:47

    I think a good deal of your problem is having the user trigger ReadDataAsync, and allowing it to be triggered while there is still a read in progress (from your description).

    The right way to do this is to start a read when the serial port is opened, and in the completion handler for the read, start another one (well, check that the completion wasn't caused by closure of the port).

    Simultaneous reads from a serial port are useless anyway, because you can't control the order in which incoming data will be handed off to complete routines.

提交回复
热议问题