串口号大于10就打不开?

打开大于10的串口

大坑

我们一般打开串口的时候使用的接口为

CreateFile( 
              "COM1",          //  address  of  name  of  the  communications  device 
              GENERIC_READ | GENERIC_WRITE,                    //  access  (read-write)  mode 
              0,                                    //  share  mode 
              NULL,                              //  address  of  security  descriptor 
              OPEN_EXISTING,            //  how  to  create 
              GENERIC_READ | GENERIC_WRITE,                                    //  file  attributes 
              NULL                                //  handle  of  file  with  attributes  to  copy 
        ); 

但是使用这个接口去打开串口的时候,突然出现串口打不开的情况,是咋回事呢?稍微查了下,原来是因为这个接口压根不支持。>_<心累,还好改起来比较简单。

解决

还是用这个方法,只是串口号的描述方式改变了。然后正常使用就好了。

CreateFile( 
              "\\\\.\\COM10",          //  address  of  name  of  the  communications  device 
              GENERIC_READ | GENERIC_WRITE,                    //  access  (read-write)  mode 
              0,                                    //  share  mode 
              NULL,                              //  address  of  security  descriptor 
              OPEN_EXISTING,            //  how  to  create 
              GENERIC_READ | GENERIC_WRITE,                                    //  file  attributes 
              NULL                                //  handle  of  file  with  attributes  to  copy 
        ); 

おすすめ

転載: blog.csdn.net/u012505629/article/details/121631476