Serial port programming c++

Jan 19, 2012 at 11:42pm
Hello,

I am fairly new to C++ and very new to serial port programming. So new that I am not even 100% sure about my definitions...so to start, from googling I believe my definitions of streaming vs polling are:

streaming: open serial port, data is continuously following into buffer until I read it.

Polling: I make a specific request for data, and then data is returned back to me.

So, I am writing a windows based program using MS visual studio. My program is continuously reading data (observations) from a serial port. However, at some point (lets say every 2 hours) I would like to POLL the serial port and ask for specific information (the version of software being run on the hardware for example).

Some exerts (really more like pseudocode) of my code are shown below.

For streaming continuous data:

while(m_bProcess)
{
try
{
Result=ReadFile(hcomm, buff,sizeof(buff), &bytesread, NULL);
if (bytesread >0)
{
WriteToLog(buff,bytesread);
}
}
}

So my question is how do I poll a specific data request at the same time? Do I need to stop this process first and then reopen it after? OR can I simply use writeFile to send my request and it should appear in my buffer as shown below:

while(m_bProcess)
{
try
{
Result=ReadFile(hcomm, buff,sizeof(buff), &bytesread, NULL);
if (bytesread >0)
{
WriteToLog(buff,bytesread);
}
DWORD dwWriteCnt = 0;
Sleep(DELAY_TIME*20);
WriteFile(hComm,POLL_REQUEST,10,&dwWriteCnt,NULL);
Sleep(DELAY_TIME);
}
}



If anymore information is required, please don't hesitate to ask.

Thanks!
Jan 20, 2012 at 3:28am
This MSDN article looks pretty good http://msdn.microsoft.com/en-us/library/ms810467 Particularly the overlapped i/o section looks like it might be helpful.
Topic archived. No new replies allowed.