Click here to Skip to main content
15,902,189 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: VC++ & Interbase Pin
Eytukan3-Oct-05 7:11
Eytukan3-Oct-05 7:11 
GeneralRe: VC++ & Interbase Pin
Eytukan3-Oct-05 7:11
Eytukan3-Oct-05 7:11 
Questionstatic text Pin
FarPointer29-Sep-05 3:58
FarPointer29-Sep-05 3:58 
AnswerRe: static text Pin
Ashok Dhamija29-Sep-05 5:06
Ashok Dhamija29-Sep-05 5:06 
GeneralRe: static text Pin
FarPointer29-Sep-05 7:34
FarPointer29-Sep-05 7:34 
GeneralRe: static text Pin
ThatsAlok29-Sep-05 18:04
ThatsAlok29-Sep-05 18:04 
AnswerRe: static text Pin
douglasjordan29-Sep-05 10:38
douglasjordan29-Sep-05 10:38 
QuestionIssues with ReadFile function Pin
Aditi48429-Sep-05 3:47
Aditi48429-Sep-05 3:47 
Hello..

I'm trying to read in data coming from the serial port.. the data can come in at any time (so the program has to monitor the serial port continuously, thats why i'm using a while loop in my code below). I'm reading Tag IDs (strings) which are formatted into packets.. each packet starts with the '&' character and ends with the '$' character..

Right now I read in the whats coming from the serial port (using a infinite while loop) into a string and then tokenize that string according to my packet delimiters.. the problem is that Readfile is returning after getting part of the tag ID packet and then the remaining part of the tag ID packet comes the next time the while loop is called.. I think its something to do with the way I use the readfile function in the while loop..my code is given below.. Please advice..

Thank you for your help..

<br />
<br />
char buffer[200000];<br />
<br />
 while (true)<br />
	{<br />
		printf("In while\n"); <br />
			<br />
		memset(buffer, 0, sizeof(buffer));<br />
		if (ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0))<br />
		{<br />
			printf("Read file has a result\n"); <br />
			if (bytesRead != 0)<br />
			{<br />
				printf("Got some bytes\n"); <br />
				printf ("%s", buffer);<br />
<br />
	//testing if buffer is broken down properly <br />
				printf( "Tokens in buffer:\n" );<br />
	/* Establish string and get the first token: */<br />
				token = strtok(buffer, "&$" );<br />
   <br />
				while( token != NULL )<br />
				{<br />
					/* While there are tokens in "string" */<br />
					printf( " %s\n", token );<br />
					/* Get next token: */<br />
					token = strtok( NULL, "&$" );<br />
				}<br />
<br />
			}<br />
			<br />
			else <br />
			{<br />
				printf("No bytes read\n"); <br />
			}<br />
		}<br />
<br />
		else {<br />
			printf("Readfile didnt give proper result \n"); 	<br />
		}<br />
		Sleep(200);<br />
	}<br />
<br />

AnswerRe: Issues with ReadFile function Pin
Cedric Moonen29-Sep-05 4:05
Cedric Moonen29-Sep-05 4:05 
GeneralRe: Issues with ReadFile function Pin
Aditi48429-Sep-05 4:34
Aditi48429-Sep-05 4:34 
AnswerRe: Issues with ReadFile function Pin
David Crow29-Sep-05 7:05
David Crow29-Sep-05 7:05 
AnswerRe: Issues with ReadFile function Pin
Aditi48430-Sep-05 2:59
Aditi48430-Sep-05 2:59 
GeneralRe: Issues with ReadFile function Pin
David Crow30-Sep-05 3:13
David Crow30-Sep-05 3:13 
GeneralRe: Issues with ReadFile function Pin
Aditi48430-Sep-05 4:28
Aditi48430-Sep-05 4:28 
GeneralRe: Issues with ReadFile function Pin
David Crow30-Sep-05 4:49
David Crow30-Sep-05 4:49 
GeneralRe: Issues with ReadFile function Pin
Aditi48430-Sep-05 5:21
Aditi48430-Sep-05 5:21 
GeneralRe: Issues with ReadFile function Pin
David Crow30-Sep-05 5:29
David Crow30-Sep-05 5:29 
GeneralRe: Issues with ReadFile function Pin
Aditi4841-Oct-05 5:06
Aditi4841-Oct-05 5:06 
QuestionPrinting centimeters Pin
Ivan Cachicatari29-Sep-05 2:53
Ivan Cachicatari29-Sep-05 2:53 
AnswerRe: Printing centimeters Pin
bugDanny29-Sep-05 3:08
bugDanny29-Sep-05 3:08 
AnswerRe: Printing centimeters Pin
vikas amin29-Sep-05 3:24
vikas amin29-Sep-05 3:24 
QuestionC++ loading XML Pin
SpuddyMcFuddy29-Sep-05 2:42
SpuddyMcFuddy29-Sep-05 2:42 
AnswerRe: C++ loading XML Pin
David Crow29-Sep-05 3:03
David Crow29-Sep-05 3:03 
AnswerRe: C++ loading XML Pin
Marc Soleda29-Sep-05 3:13
Marc Soleda29-Sep-05 3:13 
AnswerRe: C++ loading XML Pin
ThatsAlok29-Sep-05 18:07
ThatsAlok29-Sep-05 18:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.