Click to See Complete Forum and Search --> : Serial communication


Amateur2005
September 18th, 2005, 06:35 AM
Hello all..

I'm very new to programming with Visual C++.. i'm trying to do serial commuincation (rs232) with a microconcontroller.. i was bit unclear on the ReadFile() function.. if i work in the non-overlapped mode.. will

I declare char buffer[2000];

then i call ReadFile() as:

ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0)

So will ReadFile() only return when i've read in 2000 characters (no less) into buffer ?

What i actually want to do in the end is that when some data is recieved into the serial port i need to check what the 1st character is and then after that if it is say a '#' then store the next 18 bytes into a mysql database..then check again what the next character is..

I'm really confused as how to go about this.. as the data can come in any time.. the program has to sit and monitor if data is coming in and then decide what to do with depending on what it is..

Please help with any ways to go about this.. Thank you..

golanshahar
September 18th, 2005, 06:51 AM
look here at this sample might help you out:
Serial Communications in Win32 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp)

Cheers

Amateur2005
September 18th, 2005, 09:27 AM
I've been reading up on the functions used for Serial Communication.. this statement i read in the MSDN descritipns:

"The ReadFile function returns when one of the following conditions is met: a write operation completes on the write end of the pipe, the number of bytes requested has been read, or an error occurs."

Can someone pls explain this line "a write operation completes on the write end of the pipe" ???

and my earlier question,

I declare char buffer[2000];

then i call ReadFile() as:

ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0)

So will ReadFile() only return when i've read in 2000 characters (no less) into buffer ?

Then according to the msdn description above RaedFile will only return after reading 2000 characters ???

Thank you for your help..