<?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[readfile in Hex Varible speichern]]></title><description><![CDATA[<p>hi,<br />
nach Tage langen googleln, und totaler Verzweiflung probiere ich mal hier mein Glück,<br />
der PC sendet ein Singal &quot;reset&quot; zu meinem Com1 Gerät, daraufhin wird über reafile Daten gelesen.<br />
Das einzige was ich will, ist mit der Readfilefunktion binäre oder hex Zahlen in eine Variable zu speichern.<br />
Weil wenn ich eine varible bekomme z.b. 10011001, wird das erste bit als Minus angesehen, dann bekomme ich total verwirte zahlen, ich wäre schon happy, wenn ich nur positive Dezimal Zahlen bekommen würde.</p>
<p>-------------------------------schnipp zum verbinden -----------</p>
<p>//DCB dcb,dcb_neu; &lt;--- das geändert.. auf global <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
COMMTIMEOUTS cto,cto_neu;</p>
<p>//und das h_com geändert auf global <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
h_com=CreateFile(&quot;\\\.\\COM1&quot;,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);</p>
<p>GetCommState(h_com, &amp;dcb);<br />
GetCommState(h_com, &amp;dcb_neu);<br />
GetCommTimeouts(h_com,&amp;cto);<br />
GetCommTimeouts(h_com,&amp;cto_neu);</p>
<p>dcb_neu.DCBlength = sizeof(dcb_neu);<br />
dcb_neu.BaudRate = 9600; // Baudrate<br />
dcb_neu.fParity = FALSE;<br />
dcb_neu.fBinary = TRUE;<br />
dcb_neu.Parity = NOPARITY;// Kein Paritybit<br />
dcb_neu.StopBits = ONESTOPBIT;<br />
dcb_neu.fOutxCtsFlow = FALSE;<br />
dcb_neu.fOutxDsrFlow = FALSE;<br />
dcb_neu.fDtrControl = DTR_CONTROL_ENABLE;<br />
dcb_neu.fDsrSensitivity = FALSE;<br />
dcb_neu.fAbortOnError = FALSE;<br />
dcb_neu.ByteSize = 8; // 8 Datenbits</p>
<p>cto.ReadIntervalTimeout = MAXDWORD; // 0 ms Read-Tomeout<br />
cto.ReadTotalTimeoutMultiplier = 0;<br />
cto.ReadTotalTimeoutConstant = 0;<br />
cto.WriteTotalTimeoutMultiplier= 1; // 1*2 ms Write Timeout<br />
cto.WriteTotalTimeoutConstant = 2;</p>
<p>SetCommState(h_com, &amp;dcb_neu);<br />
SetCommTimeouts(h_com,&amp;cto_neu);<br />
GetDlgItem(IDC_verbinden3)-&gt;EnableWindow(FALSE);<br />
GetDlgItem(IDC_trennen3)-&gt;EnableWindow(TRUE);</p>
<p>-----------------startfunktion und lese funtkion -----------</p>
<p>UpdateData(TRUE);<br />
log += &quot;löse Reset zur Karte aus...&quot;;<br />
UpdateData(FALSE);<br />
dcb.fRtsControl=RTS_CONTROL_ENABLE; // RESET<br />
if (!SetCommState(h_com, &amp;dcb))<br />
return ;<br />
dcb.fRtsControl=RTS_CONTROL_DISABLE; //RESET OFF<br />
// Wait for 50 ms<br />
Sleep(50);<br />
if (!SetCommState(h_com, &amp;dcb))<br />
return ;</p>
<p>CString str;<br />
DWORD dwCount;<br />
char cData[2];<br />
int byte;<br />
for (byte = 0; byte &lt;15; byte++)<br />
{</p>
<p>ReadFile(h_com,cData,2,&amp;dwCount,0); // das Problem !!!<br />
log += dezhex(cData[0]); // dezhex() wandelt nur die Zahlen<br />
log += dezhex(cData[1]); // in hex und steckt sie dann in log<br />
// ABER das Vorzeichen macht Probleme<br />
}<br />
log += &quot;\r\n&quot;; // für eine Leerzeile<br />
------------------schnipp schnipp ende ------------------------</p>
<p>ICh wäre sehr sehr Dankebar für eine der 3 Lösungen, cData ist hex oder binär oder eine Dezimalzahl in ohne vorzeichen.<br />
Ich habe Visual Studio 2003 net. Progge unter MFC in c++<br />
Ich würde sogere an meinen Projekt weitermachen. :-)))</p>
<p>mfg Tomycat</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/72994/readfile-in-hex-varible-speichern</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 12:58:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/72994.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 May 2004 17:03:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to readfile in Hex Varible speichern on Tue, 04 May 2004 17:03:45 GMT]]></title><description><![CDATA[<p>hi,<br />
nach Tage langen googleln, und totaler Verzweiflung probiere ich mal hier mein Glück,<br />
der PC sendet ein Singal &quot;reset&quot; zu meinem Com1 Gerät, daraufhin wird über reafile Daten gelesen.<br />
Das einzige was ich will, ist mit der Readfilefunktion binäre oder hex Zahlen in eine Variable zu speichern.<br />
Weil wenn ich eine varible bekomme z.b. 10011001, wird das erste bit als Minus angesehen, dann bekomme ich total verwirte zahlen, ich wäre schon happy, wenn ich nur positive Dezimal Zahlen bekommen würde.</p>
<p>-------------------------------schnipp zum verbinden -----------</p>
<p>//DCB dcb,dcb_neu; &lt;--- das geändert.. auf global <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
COMMTIMEOUTS cto,cto_neu;</p>
<p>//und das h_com geändert auf global <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
h_com=CreateFile(&quot;\\\.\\COM1&quot;,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);</p>
<p>GetCommState(h_com, &amp;dcb);<br />
GetCommState(h_com, &amp;dcb_neu);<br />
GetCommTimeouts(h_com,&amp;cto);<br />
GetCommTimeouts(h_com,&amp;cto_neu);</p>
<p>dcb_neu.DCBlength = sizeof(dcb_neu);<br />
dcb_neu.BaudRate = 9600; // Baudrate<br />
dcb_neu.fParity = FALSE;<br />
dcb_neu.fBinary = TRUE;<br />
dcb_neu.Parity = NOPARITY;// Kein Paritybit<br />
dcb_neu.StopBits = ONESTOPBIT;<br />
dcb_neu.fOutxCtsFlow = FALSE;<br />
dcb_neu.fOutxDsrFlow = FALSE;<br />
dcb_neu.fDtrControl = DTR_CONTROL_ENABLE;<br />
dcb_neu.fDsrSensitivity = FALSE;<br />
dcb_neu.fAbortOnError = FALSE;<br />
dcb_neu.ByteSize = 8; // 8 Datenbits</p>
<p>cto.ReadIntervalTimeout = MAXDWORD; // 0 ms Read-Tomeout<br />
cto.ReadTotalTimeoutMultiplier = 0;<br />
cto.ReadTotalTimeoutConstant = 0;<br />
cto.WriteTotalTimeoutMultiplier= 1; // 1*2 ms Write Timeout<br />
cto.WriteTotalTimeoutConstant = 2;</p>
<p>SetCommState(h_com, &amp;dcb_neu);<br />
SetCommTimeouts(h_com,&amp;cto_neu);<br />
GetDlgItem(IDC_verbinden3)-&gt;EnableWindow(FALSE);<br />
GetDlgItem(IDC_trennen3)-&gt;EnableWindow(TRUE);</p>
<p>-----------------startfunktion und lese funtkion -----------</p>
<p>UpdateData(TRUE);<br />
log += &quot;löse Reset zur Karte aus...&quot;;<br />
UpdateData(FALSE);<br />
dcb.fRtsControl=RTS_CONTROL_ENABLE; // RESET<br />
if (!SetCommState(h_com, &amp;dcb))<br />
return ;<br />
dcb.fRtsControl=RTS_CONTROL_DISABLE; //RESET OFF<br />
// Wait for 50 ms<br />
Sleep(50);<br />
if (!SetCommState(h_com, &amp;dcb))<br />
return ;</p>
<p>CString str;<br />
DWORD dwCount;<br />
char cData[2];<br />
int byte;<br />
for (byte = 0; byte &lt;15; byte++)<br />
{</p>
<p>ReadFile(h_com,cData,2,&amp;dwCount,0); // das Problem !!!<br />
log += dezhex(cData[0]); // dezhex() wandelt nur die Zahlen<br />
log += dezhex(cData[1]); // in hex und steckt sie dann in log<br />
// ABER das Vorzeichen macht Probleme<br />
}<br />
log += &quot;\r\n&quot;; // für eine Leerzeile<br />
------------------schnipp schnipp ende ------------------------</p>
<p>ICh wäre sehr sehr Dankebar für eine der 3 Lösungen, cData ist hex oder binär oder eine Dezimalzahl in ohne vorzeichen.<br />
Ich habe Visual Studio 2003 net. Progge unter MFC in c++<br />
Ich würde sogere an meinen Projekt weitermachen. :-)))</p>
<p>mfg Tomycat</p>
]]></description><link>https://www.c-plusplus.net/forum/post/514286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/514286</guid><dc:creator><![CDATA[Tomycat2004]]></dc:creator><pubDate>Tue, 04 May 2004 17:03:45 GMT</pubDate></item></channel></rss>