So that's what I want to do. I already have some functions, for example this one to write data to the serial port, which works perfectly:
bool WriteData(char *buffer, unsigned int nbChar)
{
DWORD bytesSend;
//Try to write the buffer on the Serial port
if(!WriteFile(hSerial, (void *)buffer, nbChar, &bytesSend, 0))
{
return false;
}
else
return true;
}
The reading function is like this:
int ReadData(char *buffer, unsigned int nbChar)
{
//Number of bytes we'll have read
DWORD bytesRead;
//Number of bytes we'll really ask to read
unsigned int toRead;
ClearCommError(hSerial, NULL, &status);
//Check if there is something to read
if(status.cbInQue>0)
{
//If there is we check if there is enough data to read the required number
//of characters, if not we'll read only the available characters to prevent
//locking of the application.
if(status.cbInQue>nbChar)
{
toRead = nbChar;
}
else
{
toRead = status.cbInQue;
}
//Try to read the require number of chars, and return the number of read bytes on success
if(ReadFile(hSerial, buffer, toRead, &bytesRead, NULL) && bytesRead != 0)
{
return bytesRead;
}
}
//If nothing has been read, or that an error was detected return -1
return -1;
}
And no matter what I do with the arduino, this function always returns -1, I even tried loading a code that constantly writes a character to the serial port, but nothing.
I got the functions from here: http://playground.arduino.cc/Interfacing/CPPWindows
so my functions are basically the same. I just copied them into my code instead of using them as classes objects, but more than that it's the same.
So that's my problem, I can write data to the serial but I can't read, what can I try?
GetLastError? Are you sure the device is actually giving you something to read?cbInQueis going to fail?