十个以上串口加载问题-用CREATEFILE打开COM10

用CREATEFILE 打开1-9的串口没问题,但是打开COM10之类的串口号就返回-1了,请问是什么问题呢?

=========================分割线=================================

CreateFile() 可获得到串行端口的句柄。 "Win 32 编程人员参考"项"CreateFile() 提及的共享模式必须是 0 中,创建参数必须是 OPEN_EXISTING,并且该模板必须为 NULL。

文件名中,使用"COM 1"到"COM9 时 CreateFile() 是否成功但是,邮件
INVALID_HANDLE_VALUE
如果您使用"COM10 返回或更高版本。

如果端口的名称为 //./COM10,CreateFile() 调用中指定串行端口,正确方法是,如下所示:
   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: 此语法也适用于通过 COM9 的 COM 1 端口。 某些板将允许您选择端口名称自己。 该语法适用于这些名称。

在MSDN->Device File Names中,明确说了CreateFile的三种参数,亦即设备名称有三种表示方式:
    "COMX:",
    "/$device/COMX",
    "/$bus/PCMCIA_0_0_0"。
 其中第一种方式只适合从0~9的设备名,亦即COM10:中10超出了设备命名规范,所以用CreateFile打开设备失败。
 使用第二种方式/$device/COM10,作为参数传递给CreateFile,成功打开COM口,通讯正常,搞定。
 第三种是用在总线驱动上的,暂时没涉及到


You   can   use   paths   longer   than   MAX_PATH   characters   by   calling   the   wide   (W)   version   of   CreateFile   and   prepending   "//?/"   to   the   path.   The   "//?/"   tells   the   function   to   turn   off   path   parsing.   This   lets   you   use   paths   that   are   nearly   32,000   Unicode   characters   long.   However,   each   component   in   the   path   cannot   be   more   than   MAX_PATH   characters   long.   You   must   use   fully-qualified   paths   with   this   technique.   This   also   works   with   UNC   names.   The   "//?/"   is   ignored   as   part   of   the   path.   For   example,   "//?/C:/myworld/private"   is   seen   as   "C:/myworld/private",   and   "//?/UNC/tom_1/hotstuff/coolapps"   is   seen   as   "//tom_1/hotstuff/coolapps".

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值