Hi guys,
I've been trying to develop some code on C++ using Visual C++ 2008 Express Edition. Inside the code i wanted to use the serial interface to send messages to Arduino, but for some reason it is not working.
When i send messages to the serial port, the Arduino's leds for serial communication don't even blink. I suppose it is not receiving any information, because it doesn't react to incoming messages.
On the C++ side, it creates the serial port succesfully without errors. It also sends message through the serial port without returning any error. What is wrong?
In my C++ code I use three different functions: one to initialize serial port, another to close serial port and one to send messages.
The code for serial initializing is the following:
int initSerial(){
hSerial = CreateFile(TEXT("COM11"),
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if(hSerial == INVALID_HANDLE_VALUE)
{
return false;
}
DCB dcb;
if( !GetCommState(hSerial, &dcb))
return false;
dcb.BaudRate = CBR_9600;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
dcb.StopBits = ONESTOPBIT;
if( SetCommState(hSerial, &dcb) == 0 )
return false;
}
The code for serial closing is the following:
void terminateSerial()
{
CloseHandle( hSerial );
}
The code for sending messages to the serial port is:
void escreveSerial(char MSG[1000])
{
DWORD BytesEscritos = 0;
if(!WriteFile( hSerial, MSG, strlen(MSG), &BytesEscritos, NULL ))
printf("Error Writefile!\n");
}
Has anyone here ever worked with serial communication that could help me?
Thanks!