SerialPort port.open “The port 'COM2' does not exist.”

前端 未结 2 826
太阳男子
太阳男子 2021-02-14 09:59

I\'m having a big problem with the SerialPort.Open();

I am communicating with an usb virtual com port (cdc), and it is listed as COM2.

It works fine

2条回答
  •  失恋的感觉
    2021-02-14 10:34

    I've worked with virtual serial ports before. Oftentimes they aren't accessible as "COMX:" to some windows API calls, and you have to fully specify them. That might be the case here. Try using the Windows device namespace path for the serial device. For example: "\\.\COM2"

    Another thing I've found useful for debugging is opening up a Hyperterm on the given serial port.

    One final thing: For debugging your logic on systems that don't have all the hardware, I found this wonderful program called com0com. It is a GPL Sourceforge project that creates tied pairs of virtual com ports on your system. Whatever is written to one can be read from the other, and visa versa. You can either write an emulator and give it one of the ports, or just open up Hyperterm on it. Then give the other to your program. Testing with no cables or other hardware required.

提交回复
热议问题