GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-May-2006, 16:28
slippygod slippygod is offline
New Member
 
Join Date: May 2006
Posts: 7
slippygod is on a distinguished road

Receiving data over serial port


I'm programming a C++ console app that receives data over the serial port and does some number crunching on it. I got the serial library over at http://www.codeproject.com/system/serial.asp . I'm hoping someone here is familiar with it, because I'm having problems using it.
First all, I know that the input data is a series of 6 bytes at a baud rate of 115200, no handshaking, and theoretically continues forever. I am using a serial port monitoring program and can confirm that this data is being sent properly. The problem is that my program receives the data, but at varying byte intervals, ranging from 9 to too-many-to-count. There are no control codes or anything in the stream, so if it doesn't read in the 6 bytes per read then the rest of the data won't be correct.

CPP / C++ / C Code:
	serial_in.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);

	serial_in.SetMask(CSerial::EEventRecv);

	do
	{
		serial_in.WaitEvent();

		DWORD dwBytesRead = 0;
		char szBuffer[7];

		do
		{
			serial_in.Read(szBuffer,sizeof(szBuffer)-1,&dwBytesRead);
			if (dwBytesRead > 0)
			{
				szBuffer[dwBytesRead] = '\0';

		
			}
		}
		while (dwBytesRead == sizeof(szBuffer)-1);
		
		[do calculations here]
	}
	while(true)

I figure the code won't mean much to people who haven't used this specific library, but I'm hoping that someone can give me a hand.
Any help would be appreciated!
Last edited by admin : 23-May-2006 at 06:50. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 03-Aug-2006, 08:32
soldstatic soldstatic is offline
New Member
 
Join Date: Jul 2006
Posts: 16
soldstatic is on a distinguished road

Re: Receiving data over serial port


i dont know anything about that library, but i looked at it when I was going to do all my serial port stuff. ended up finding some really good howto kinda stuff, which i basically threw together in this post:

http://www.gidforums.com/showthread.php?p=46273

i had a ton of trouble trying to get this and that class working and eventually just had to dig in and do it that way^, but it turned out to be really easy since I basically copy and pasted the code into my prog and it worked.

maybe itll help you? if not good luck!
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Strange C++ code memory leakage problem gaoanyu C++ Forum 7 04-Nov-2005 08:09
Problem to read on a serial port collinm C Programming Language 2 30-Mar-2005 01:42
Problem with string and serial port collinm C Programming Language 13 25-Mar-2005 07:39
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:44.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.