Click here to Skip to main content
15,921,716 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7731-Jul-05 15:19
firebolt7731-Jul-05 15:19 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus31-Jul-05 15:58
protectorChristian Graus31-Jul-05 15:58 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7731-Jul-05 16:16
firebolt7731-Jul-05 16:16 
GeneralRe: troubles on using scroll bar in frame Pin
Christian Graus31-Jul-05 16:20
protectorChristian Graus31-Jul-05 16:20 
GeneralRe: troubles on using scroll bar in frame Pin
firebolt7731-Jul-05 16:38
firebolt7731-Jul-05 16:38 
Generala very looooong integer Pin
knapak28-Jul-05 15:34
knapak28-Jul-05 15:34 
GeneralRe: a very looooong integer Pin
Christian Graus28-Jul-05 15:40
protectorChristian Graus28-Jul-05 15:40 
GeneralRe: a very looooong integer Pin
Bob Stanneveld28-Jul-05 19:14
Bob Stanneveld28-Jul-05 19:14 
GeneralProblem with Multiple Views (SDI APplication). Pin
Faheem8228-Jul-05 11:47
Faheem8228-Jul-05 11:47 
QuestionWhat port is GetPeerName returning? Pin
lihin0028-Jul-05 9:21
lihin0028-Jul-05 9:21 
AnswerRe: What port is GetPeerName returning? Pin
Alexander M.,28-Jul-05 9:29
Alexander M.,28-Jul-05 9:29 
GeneralRe: What port is GetPeerName returning? Pin
lihin0028-Jul-05 9:36
lihin0028-Jul-05 9:36 
Questionsndvol32? Pin
billiam90428-Jul-05 8:57
billiam90428-Jul-05 8:57 
AnswerRe: sndvol32? Pin
Alexander M.,28-Jul-05 9:06
Alexander M.,28-Jul-05 9:06 
GeneralRe: sndvol32? Pin
billiam90428-Jul-05 9:10
billiam90428-Jul-05 9:10 
GeneralRe: sndvol32? Pin
Alexander M.,28-Jul-05 9:14
Alexander M.,28-Jul-05 9:14 
Generaltimeout for while loop Pin
trigger9128-Jul-05 8:53
susstrigger9128-Jul-05 8:53 
GeneralRe: timeout for while loop Pin
Alexander M.,28-Jul-05 8:57
Alexander M.,28-Jul-05 8:57 
GeneralRe: timeout for while loop Pin
trigger9128-Jul-05 9:33
susstrigger9128-Jul-05 9:33 
GeneralRe: timeout for while loop Pin
Alexander M.,29-Jul-05 4:26
Alexander M.,29-Jul-05 4:26 
GeneralRe: timeout for while loop Pin
Peter Weyzen28-Jul-05 9:46
Peter Weyzen28-Jul-05 9:46 
GeneralRe: timeout for while loop Pin
Alexander M.,29-Jul-05 4:25
Alexander M.,29-Jul-05 4:25 
GeneralRe: timeout for while loop Pin
David Crow29-Jul-05 6:03
David Crow29-Jul-05 6:03 
GeneralRe: timeout for while loop Pin
nm_11429-Jul-05 14:16
nm_11429-Jul-05 14:16 
Generalread from comport problem Pin
quarry_0628-Jul-05 8:42
quarry_0628-Jul-05 8:42 
Hi I am using the library I found here:
http://www.codeproject.com/system/serial.asp
in my program. However, I run into the following problem when I am reading from a comport. (example listener).

I took the code, and created a little function
int readme(CSerial &serial)<br />
{<br />
	LONG    lLastError = ERROR_SUCCESS;<br />
	lLastError = serial.SetMask(CSerial::EEventBreak |<br />
								CSerial::EEventCTS   |<br />
								CSerial::EEventDSR   |<br />
								CSerial::EEventError |<br />
								CSerial::EEventRing  |<br />
								CSerial::EEventRLSD  |<br />
								CSerial::EEventRecv);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port event mask"));<br />
<br />
	// Use 'non-blocking' reads, because we don't know how many bytes<br />
	// will be received. This is normally the most convenient mode<br />
	// (and also the default mode for reading data).<br />
    lLastError = serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port read timeout."));<br />
	<br />
	bool fContinue = true;<br />
	do<br />
	{<br />
		// Wait for an event<br />
		lLastError = serial.WaitEvent();<br />
		if (lLastError != ERROR_SUCCESS)<br />
			return ::ShowError(serial.GetLastError(), _T("Unable to wait for a COM-port event."));<br />
<br />
		// Save event<br />
		const CSerial::EEvent eEvent = serial.GetEventType();<br />
<br />
		// Handle break event<br />
		if (eEvent & CSerial::EEventBreak)<br />
		{<br />
			printf("\n### BREAK received ###\n");<br />
		}<br />
<br />
		// Handle CTS event<br />
		if (eEvent & CSerial::EEventCTS)<br />
		{<br />
			printf("\n### Clear to send %s ###\n", serial.GetCTS()?"on":"off");<br />
		}<br />
<br />
		// Handle DSR event<br />
		if (eEvent & CSerial::EEventDSR)<br />
		{<br />
			printf("\n### Data set ready %s ###\n", serial.GetDSR()?"on":"off");<br />
		}<br />
<br />
		// Handle error event<br />
		if (eEvent & CSerial::EEventError)<br />
		{<br />
			printf("\n### ERROR: ");<br />
			switch (serial.GetError())<br />
			{<br />
			case CSerial::EErrorBreak:		printf("Break condition");			break;<br />
			case CSerial::EErrorFrame:		printf("Framing error");			break;<br />
			case CSerial::EErrorIOE:		printf("IO device error");			break;<br />
			case CSerial::EErrorMode:		printf("Unsupported mode");			break;<br />
			case CSerial::EErrorOverrun:	printf("Buffer overrun");			break;<br />
			case CSerial::EErrorRxOver:		printf("Input buffer overflow");	break;<br />
			case CSerial::EErrorParity:		printf("Input parity error");		break;<br />
			case CSerial::EErrorTxFull:		printf("Output buffer full");		break;<br />
			default:						printf("Unknown");					break;<br />
			}<br />
			printf(" ###\n");<br />
		}<br />
<br />
		// Handle ring event<br />
		if (eEvent & CSerial::EEventRing)<br />
		{<br />
			printf("\n### RING ###\n");<br />
		}<br />
<br />
		// Handle RLSD/CD event<br />
		if (eEvent & CSerial::EEventRLSD)<br />
		{<br />
			printf("\n### RLSD/CD %s ###\n", serial.GetRLSD()?"on":"off");<br />
		}<br />
<br />
		// Handle data receive event<br />
		if (eEvent & CSerial::EEventRecv)<br />
		{<br />
			// Read data, until there is nothing left<br />
			DWORD dwBytesRead = 0;<br />
			char szBuffer[101];<br />
			do<br />
			{<br />
				// Read data from the COM-port<br />
				lLastError = serial.Read(szBuffer,sizeof(szBuffer)-1,&dwBytesRead);<br />
				if (lLastError != ERROR_SUCCESS)<br />
					return ::ShowError(serial.GetLastError(), _T("Unable to read from COM-port."));<br />
<br />
				if (dwBytesRead > 0)<br />
				{<br />
					// Finalize the data, so it is a valid string<br />
					szBuffer[dwBytesRead] = '\0';<br />
<br />
					// Display the data<br />
					printf("%s|", szBuffer);<br />
					<br />
					// Check if EOF (CTRL+'[') has been specified<br />
					if (strchr(szBuffer,EOF_Char))<br />
						fContinue = false;<br />
				}<br />
			}<br />
		    while (dwBytesRead == sizeof(szBuffer)-1);<br />
		}<br />
	}<br />
	while (fContinue);<br />
	serial.Close();<br />
	lLastError = serial.Open(_T("COM1"),0,0,false);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
    // Setup the serial port (9600,8N1, which is the default setting)<br />
    lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
	return 0;<br />
}


then, what I do is following:

int __cdecl _tmain (int /*argc*/, char** /*argv*/)<br />
{<br />
    CSerial serial;<br />
	LONG    lLastError = ERROR_SUCCESS;<br />
<br />
    // Attempt to open the serial port (COM1)<br />
    lLastError = serial.Open(_T("COM1"),0,0,false);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port"));<br />
<br />
    // Setup the serial port (9600,8N1, which is the default setting)<br />
    lLastError = serial.Setup(CSerial::EBaud38400,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);<br />
	if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting"));<br />
<br />
    // Register only for the receive event<br />
    <br />
<br />
    // Keep reading data, until an EOF (CTRL-Z) has been received<br />
<br />
	//lLastError = serial.Write("\n");<br />
	//Sleep(1000);<br />
lLastError = serial.Write("\nwhoami\n");<br />
int r;<br />
//r = readme(serial);<br />
if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
lLastError = serial.Write("\nwhoami\n");<br />
		 <br />
r = readme(serial);<br />
if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
<br />
		//r = readme(serial);<br />
<br />
		//lLastError = serial.Write("\nwhoami\n");<br />
if (lLastError != ERROR_SUCCESS)<br />
		return ::ShowError(serial.GetLastError(), _T("Error sending a return"));<br />
<br />
    // Close the port again<br />
    serial.Close();<br />
    return 0;<br />
}


ok when the first is commented out, I see the results of both functions. but when the first readme is there, it only reads up to that point, and goes no further.

why is that so? I would like to read information step by step, as it needs to processed.

thanks alot for any help

quarry

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.