jickknight
驱动牛犊
驱动牛犊
  • 注册日期2004-05-03
  • 最后登录2005-12-27
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2966回复:2

紧急求教,用函数CreateFile打开 COM10以上的虚拟串口为什么会报错!???

楼主#
更多 发布于:2004-06-29 21:09
比如虚拟出来 一对串口 COM3<==>COM10 ,但是在执行
CreateFile(portName,  // Specify port device: default "COM1"
          GENERIC_READ | GENERIC_WRITE,      
                     // Specify    mode that open device.
           0,        // the devide isn't shared.
        NULL,        // the object gets a default security.
    OPEN_EXISTING, // Specify which action to take on file.
    0,            // default.
    NULL);

这个标准函数打开COM 10以上串口时,所不能成功!

请教为什么,大家是怎么打开的!?
Chasing my dreams!
KMK
KMK
驱动大牛
驱动大牛
  • 注册日期2001-09-12
  • 最后登录2017-10-06
  • 粉丝2
  • 关注0
  • 积分42分
  • 威望404点
  • 贡献值2点
  • 好评度58点
  • 原创分1分
  • 专家分1分
  • 社区居民
沙发#
发布于:2004-06-30 08:00
 
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.




http://support.microsoft.com/?id=115831



[编辑 -  6/30/04 by  KMK]
jickknight
驱动牛犊
驱动牛犊
  • 注册日期2004-05-03
  • 最后登录2005-12-27
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-06-30 10:14
谢谢!
Chasing my dreams!
游客

返回顶部