HANDLE hComm = CreateFile( "com10", GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL /*| FILE_FLAG_OVERLAPPED*/, NULL );
if ( INVALID_HANDLE_VALUE==hComm )
{
int err=GetLastError();
TRACE( "Error in open COM port: %s. %d\n", deviceName,err );
return FALSE;
}/////////////
我的机器上一共有20个串口,通过扩展来.
用程序打开 com1 到 com9 都没有问题,但是 com10 开始就出现错误
err=2 ,表示 The system cannot find the file specified. ERROR_FILE_NOT_FOUND ////////////
奇怪的是我通过 CMsComm 空间就可以访问大于10的串口,
代码如下:
void CComTestDlg::OnBUTTONOpen()
{
// TODO: Add your control notification handler code here
try{
m_comm1.SetCommPort(10);
m_comm1.SetPortOpen(TRUE);
MessageBox("Open ok!");
}catch(...){
MessageBox("ERROR Open Comm");
}
}///////////////////
请问,用文件方式如何解决这个问题?
路过的都帮助顶一下
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL /*| FILE_FLAG_OVERLAPPED*/, NULL );
if ( INVALID_HANDLE_VALUE==hComm )
{
int err=GetLastError();
TRACE( "Error in open COM port: %s. %d\n", deviceName,err );
return FALSE;
}/////////////
我的机器上一共有20个串口,通过扩展来.
用程序打开 com1 到 com9 都没有问题,但是 com10 开始就出现错误
err=2 ,表示 The system cannot find the file specified. ERROR_FILE_NOT_FOUND ////////////
奇怪的是我通过 CMsComm 空间就可以访问大于10的串口,
代码如下:
void CComTestDlg::OnBUTTONOpen()
{
// TODO: Add your control notification handler code here
try{
m_comm1.SetCommPort(10);
m_comm1.SetPortOpen(TRUE);
MessageBox("Open ok!");
}catch(...){
MessageBox("ERROR Open Comm");
}
}///////////////////
请问,用文件方式如何解决这个问题?
路过的都帮助顶一下
解决方案 »
- 使用TAB控件显示对话框前,对话框大小可以改变吗?代码如下~~
- 如何在创建listview后调整四种不同形式如report、 small icom、 list
- 高分求CStatic 滚动字幕效果的源玛,在线等
- 有熟悉向打印机写数据的吗,帮忙看看是什么问题?谢谢了
- 高分求 图形绘制类例程,给出下载地址也有分
- 为什么我使用dll的时候跟踪进入dll函数,此时能打开我写的dll源文件,是不是有什么编译选项设置?
- 如何用vc实现后期绑定?
- 请教各位,在listview中用大图标显示,如何设定Imagelist?
- 有劳斑竹和各位高手了
- 怎样制作一个像媒体播放器中播放按钮那样的按钮。
- 怎么MDIGetActive()出错啊?
- 贺
The information in this article applies to:Microsoft Win32 Application Programming Interface (API), used with:
Microsoft Windows NT Server versions 3.5, 3.51, 4.0
Microsoft Windows NT Workstation versions 3.5, 3.51, 4.0
Microsoft Windows 95
the operating system: Microsoft Windows 2000--------------------------------------------------------------------------------
SUMMARY
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 messageINVALID_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.