开发者

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 availiabl开发者_开发问答e 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜