串口C++问题

发布于 2024-09-30 22:58:53 字数 595 浏览 0 评论 0原文

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

我正在使用 Arduino Playground 中提供的 SerialClass,但无法打开手柄到我的港口。每次尝试都会抛出 ERROR_FILE_NOT_FOUND 。

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

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

但没有任何效果。

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

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

该类是用

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

构造的,错误字符串显示正确的端口名称。

我做错了什么?

文件打开也不起作用。

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

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"

but nothing's working.

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

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

The class is constructed with

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

and the error string shows the right portname.

What I'm doing wrong?

File opening isn't working, too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少女净妖师 2024-10-07 22:58:53

此处是其他人手动使用 api 打开串行端口的一个很好的示例。相关部分(关于您的问题)显示它们使用端口号,如下所示:

...
CreateFile("\\\\.\\COM1",GENERIC_WRITE
...

因此它可能是 \\\\.\\COM1 而不是您尝试过的选项。

A good example of others manually using the api to open a serial port is here. The relevant part (regarding your question) shows them using the port number as follows:

...
CreateFile("\\\\.\\COM1",GENERIC_WRITE
...

so it could be \\\\.\\COM1 instead of the options you have tried.

春夜浅 2024-10-07 22:58:53

找到答案了!

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

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

进行转换。

Found the Answer!

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

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

for conversion.

时光倒影 2024-10-07 22:58:53

您确定这不是 Windows 7 64 位的驱动程序问题吗?

Are you sure this isnt a driver problem with Windows 7 64 bit ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文