打开 COM 端口时调试断言失败
Debug Assertion Failed during opening COM port
我正在开发一个程序,使用 Arduino UNO 从接近传感器获取读数。虽然我可以使用 Arduino 的内置串行监视器获得读数,但不知何故我无法从 MS VC++.
打开相同的端口
以下为(部分)程序:
int main(void)
{
/*used for port"COM13"*/
HANDLE hCom=INVALID_HANDLE_VALUE;
char input[30];
string ss,ss1,ss2,ss3,ss4;
/*Open "COM13"*/
hCom=CreateFile("COM13",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(hCom==INVALID_HANDLE_VALUE)
{
printf("can't open file");
}
/*Communication Setting*/
DCB dcb;
memset(&dcb,0,sizeof (DCB));
dcb.DCBlength=sizeof (DCB);
dcb.BaudRate=CBR_9600;
dcb.ByteSize=8;
dcb.Parity=NOPARITY;
dcb.StopBits=ONESTOPBIT;
SetCommState(hCom,&dcb);
while(1)
{
//using the data string inputs, printout the readings, process it etc...
}
}
当我尝试调试它时,我会得到这个错误:
我从调试 windows 得到 can't open file
显示在打开端口时出现问题。
一些附加信息:
- 为什么 VC++?我还在同一程序中使用 OpenCV 和一些数学计算,因此我可以更轻松地在 VC++
中工作
- 我还使用 TeraTerm 测试了我的 UNO 程序的数据读取没有问题(=我的 UNO 没有问题)
- 我已经用另一个微控制器(非 Arduino)测试了上面的程序没有问题。
如果需要,我会上传我的 UNO 程序。
提前致谢!
来自 CreateFile 上的 MSDN 页面:
To specify a COM port number greater than 9, use the following syntax:
"\.\COM10". This syntax works for all port numbers and hardware that
allows COM port numbers to be specified.
我正在开发一个程序,使用 Arduino UNO 从接近传感器获取读数。虽然我可以使用 Arduino 的内置串行监视器获得读数,但不知何故我无法从 MS VC++.
打开相同的端口以下为(部分)程序:
int main(void)
{
/*used for port"COM13"*/
HANDLE hCom=INVALID_HANDLE_VALUE;
char input[30];
string ss,ss1,ss2,ss3,ss4;
/*Open "COM13"*/
hCom=CreateFile("COM13",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(hCom==INVALID_HANDLE_VALUE)
{
printf("can't open file");
}
/*Communication Setting*/
DCB dcb;
memset(&dcb,0,sizeof (DCB));
dcb.DCBlength=sizeof (DCB);
dcb.BaudRate=CBR_9600;
dcb.ByteSize=8;
dcb.Parity=NOPARITY;
dcb.StopBits=ONESTOPBIT;
SetCommState(hCom,&dcb);
while(1)
{
//using the data string inputs, printout the readings, process it etc...
}
}
当我尝试调试它时,我会得到这个错误:
我从调试 windows 得到 can't open file
显示在打开端口时出现问题。
一些附加信息:
- 为什么 VC++?我还在同一程序中使用 OpenCV 和一些数学计算,因此我可以更轻松地在 VC++ 中工作
- 我还使用 TeraTerm 测试了我的 UNO 程序的数据读取没有问题(=我的 UNO 没有问题)
- 我已经用另一个微控制器(非 Arduino)测试了上面的程序没有问题。
如果需要,我会上传我的 UNO 程序。
提前致谢!
来自 CreateFile 上的 MSDN 页面:
To specify a COM port number greater than 9, use the following syntax: "\.\COM10". This syntax works for all port numbers and hardware that allows COM port numbers to be specified.