How do I use dataReceived event of the SerialPort Port Object in C#?

后端 未结 7 1721
無奈伤痛
無奈伤痛 2020-11-28 07:26

I am attempting to create a small application to collect data received from an external sensor attached to COM10. I have successfully created a small C# console object and

相关标签:
7条回答
  • 2020-11-28 08:00

    Be aware that there are problems using .NET/C# and any COM port higher than COM9.

    See: HOWTO: Specify Serial Ports Larger than COM9

    There is a workaround in the format: "\\.\COM10" that is supported in the underlying CreateFile method, but .NET prevents using that workaround format; neither the SerialPort constructor nor the PortName property will allow a port name that begins with "\"

    I've been struggling to get reliable communications to COM10 in C#/.NET. As an example, if I have a device on COM9 and COM10, traffic intended for COM10 goes to the device on COM9! If I remove the device on COM9, COM10 traffic goes to the device on COM10.

    I still haven't figured how to use the handle returned by CreateFile to create a C#/.NET style SerialPort object, if I knew how to do that, then I think I could use COM10+ just fine from C#.

    0 讨论(0)
提交回复
热议问题