简体   繁体   中英

Serial port C++ problem

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.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM