How to open COMXX files(serial port)

前端 未结 1 789
故里飘歌
故里飘歌 2021-01-19 11:38

I\'ve problem with serial port.

I\'ve written a program that can read ports COM1 to COM9, but can open COMXX(like com10, com11, etc.)

I\'ve searched and lear

相关标签:
1条回答
  • 2021-01-19 12:12

    You need to escape the backslashes in the filename parameter:

    myPort = CreateFile("\\\\.\\COM14",
                  GENERIC_READ | GENERIC_WRITE,
                  0,    /* exclusive access  */
                  NULL, /* no security attrs */
                  OPEN_EXISTING,
                  0,
                  NULL );
    

    You're also trying to open COM port 14. Do you really have 14 COM ports on your machine? Try COM1 instead.

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