CreateFile 串口打不开,如下代码.....
hCom=CreateFile("COM15", // 文件名
GENERIC_READ | GENERIC_WRITE, // 允许读和写 
0, // 独占方式
NULL, 
OPEN_EXISTING, //打开而不是创建
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, // 重叠方式
NULL
);


if(hCom==INVALID_HANDLE_VALUE)
{
AfxMessageBox("打开COM失败!");
int   err=GetLastError();   
CString st;
st.Format(   "Error   in   open   COM   port:  %d\n", err   ); 
MessageBox(st);  
return;
}

解决方案 »

  1.   

    用超级终端连接com15是正常的.
      

  2.   

    "\\\\.\\COM15"
    用UNC,仔细看MSDN中CreateFile的说明
      

  3.   

    用CreateFile的方式打开串口,对于小于10的串口号来说,file name 可以用"COM1"这样来表示,但对于大于10(包括10)的串口好,必须使用"\\\\.\\COM15"这样的格式,这可以说是WINDOWS早期的一个缺陷吧。
      

  4.   


    偶使用的是VC++ 6.0 要使用哪个版本的MSDN?
      

  5.   

    哪个版本的都可以,书写格式上改一下就可以了,你的PC上用的是MOX卡吧
      

  6.   

    http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
    //关于 “Win32 Device Namespaces”
      

  7.   

    你可以查 MSDN library october 2001, createfile 函数的说明中:String Meaning 
    \\.\PHYSICALDRIVE2 Obtains a handle to the third physical drive on the user's computer. 
    Tape Drives
    Windows NT/2000/XP: You can open tape drives using a file name of the form \\.\TAPEx where x is a number indicating which drive to open, starting with tape drive 0. To open tape drive 0 in C, use the file name "\\\\.\\TAPE0". For more information on manipulating tape drives for backup or other applications, see Tape Backup.