阅读:3012回复:2
紧急求教,用函数CreateFile打开 COM10以上的虚拟串口为什么会报错!???
比如虚拟出来 一对串口 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以上串口时,所不能成功! 请教为什么,大家是怎么打开的!? |
|
|
沙发#
发布于: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] |
|
板凳#
发布于:2004-06-30 10:14
谢谢!
|
|
|