How to Access Serial Ports Greater Than COM9 Using C/C++

The following is a tech note published by Microsoft, regarding a solution to accessing com ports above Com 9.

 

HOWTO: Specify Serial Ports Larger than COM9Last reviewed: January 20, 1997
Article ID: Q115831

The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:
        - Microsoft Windows NT versions 3.1, 3.5, 3.51, 4.0
        - Microsoft Windows 95 version 4.0

CreateFile() can be used to get a handle to a serial port. The "Win32 Programmer's Reference" entry for "CreateFile()" mentions that the share mode must be 0, the create parameter must be OPEN_EXISTING, and the template must be NULL.

CreateFile() is successful when you use "COM1" through "COM9" for the name of the file; however, the message "INVALID_HANDLE_VALUE" is returned if you use "COM10" or greater.

If the name of the port is //./COM10, the correct way to specify the serial port in a call to CreateFile() is as follows:

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

NOTES: This syntax also works for ports COM1 through COM9. Certain boards will let you choose the port names yourself. This syntax works for those names as well.

Additional reference words: 3.10 3.50 4.00 95
KBCategory: kbprg kbhowto
KBSubcategory: BseCommapi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值