<?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[Bytes senden via RS232]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich programmiere gerade auf einem PDA mit MFC eine RS232 Kommunikation.<br />
Das empfangen der Daten klappt, jedoch kann ich nicht gleichzeitig Daten senden (nur ein Byte). Woran kann das liegen, sind Einstellungen an der Schnittstelle falsch, so das nicht gleichzeitig gesendet und empfangen werden kann?</p>
<p>hier mal die wichtigsten Codesegmente:</p>
<pre><code>void mDaten::startSeq()
{
char sentchar[16];
sprintf(sentchar,&quot;%s&quot;,&quot;A&quot;);	
fprintf(fileHandle,&quot;Daten geschrieben: %i\n&quot;,comPort.SendData(sentchar,1));
fprintf(fileHandle,&quot;Datawaiting: %i\n&quot;,comPort.SendDataWaiting());
	return;
}

int CSerial::SendData (const char *buffer, int iBytesToWrite)
{
   if (INVALID_HANDLE_VALUE == hComm)
	{
		SetLastError(ERROR_INVALID_HANDLE);
      return (0);
	}

   DWORD dwBytesWritten = 0;
   WriteFile(hComm, buffer, iBytesToWrite, &amp;dwBytesWritten, NULL);

   return ((int) dwBytesWritten);
}

bool CSerial::Open (int nComPortNr, int nBaud, int nBits, int nParity, int nStopp)
{
   if (INVALID_HANDLE_VALUE != hComm)
	{
		return (true);
	}

   TCHAR szPort[16];

   wsprintf (szPort, TEXT(&quot;\\\\.\\COM%d&quot;), nComPortNr);

   hComm = CreateFile (_T(&quot;COM1:&quot;),
						  GENERIC_READ | GENERIC_WRITE,
                    0,
                    NULL,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);

   if (hComm == INVALID_HANDLE_VALUE)
   {
	   return (false);
   }

   if (!GetCommTimeouts(hComm, &amp;timeouts_alt))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
		printf(&quot;Fehler 3 %c&quot;,szPort);
      return (false);
   }

   COMMTIMEOUTS timeouts;
   timeouts.ReadIntervalTimeout = MAXDWORD ;
   timeouts.ReadTotalTimeoutMultiplier = MAXDWORD ;
   timeouts.ReadTotalTimeoutConstant = 3000; // Timeout ist 3000ms 
   timeouts.WriteTotalTimeoutMultiplier = 1000;
   timeouts.WriteTotalTimeoutConstant = 1000;

   if (!SetCommTimeouts(hComm, &amp;timeouts))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
      return (false);
   }

   DCB dcb;
   ZeroMemory (&amp;dcb, sizeof(dcb));
	dcb.DCBlength = sizeof(DCB);

   if (!GetCommState (hComm, &amp;dcb))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
      return (false);
   }

	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 = nBaud;
	dcb.ByteSize = (BYTE)nBits;
	dcb.Parity   = (BYTE)nParity;
	dcb.StopBits = (BYTE)nStopp;   

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

   if (!SetCommState(hComm, &amp;dcb))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
		printf(&quot;Fehler 6 %c&quot;,szPort);
      return (false);
   }

   m_bOpened = true;
   return(true);
}
</code></pre>
<p>Danke<br />
TBone</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/180448/bytes-senden-via-rs232</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 06:34:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/180448.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 May 2007 21:17:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bytes senden via RS232 on Wed, 02 May 2007 21:17:48 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich programmiere gerade auf einem PDA mit MFC eine RS232 Kommunikation.<br />
Das empfangen der Daten klappt, jedoch kann ich nicht gleichzeitig Daten senden (nur ein Byte). Woran kann das liegen, sind Einstellungen an der Schnittstelle falsch, so das nicht gleichzeitig gesendet und empfangen werden kann?</p>
<p>hier mal die wichtigsten Codesegmente:</p>
<pre><code>void mDaten::startSeq()
{
char sentchar[16];
sprintf(sentchar,&quot;%s&quot;,&quot;A&quot;);	
fprintf(fileHandle,&quot;Daten geschrieben: %i\n&quot;,comPort.SendData(sentchar,1));
fprintf(fileHandle,&quot;Datawaiting: %i\n&quot;,comPort.SendDataWaiting());
	return;
}

int CSerial::SendData (const char *buffer, int iBytesToWrite)
{
   if (INVALID_HANDLE_VALUE == hComm)
	{
		SetLastError(ERROR_INVALID_HANDLE);
      return (0);
	}

   DWORD dwBytesWritten = 0;
   WriteFile(hComm, buffer, iBytesToWrite, &amp;dwBytesWritten, NULL);

   return ((int) dwBytesWritten);
}

bool CSerial::Open (int nComPortNr, int nBaud, int nBits, int nParity, int nStopp)
{
   if (INVALID_HANDLE_VALUE != hComm)
	{
		return (true);
	}

   TCHAR szPort[16];

   wsprintf (szPort, TEXT(&quot;\\\\.\\COM%d&quot;), nComPortNr);

   hComm = CreateFile (_T(&quot;COM1:&quot;),
						  GENERIC_READ | GENERIC_WRITE,
                    0,
                    NULL,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL);

   if (hComm == INVALID_HANDLE_VALUE)
   {
	   return (false);
   }

   if (!GetCommTimeouts(hComm, &amp;timeouts_alt))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
		printf(&quot;Fehler 3 %c&quot;,szPort);
      return (false);
   }

   COMMTIMEOUTS timeouts;
   timeouts.ReadIntervalTimeout = MAXDWORD ;
   timeouts.ReadTotalTimeoutMultiplier = MAXDWORD ;
   timeouts.ReadTotalTimeoutConstant = 3000; // Timeout ist 3000ms 
   timeouts.WriteTotalTimeoutMultiplier = 1000;
   timeouts.WriteTotalTimeoutConstant = 1000;

   if (!SetCommTimeouts(hComm, &amp;timeouts))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
      return (false);
   }

   DCB dcb;
   ZeroMemory (&amp;dcb, sizeof(dcb));
	dcb.DCBlength = sizeof(DCB);

   if (!GetCommState (hComm, &amp;dcb))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
      return (false);
   }

	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 = nBaud;
	dcb.ByteSize = (BYTE)nBits;
	dcb.Parity   = (BYTE)nParity;
	dcb.StopBits = (BYTE)nStopp;   

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

   if (!SetCommState(hComm, &amp;dcb))
   {
		DWORD dwError = GetLastError();
		Close ();
		SetLastError(dwError);
		printf(&quot;Fehler 6 %c&quot;,szPort);
      return (false);
   }

   m_bOpened = true;
   return(true);
}
</code></pre>
<p>Danke<br />
TBone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277850</guid><dc:creator><![CDATA[TBone]]></dc:creator><pubDate>Wed, 02 May 2007 21:17:48 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Thu, 03 May 2007 01:18:24 GMT]]></title><description><![CDATA[<p>Wie klappt es denn nicht?<br />
Und ... vielleicht wäre es hilfreich die Timeout-Werte explizit zu setzen wenn du schon mit Hardware Handshake arbeitest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277901</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Thu, 03 May 2007 01:18:24 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Thu, 03 May 2007 05:46:40 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>Wie klappt es denn nicht?<br />
Und ... vielleicht wäre es hilfreich die Timeout-Werte explizit zu setzen wenn du schon mit Hardware Handshake arbeitest.</p>
</blockquote>
<p>Hallo Hustbear,</p>
<p>es klappt folgendes nicht! Der PDA bekommt nach dem Starten-Button die Daten von einem MSP, das lesen klappt! Vor dem Starten soll der PDA jedoch dem MSP noch ein Byte schicken, so dass der MSP weiß jetzt soll er die Daten schicken! Und genau dieses Senden des einen Bytes funktioniert nicht. Ich frag ich auch ab, ob eine Byte geschrieben hat und ob der Buffer leer ist, und darauf kommt die Antwort ein Byte geschrieben und Buffer leer, aber es kommt definitiv nichts am MSP an.</p>
<pre><code>void mDaten::startSeq()
{
char sentchar[16];
sprintf(sentchar,&quot;%s&quot;,&quot;A&quot;);   
fprintf(fileHandle,&quot;Daten geschrieben: %i\n&quot;,comPort.SendData(sentchar,1));
fprintf(fileHandle,&quot;Datawaiting: %i\n&quot;,comPort.SendDataWaiting());
    return;
}
</code></pre>
<p>Aber die Sache mit dem Hardwarehandshake klingt schonmal sehr gut, eigentlich könnte ich doch auch darauf verzichten, wie kann ich das ausschalten?</p>
<p>Viele Grüße<br />
TBone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277917</guid><dc:creator><![CDATA[TBone]]></dc:creator><pubDate>Thu, 03 May 2007 05:46:40 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Thu, 03 May 2007 20:13:13 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe jetzt DTR_CONTROL_DISABLE und RTS_CONTROL_DISABLE gesetz aber die Daten vom PDA kommen immer noch nirgens an, der PDA sendet nicht!</p>
<p>Woran kann es noch liegen?</p>
<p>Viele Grüße<br />
TBone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1278392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1278392</guid><dc:creator><![CDATA[TBone]]></dc:creator><pubDate>Thu, 03 May 2007 20:13:13 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Thu, 03 May 2007 20:30:09 GMT]]></title><description><![CDATA[<p>Könnte vielleicht <strong>XON/XOFF</strong> noch ein Problem sein?</p>
<p>Gruss, Gio</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1278406</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1278406</guid><dc:creator><![CDATA[Gio]]></dc:creator><pubDate>Thu, 03 May 2007 20:30:09 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Thu, 03 May 2007 21:59:44 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>hab ich auch schon ausprobiert, ändertn leider nichts.</p>
<p>Viele Grüße<br />
TBone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1278450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1278450</guid><dc:creator><![CDATA[TBone]]></dc:creator><pubDate>Thu, 03 May 2007 21:59:44 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Fri, 04 May 2007 07:54:36 GMT]]></title><description><![CDATA[<p>Naja, das habe ich wohl etwas falsch formuliert... wenn der PDA das unterstützt ist Hardware Handshake schon gut, bloss Timeouts gehören IMHO eingestellt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1278553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1278553</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 04 May 2007 07:54:36 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Fri, 04 May 2007 15:06:17 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>wie gesagt ich habe jetzt die Flusskontolle ausgeschalten und der PDA sendet immer noch nicht!<br />
Wenn ich im Programm abfrage ob Daten in den Ausgabebuffer geschrieben wurden, werden diese mit der korrekten Zahl bestätigt. Wenn ich dann abfrage ob noch Daten im Buffer stehen ist dieser leer.<br />
Wenn ich jetzt die Timeouts einstelle, kann es das Problem beim Senden beheben?</p>
<p>Viele Grüße<br />
TBone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1278808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1278808</guid><dc:creator><![CDATA[TBone]]></dc:creator><pubDate>Fri, 04 May 2007 15:06:17 GMT</pubDate></item><item><title><![CDATA[Reply to Bytes senden via RS232 on Sat, 05 May 2007 18:40:45 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>kann es sein das so ein PDA gar keine Daten über die RS232 senden kann. Ich bin momentan am Verzweifeln und kurz davor alles als ein Elektronikproblem zu deklarieren.</p>
<p>Viele Grüße<br />
TBone</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1279431</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1279431</guid><dc:creator><![CDATA[TBone]]></dc:creator><pubDate>Sat, 05 May 2007 18:40:45 GMT</pubDate></item></channel></rss>