串口C++问题 [英] Serial port C++ problem

查看:63
本文介绍了串口C++问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 上使用 C++ 连接到任何串行端口(想要与 Arduino 交换)时遇到问题.

I have a problem connecting to any serial port (want to exchange with an Arduino) using c++ on visual studio.

我正在使用 Arduino 游乐场中提供的 SerialClass,但不能打开我的端口的句柄.每次尝试都会抛出 ERROR_FILE_NOT_FOUND ..

I'm using the SerialClass given in the Arduino playground, but can't open an handle to my port. It throws ERROR_FILE_NOT_FOUND on every try..

我一直在测试许多其他标记端口的方法:

I've been testing many other ways of notating the port:

"COM1"
"COM1:"
"\\.\COM1"

但没有任何效果.

该端口在系统上可用,并且可以使用 Putty 或 Arduino IDE 正常工作.此外,它不会被其他进程阻止.

The port is availiable on the system, and working fine using Putty or the Arduino IDE. Additionally it isn't blocked by other processes.

我使用的是 Windows 7 x64,但项目是 Win32.

I'm using Windows 7 x64, but project is Win32.

类是用

serialPort = new Serial((char*)port);

并且错误字符串显示了正确的端口名.

and the error string shows the right portname.

我做错了什么?

文件打开也不起作用.

推荐答案

找到答案!

我使用 (LPCTSTR) 转换了字符串,但这不会返回有效的字符串.必须使用

I casted the string using (LPCTSTR), but this wouldn't return a valid string. Had to use

const WCHAR FileFullPath[] = {L"COM4"} ;

用于转换.

这篇关于串口C++问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆