<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Programm läuft auf einem Rechner nicht]]></title><description><![CDATA[<p>Hallo</p>
<p>ich habe ein sehr unschönes Problem. Ich habe ein Programm geschrieben, welches auf Daten auf der seriellen Schnittstelle wartet und diese anzeigt (Eigentlich keine große Sache).</p>
<p>Um das Programm zu testen, habe ich zwei Rechner, zwischen denen eine serielle Verbindung besteht.</p>
<p>Rechner 1: IBM Thinkpad mit Docking Station<br />
Rechner 2: Desktop Rechner 800MHz</p>
<p>Auf dem Rechner 1 wird die Software entwickelt.</p>
<p>Jetzt zu meinem Problem.</p>
<p>Wenn Rechner 2 die Daten empfängt und Rechner 1 sendet läuft das Programm wie gewollt.<br />
Wenn, allerdings Rechner 1 die Daten empfangen soll geht es schief.</p>
<p>Bsp.</p>
<p>Ich sende vier Zeichen: 2,2,1,1</p>
<p>Es kommt an: 2,2</p>
<p>ich sende nochmals vier Zeichen 3,3,3,3</p>
<p>Es kommt an: 1,1 (!)</p>
<p>Ich poste mal meinen Code:</p>
<p>Lasse ich die WaitCommEvent Sache weg, läuft das Programm, allerdings habe ich wegen des Pollings den Befehl überhaupt erst eingebaut.</p>
<p>Ich hoffe ihr könnt mir Helfen</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;assert.h&gt;
#include &lt;stdio.h&gt;

void main( )
	{
	COMMTIMEOUTS timeouts_alt;
	DCB dcb_alt;
	DCB dcb;
	HANDLE hCom;
	BOOL fSuccess;
	DWORD dwEvtMask;
	DWORD dwRead = 0;
	char chRead;

	hCom = CreateFile( &quot;COM1&quot;,
		GENERIC_READ,// | GENERIC_WRITE,
		0,    // exclusive access 
		0, // default security attributes 
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,//FILE_FLAG_OVERLAPPED,
		NULL);

	//if (hCom == INVALID_HANDLE_VALUE) 
	//	{
	//	//Handle the error. 
	//		printf(&quot;CreateFile failed with error %d.\n&quot;, GetLastError());
	//	return;
	//	}

	ZeroMemory (&amp;dcb, sizeof(dcb)); // ..und schön löschen (wichtig!)
	dcb.DCBlength = sizeof(DCB);

	GetCommState (hCom, &amp;dcb);
	dcb_alt = dcb;
	dcb.fBinary = TRUE; // muss immer &quot;TRUE&quot; sein!
	dcb.fParity = TRUE;
	dcb.fOutxCtsFlow = FALSE;
	dcb.fOutxDsrFlow = FALSE;
	dcb.fDtrControl = DTR_CONTROL_ENABLE;
	dcb.fDsrSensitivity = FALSE;
	dcb.fTXContinueOnXoff = TRUE;
	dcb.fOutX = FALSE;
	dcb.fInX = FALSE;
	dcb.fErrorChar = FALSE;
	dcb.fNull = FALSE;
	dcb.fRtsControl = RTS_CONTROL_ENABLE;
	dcb.fAbortOnError = FALSE;
	dcb.wReserved = 0; // muss immer &quot;0&quot; sein!

	dcb.BaudRate = 9600;
	dcb.ByteSize = 8;
	dcb.Parity   = EVENPARITY;
	dcb.StopBits = ONESTOPBIT;

	dcb.fParity = (dcb.Parity != NOPARITY);

	SetCommState(hCom, &amp;dcb);

	GetCommTimeouts(hCom, &amp;timeouts_alt);
	COMMTIMEOUTS timeouts;
	timeouts.ReadIntervalTimeout = MAXDWORD ;
	timeouts.ReadTotalTimeoutMultiplier = MAXDWORD ;
	timeouts.ReadTotalTimeoutConstant = 3000; // Timeout ist 3000ms 
	timeouts.WriteTotalTimeoutMultiplier = 1000;
	timeouts.WriteTotalTimeoutConstant = 1000;

	SetCommTimeouts(hCom, &amp;timeouts);

	fSuccess = SetCommMask(hCom,EV_RXCHAR);

	//if (!fSuccess) 
	//	{
	//	//Handle the error. 
	//		printf(&quot;SetCommMask failed with error %d.\n&quot;, GetLastError());
	//	return;
	//	}

	int count=0;
	int Zz=0;
	do{
		if (WaitCommEvent(hCom, &amp;dwEvtMask, NULL)) 
			{
			if (dwEvtMask &amp; EV_RXCHAR)
				{
				Zz++;
				//std::cout &lt;&lt; &quot;Zeichen\n&quot;;
				ReadFile(hCom, &amp;chRead, 1, &amp;dwRead, NULL);
				std::cout &lt;&lt; int(unsigned char(chRead)) &lt;&lt; &quot; &quot; &lt;&lt; chRead &lt;&lt; std::endl;

				if( unsigned char(chRead) == 0xff)
					{
					count++;
					}
				else
					{
					count=0;
					}
				if(count &gt;= 4)
					{
					count=0;

					std::cout &lt;&lt; Zz &lt;&lt; &quot; &quot;;
					Zz=0;
					}

				chRead = 0x00;
				dwRead = 0;
				}
			}
		//else
		//	{
		//	DWORD dwRet = GetLastError();
		//	if( ERROR_IO_PENDING == dwRet)
		//		{
		//		printf(&quot;I/O is pending...\n&quot;);

		//		//To do.
		//		}
		//	else 
		//		printf(&quot;Wait failed with error %d.\n&quot;, GetLastError());
		//	}
		}while(1 == 1);
	system(&quot;PAUSE&quot;);
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/145455/programm-läuft-auf-einem-rechner-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 05:24:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/145455.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Apr 2006 06:18:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Programm läuft auf einem Rechner nicht on Fri, 28 Apr 2006 06:18:02 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>ich habe ein sehr unschönes Problem. Ich habe ein Programm geschrieben, welches auf Daten auf der seriellen Schnittstelle wartet und diese anzeigt (Eigentlich keine große Sache).</p>
<p>Um das Programm zu testen, habe ich zwei Rechner, zwischen denen eine serielle Verbindung besteht.</p>
<p>Rechner 1: IBM Thinkpad mit Docking Station<br />
Rechner 2: Desktop Rechner 800MHz</p>
<p>Auf dem Rechner 1 wird die Software entwickelt.</p>
<p>Jetzt zu meinem Problem.</p>
<p>Wenn Rechner 2 die Daten empfängt und Rechner 1 sendet läuft das Programm wie gewollt.<br />
Wenn, allerdings Rechner 1 die Daten empfangen soll geht es schief.</p>
<p>Bsp.</p>
<p>Ich sende vier Zeichen: 2,2,1,1</p>
<p>Es kommt an: 2,2</p>
<p>ich sende nochmals vier Zeichen 3,3,3,3</p>
<p>Es kommt an: 1,1 (!)</p>
<p>Ich poste mal meinen Code:</p>
<p>Lasse ich die WaitCommEvent Sache weg, läuft das Programm, allerdings habe ich wegen des Pollings den Befehl überhaupt erst eingebaut.</p>
<p>Ich hoffe ihr könnt mir Helfen</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;assert.h&gt;
#include &lt;stdio.h&gt;

void main( )
	{
	COMMTIMEOUTS timeouts_alt;
	DCB dcb_alt;
	DCB dcb;
	HANDLE hCom;
	BOOL fSuccess;
	DWORD dwEvtMask;
	DWORD dwRead = 0;
	char chRead;

	hCom = CreateFile( &quot;COM1&quot;,
		GENERIC_READ,// | GENERIC_WRITE,
		0,    // exclusive access 
		0, // default security attributes 
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,//FILE_FLAG_OVERLAPPED,
		NULL);

	//if (hCom == INVALID_HANDLE_VALUE) 
	//	{
	//	//Handle the error. 
	//		printf(&quot;CreateFile failed with error %d.\n&quot;, GetLastError());
	//	return;
	//	}

	ZeroMemory (&amp;dcb, sizeof(dcb)); // ..und schön löschen (wichtig!)
	dcb.DCBlength = sizeof(DCB);

	GetCommState (hCom, &amp;dcb);
	dcb_alt = dcb;
	dcb.fBinary = TRUE; // muss immer &quot;TRUE&quot; sein!
	dcb.fParity = TRUE;
	dcb.fOutxCtsFlow = FALSE;
	dcb.fOutxDsrFlow = FALSE;
	dcb.fDtrControl = DTR_CONTROL_ENABLE;
	dcb.fDsrSensitivity = FALSE;
	dcb.fTXContinueOnXoff = TRUE;
	dcb.fOutX = FALSE;
	dcb.fInX = FALSE;
	dcb.fErrorChar = FALSE;
	dcb.fNull = FALSE;
	dcb.fRtsControl = RTS_CONTROL_ENABLE;
	dcb.fAbortOnError = FALSE;
	dcb.wReserved = 0; // muss immer &quot;0&quot; sein!

	dcb.BaudRate = 9600;
	dcb.ByteSize = 8;
	dcb.Parity   = EVENPARITY;
	dcb.StopBits = ONESTOPBIT;

	dcb.fParity = (dcb.Parity != NOPARITY);

	SetCommState(hCom, &amp;dcb);

	GetCommTimeouts(hCom, &amp;timeouts_alt);
	COMMTIMEOUTS timeouts;
	timeouts.ReadIntervalTimeout = MAXDWORD ;
	timeouts.ReadTotalTimeoutMultiplier = MAXDWORD ;
	timeouts.ReadTotalTimeoutConstant = 3000; // Timeout ist 3000ms 
	timeouts.WriteTotalTimeoutMultiplier = 1000;
	timeouts.WriteTotalTimeoutConstant = 1000;

	SetCommTimeouts(hCom, &amp;timeouts);

	fSuccess = SetCommMask(hCom,EV_RXCHAR);

	//if (!fSuccess) 
	//	{
	//	//Handle the error. 
	//		printf(&quot;SetCommMask failed with error %d.\n&quot;, GetLastError());
	//	return;
	//	}

	int count=0;
	int Zz=0;
	do{
		if (WaitCommEvent(hCom, &amp;dwEvtMask, NULL)) 
			{
			if (dwEvtMask &amp; EV_RXCHAR)
				{
				Zz++;
				//std::cout &lt;&lt; &quot;Zeichen\n&quot;;
				ReadFile(hCom, &amp;chRead, 1, &amp;dwRead, NULL);
				std::cout &lt;&lt; int(unsigned char(chRead)) &lt;&lt; &quot; &quot; &lt;&lt; chRead &lt;&lt; std::endl;

				if( unsigned char(chRead) == 0xff)
					{
					count++;
					}
				else
					{
					count=0;
					}
				if(count &gt;= 4)
					{
					count=0;

					std::cout &lt;&lt; Zz &lt;&lt; &quot; &quot;;
					Zz=0;
					}

				chRead = 0x00;
				dwRead = 0;
				}
			}
		//else
		//	{
		//	DWORD dwRet = GetLastError();
		//	if( ERROR_IO_PENDING == dwRet)
		//		{
		//		printf(&quot;I/O is pending...\n&quot;);

		//		//To do.
		//		}
		//	else 
		//		printf(&quot;Wait failed with error %d.\n&quot;, GetLastError());
		//	}
		}while(1 == 1);
	system(&quot;PAUSE&quot;);
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1046840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1046840</guid><dc:creator><![CDATA[Dippl Insch]]></dc:creator><pubDate>Fri, 28 Apr 2006 06:18:02 GMT</pubDate></item><item><title><![CDATA[Reply to Programm läuft auf einem Rechner nicht on Fri, 28 Apr 2006 06:33:44 GMT]]></title><description><![CDATA[<p>So wie immer Rate ich bei der seriellen Kommunikation dazu dies nicht selber zu machen, da es nicht so trivial ist, wie es sich anhört. Sondern verwende eine gute, getestete Klasse die schon alles kann:<br />
<a href="http://www.codeproject.com/system/serial.asp" rel="nofollow">http://www.codeproject.com/system/serial.asp</a></p>
<p>PS: Dein Fehler ist natürlich, dass Du nur ein Zeichen liest! Du musst aber so viel lesen, bis der gesamte Puffer leer ist. Es kommt ja nicht für <em>jedes</em> Zeichen ein Event, sondern nur wenn Zeichen eingetroffen sind (also unabhängig der Anzahl).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1046845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1046845</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 28 Apr 2006 06:33:44 GMT</pubDate></item><item><title><![CDATA[Reply to Programm läuft auf einem Rechner nicht on Fri, 28 Apr 2006 06:39:28 GMT]]></title><description><![CDATA[<p>Ich verwende eine Klasse von</p>
<p><a href="http://www.winapi.net" rel="nofollow">www.winapi.net</a></p>
<p><a href="http://www.winapi.net/index.php?inhalt=t3" rel="nofollow">http://www.winapi.net/index.php?inhalt=t3</a></p>
<p>Ich habe nur die wesentlichen Codeteile herausgepickt um den Fehler besser suchen zu können.</p>
<p>Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1046847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1046847</guid><dc:creator><![CDATA[Dippl Insch]]></dc:creator><pubDate>Fri, 28 Apr 2006 06:39:28 GMT</pubDate></item></channel></rss>