<?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[Werte in Hexadezimal an Messgerät senden über RS232]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich habe ein problem wo ich schon den ganzen Tag dran hänge . Wie kann ich auf ein Messgerät Hexadezimal werte senden und mit antwort zurückbekommen aus meinen Sendebefehl. Habe es shcon probiert werte eingegeben in ein Edit feld aber so richtig sendet er die Werte nicht gibt es da ein Sendbefehl unter RS 232. Würde mich über eine Antwort freuen .</p>
<p>Gruss Praetorianer</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/92805/werte-in-hexadezimal-an-messgerät-senden-über-rs232</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Jul 2026 23:08:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/92805.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Nov 2004 14:58:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Werte in Hexadezimal an Messgerät senden über RS232 on Tue, 23 Nov 2004 14:58:14 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Ich habe ein problem wo ich schon den ganzen Tag dran hänge . Wie kann ich auf ein Messgerät Hexadezimal werte senden und mit antwort zurückbekommen aus meinen Sendebefehl. Habe es shcon probiert werte eingegeben in ein Edit feld aber so richtig sendet er die Werte nicht gibt es da ein Sendbefehl unter RS 232. Würde mich über eine Antwort freuen .</p>
<p>Gruss Praetorianer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/657306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/657306</guid><dc:creator><![CDATA[Praetorianer_33]]></dc:creator><pubDate>Tue, 23 Nov 2004 14:58:14 GMT</pubDate></item><item><title><![CDATA[Reply to Werte in Hexadezimal an Messgerät senden über RS232 on Tue, 23 Nov 2004 15:47:19 GMT]]></title><description><![CDATA[<p>Brauchst halt ne Komponente dafür.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/657354</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/657354</guid><dc:creator><![CDATA[HEZ]]></dc:creator><pubDate>Tue, 23 Nov 2004 15:47:19 GMT</pubDate></item><item><title><![CDATA[Reply to Werte in Hexadezimal an Messgerät senden über RS232 on Wed, 24 Nov 2004 10:52:29 GMT]]></title><description><![CDATA[<p>HEZ schrieb:</p>
<blockquote>
<p>Brauchst halt ne Komponente dafür.</p>
</blockquote>
<p>Am besten schau bei <a href="http://www.torry.net" rel="nofollow">www.torry.net</a> nach. Das gibts viele kostenlose Komponenten, die Deinen Zweck erfüllen sollten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/657841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/657841</guid><dc:creator><![CDATA[Burkhi]]></dc:creator><pubDate>Wed, 24 Nov 2004 10:52:29 GMT</pubDate></item><item><title><![CDATA[Reply to Werte in Hexadezimal an Messgerät senden über RS232 on Thu, 25 Nov 2004 18:46:59 GMT]]></title><description><![CDATA[<p>Hallo ich habe mir eine Klasse für die RS232 Communication geschrieben.</p>
<pre><code class="language-cpp">//***************************************************************************
// Header
//***************************************************************************
//---------------------------------------------------------------------------
#ifndef rs232H
#define rs232H
#include &quot;rs232.h&quot;
#include &lt;ComCtrls.hpp&gt;
class rs232
{
private:	// Benutzer-Deklarationen

public:		// Benutzer-Deklarationen

     rs232();   	//Konstruktor
     int baudrate;
     AnsiString comport;
     int timeout;
     bool simulate;
     bool online;
     bool init_rs232(void);
     bool write_rs232(unsigned char data);
     bool read_rs232(unsigned char* data);
     void close_comport(void);
     bool write_check(char data,unsigned char* rs_data);
     bool get_high_low(signed __int16* data);
     bool write_high_low(unsigned int data);
     bool get_modul_values(void);
     void test_comports(TMenuItem* com1,TMenuItem* com2,TMenuItem*        
     com3,TMenuItem* com4);
     bool send_command(char a, char b);
     void controller_error(TStatusBar* obj,char item,TTimer* timer,char* text);
     HANDLE chandle1;
     DCB dcb;
     COMMTIMEOUTS rs232timeout;
};
//---------------------------------------------------------------------------
#endif
//***************************************************************************
// cpp Modul
//***************************************************************************
#include &lt;vcl\vcl.h&gt;
#include &lt;stdio.h&gt;
#include &quot;rs232.h&quot;
//--------------Konstruktor----------------------------------------------------
rs232::rs232()
{
     baudrate = 19200;
     comport  = &quot;com1&quot;;
     timeout  = 1000;
     simulate = false;
     online   = false;
}
//------------------------------------------------------------------------------
bool rs232::init_rs232(void)
{
     chandle1 = CreateFile(comport.c_str(),GENERIC_WRITE | GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
     if (chandle1 != INVALID_HANDLE_VALUE)
     {
    	GetCommState(chandle1,&amp;dcb);
        GetCommTimeouts(chandle1,&amp;rs232timeout);
      //  dcb.DCBlength = 10;
        dcb.fBinary = true;
        dcb.Parity = false; // no parity bit
        dcb.fOutxCtsFlow = false;
        dcb.fOutxDsrFlow = false;
        dcb.fDtrControl = DTR_CONTROL_DISABLE;
        dcb.fDsrSensitivity = false;
        dcb.fTXContinueOnXoff = false;
    	   dcb.BaudRate = baudrate; // set the baud rate
        dcb.ByteSize = 8; // data size, xmit, and rcv
        dcb.fOutX = false;
        dcb.fInX = false;
        dcb.fErrorChar = false;
        dcb.fNull = false;
        dcb.fRtsControl = RTS_CONTROL_DISABLE;
        dcb.fAbortOnError = false;
        dcb.XonLim;
        dcb.XoffLim;
        dcb.ByteSize;
        dcb.Parity;
        dcb.StopBits = ONESTOPBIT ;
        dcb.XonChar;
        dcb.XoffChar;
        dcb.ErrorChar;
        dcb.EofChar;
        dcb.EvtChar;
        dcb.wReserved1;
        rs232timeout.ReadIntervalTimeout = 1000;
        rs232timeout.ReadTotalTimeoutMultiplier = timeout;
        rs232timeout.ReadTotalTimeoutConstant = 0;
        if(SetCommState(chandle1, &amp;dcb))
        {
            if (SetCommTimeouts(chandle1,&amp;rs232timeout))
            {

               	return 1;
            }
            else
            {
             	CloseHandle(chandle1);
            	return 0;
            }
        }
        else
        {
         	     CloseHandle(chandle1);
               return 0;
        }

    }
    return 0;
}
//------------------------------------------------------------------------------
bool rs232::write_rs232(unsigned char data)
{
	unsigned long y;
 	if (!WriteFile(chandle1,&amp;data,1,&amp;y,0))
     {
    	     return 0;
     }
     return 1;
}
//------------------------------------------------------------------------------
bool rs232::read_rs232(unsigned char* data)
{
	unsigned long b;
 	ReadFile(chandle1,data,1,&amp;b,NULL);
     if (b == 0)
     {
          return 0;
     }
     return 1;
}
//------------------------------------------------------------------------------
void rs232::close_comport(void)
{
     CloseHandle(chandle1);
     return;
}
//------------------------------------------------------------------------------
bool rs232::write_check(char data,unsigned char* rs_data)
{
     if(simulate)
     {
          rs_data = (unsigned char*) 0x55;
          return 1;
     }
     write_rs232(data);
     if (!read_rs232(rs_data))
     {
          return 0;
     }
     return 1;
}
//------------------------------------------------------------------------------
bool rs232::send_command(char a, char b)
{
     unsigned char back;
     if(a != NULL)
     {
          if (write_check(a,&amp;back))              //Prog End
          {
               if (!write_check(b,&amp;back))
    		     {
                    return 0;
    		     }
          }
          else
          {
               return 0;
          }
          return 1;
     }
     else
     {
          if (!write_check(b,&amp;back))
    		{
               return 0;
    		}
          return 1;
     }
     return 0;
}
//------------------------------------------------------------------------------
bool  rs232::get_high_low(signed __int16* data)
{
     unsigned char rs_data;
     signed int temp;
 	if (!write_check(0,&amp;rs_data))
     {
    	     return 0;
     }
     else
     {
       	temp =  rs_data &lt;&lt; 8;
     }
     if (!write_check(0,&amp;rs_data))
     {
    	     return 0;
     }
     else
     {
          temp = temp | rs_data;
     }
    *data = temp;
    return 1;
}
//-----------------------------------------------------------------------------
bool  rs232::write_high_low(unsigned int data)
{
     unsigned char rs_data;
 	if (!write_check(data&gt;&gt;8,&amp;rs_data))
     {
    	     return 0;
     }
     else
     {
     	if (!write_check(data,&amp;rs_data))
     	{
    	     	return 0;
     	}
	}
    return 1;
}
//-----------------------------------------------------------------------------
void rs232::test_comports(TMenuItem* com1,TMenuItem* com2,TMenuItem* com3,TMenuItem* com4)
{
 	comport = &quot;com1&quot;;
	if(init_rs232())
     {
		com1-&gt;Enabled = true;
	}
     close_comport();

	comport = &quot;com2&quot;;
	if(init_rs232())
     {
     	com2-&gt;Enabled = true;
	}
     close_comport();

    	comport = &quot;com3&quot;;
	if(init_rs232())
     {
     	com3-&gt;Enabled = true;
	}
     close_comport();

	comport = &quot;com4&quot;;
	if(init_rs232())
     {
     	com4-&gt;Enabled = true;
	}
     close_comport();
     return;
}
void rs232::controller_error(TStatusBar* obj,char item,TTimer* timer,char* text)
{
     online = false;
     if(obj != NULL)
     {
          if(item != NULL)
          {
               obj-&gt;Panels-&gt;Items[item]-&gt;Text = &quot;Status:Offline&quot;;
          }
          else
          {
               obj-&gt;SimpleText = &quot;Status:Offline&quot;;
          }
     }
     if(timer != NULL)
     {
          timer-&gt;Enabled = false;
     }
	Application-&gt;MessageBox(&quot;Programm is Offline&quot;,text,MB_OK | 
         MB_ICONERROR);
     return;
}
</code></pre>
<p>Du benötigst zum senden eines Bytes nur die Funktion write_rs232 sowie<br />
zum empfangen eines Bytes die Funktion read_rs232.</p>
<pre><code class="language-cpp">//--------------------------------------------------------
// Objekt com erzeugen und Eigenschaften initialisieren
//--------------------------------------------------------
     com = new rs232;
     com-&gt;baudrate = 19200;     //Baudrate 19200
     com-&gt;comport  = &quot;com1&quot;;    //Port Com1 
     com-&gt;timeout  = 500;       //Timeout 500ms

//--------------------------------------------------------
// Port initialisieren
//--------------------------------------------------------

     if(!(com-&gt;init_rs232()))
     {
          Application-&gt;MessageBox(&quot;RS232 Port not found&quot;,&quot; &quot;,MB_OK | 
          MB_ICONERROR);
     }

//--------------------------------------------------------
// Senden
//--------------------------------------------------------

     if(!com-&gt;write_rs232(0xaa))
     {
          //Sende Fehler
     } 
          //Erfolgreich gesendet

//--------------------------------------------------------
// Empfangen
//--------------------------------------------------------

   char data;

     if(!com-&gt;read_rs232(&amp;data)) 
     {
         //Fehler        z.B. Timeout 500ms
     }
        //Erfolgreich Byte in data
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/659322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/659322</guid><dc:creator><![CDATA[hermes]]></dc:creator><pubDate>Thu, 25 Nov 2004 18:46:59 GMT</pubDate></item><item><title><![CDATA[Reply to Werte in Hexadezimal an Messgerät senden über RS232 on Fri, 26 Nov 2004 05:12:01 GMT]]></title><description><![CDATA[<p>wenn wir schonmal dabei sind den COM Port abzuhandeln, hier mein TCommSettings<br />
Control, damit kann man sich super leicht den COM Port wählen. Die am<br />
jeweiligen PC vorhandenen Ports werden erkannt, die Einstellungen können<br />
in einer ini gespeichert werden.</p>
<p>Beim Starten der Anwendung muss<br />
CommSettings-&gt;LoadFromINI();<br />
aufgerufen werden.</p>
<p>beim Beenden kann<br />
CommSettings-&gt;SaveToINI();<br />
aufgerufen werden, wenn man die Einstellungen speichen will.</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

   .-------------------------------------------------------------------------.
   |  S I E M E N S   E N G I N E   5.1                                      |
   |  (c) 2004 by ACiD[mrp]                                                  |
   |                                                                         |
   |  GSM Development Crew                                                   |
   |  www.gsm-dev.com                                                        |
   |                                                                         |
   |  COM, USB, AT, BFB, BFC, IrObex, Flash35, Flash45, Flash55, Flash65     |
   |                                                                         |
   '-------------------------------------------------------------------------'

#ifndef CommSettingsH
#define CommSettingsH
//---------------------------------------------------------------------------
#include &lt;SysUtils.hpp&gt;
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;ExtCtrls.hpp&gt;
#include &lt;registry.hpp&gt;
#include &lt;inifiles.hpp&gt;

//---------------------------------------------------------------------------
class PACKAGE TCommSettings : public TPanel
{
private:
    TLabel * lblComPort;
    TComboBox * selComPort;

    TLabel * lblBaudRate;
    TComboBox * selBaudRate;

    void __fastcall TCommSettings::GetCommPorts(TStrings *strCommPorts);
    void __fastcall TCommSettings::GetPortSpeeds(TStrings *strPortSpeeds);
    void __fastcall TCommSettings::Resize(TObject *Sender);
protected:
public:
    void __fastcall TCommSettings::LoadFromINI(void);
    void __fastcall TCommSettings::SaveToINI(void);
    AnsiString __fastcall TCommSettings::GetPort(void);
    int __fastcall TCommSettings::GetBaudRate(void);

    __fastcall TCommSettings(TComponent* Owner);
__published:
};
//---------------------------------------------------------------------------
#endif
</code></pre>
<pre><code class="language-cpp">#include &lt;vcl.h&gt;

#pragma hdrstop

#include &quot;CommSettings.h&quot;
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Mit ValidCtrCheck wird sichergestellt, daß die erzeugten Komponenten
// keine rein virtuellen Funktionen besitzen.
//

static inline void ValidCtrCheck(TCommSettings *)
{
    new TCommSettings(NULL);
}

//---------------------------------------------------------------------------
__fastcall TCommSettings::TCommSettings(TComponent* Owner)
    : TPanel(Owner)
{

    lblComPort = new TLabel(this);
    lblComPort-&gt;Parent = this;
    lblComPort-&gt;Left = 8;
    lblComPort-&gt;Top = 8;
    lblComPort-&gt;Caption = &quot;COM Port:&quot;;

    selComPort = new TComboBox(this);
    selComPort-&gt;Parent = this;
    selComPort-&gt;Left = 24;
    selComPort-&gt;Top = 24;
    selComPort-&gt;Style = csDropDownList;

    lblBaudRate = new TLabel(this);
    lblBaudRate-&gt;Parent = this;
    lblBaudRate-&gt;Left = 8;
    lblBaudRate-&gt;Top = 56;
    lblBaudRate-&gt;Caption = &quot;Baud Rate:&quot;;

    selBaudRate = new TComboBox(this);
    selBaudRate-&gt;Parent = this;
    selBaudRate-&gt;Left = 24;
    selBaudRate-&gt;Top = 72;
    selBaudRate-&gt;Style = csDropDownList;

    this-&gt;Constraints-&gt;MinHeight = 105;
    this-&gt;Constraints-&gt;MinWidth = 177;
    this-&gt;OnResize = Resize;
    this-&gt;Height = 105;
    this-&gt;Width = 177;
    //LoadFromINI();

}

void __fastcall TCommSettings::Resize(TObject *Sender)
{
    this-&gt;Caption = &quot;&quot;;
}

void __fastcall TCommSettings::GetPortSpeeds(TStrings *strPortSpeeds)
{
    strPortSpeeds-&gt;Clear();
    strPortSpeeds-&gt;Add(&quot;1200&quot;);
    strPortSpeeds-&gt;Add(&quot;2400&quot;);
    strPortSpeeds-&gt;Add(&quot;4800&quot;);
    strPortSpeeds-&gt;Add(&quot;9600&quot;);
    strPortSpeeds-&gt;Add(&quot;19200&quot;);
    strPortSpeeds-&gt;Add(&quot;38400&quot;);
    strPortSpeeds-&gt;Add(&quot;57600&quot;);
    strPortSpeeds-&gt;Add(&quot;115200&quot;);
    strPortSpeeds-&gt;Add(&quot;230400&quot;);
    strPortSpeeds-&gt;Add(&quot;460800&quot;);
    strPortSpeeds-&gt;Add(&quot;921600&quot;);
    strPortSpeeds-&gt;Add(&quot;1843200&quot;);
    strPortSpeeds-&gt;Add(&quot;3686400&quot;);
}

void __fastcall TCommSettings::GetCommPorts(TStrings *strCommPorts)
{
    // Alle verfügbaren COM Ports aus der Registry auslesen
    // und als TStrings zurückgeben
    TStringList *MyStringList = new TStringList;
    TRegistry *MyReg = new TRegistry;
    MyReg-&gt;RootKey = HKEY_LOCAL_MACHINE;
    MyReg-&gt;OpenKey(&quot;\\HARDWARE\\DEVICEMAP\\SERIALCOMM&quot;, false);
    MyReg-&gt;GetValueNames(MyStringList);
    for (int i=0; i&lt;MyStringList-&gt;Count; i++) {
        MyStringList-&gt;Strings[i] = MyReg-&gt;ReadString(MyStringList-&gt;Strings[i])
             + &quot;: &quot;
             + MyStringList-&gt;Strings[i].SubString(9,MyStringList-&gt;Strings[i].Length())
             + &quot;&quot;;
    }
    MyStringList-&gt;Sort();

    for (int i=0; i&lt;MyStringList-&gt;Count; i++) {
        strCommPorts-&gt;Add(MyStringList-&gt;Strings[i]);
    }
    if (strCommPorts-&gt;Count == 0) {
        // Autodetection failed
        for (int i = 1; i&lt;129; i++) {
            strCommPorts-&gt;Add(&quot;COM&quot;+IntToStr(i));
        }
    }

    MyReg-&gt;CloseKey();
    delete MyReg;
    delete MyStringList;
}

AnsiString __fastcall TCommSettings::GetPort(void)
{
    //return &quot;COM4&quot;;
    return selComPort-&gt;Text;
    //ShowMessage(selComPort-&gt;Items-&gt;Strings[selComPort-&gt;ItemIndex]);
}

int __fastcall TCommSettings::GetBaudRate(void)
{
    return selBaudRate-&gt;Text.ToIntDef(115200);
}

void __fastcall TCommSettings::LoadFromINI(void)
{
    GetCommPorts(selComPort-&gt;Items);
    GetPortSpeeds(selBaudRate-&gt;Items);

    TIniFile *ini;
    ini = new TIniFile(ChangeFileExt(Application-&gt;ExeName, &quot;.ini&quot;));

    AnsiString strTemp=ini-&gt;ReadString(&quot;COMPort&quot;, &quot;COMPortNumber&quot;, &quot;COM1&quot;);
    for (int i = 0; i&lt;selComPort-&gt;Items-&gt;Count; i++) {
        if (selComPort-&gt;Items-&gt;Strings[i].SubString(1,strTemp.Length()) == strTemp) {
            selComPort-&gt;ItemIndex = i;
            i=selComPort-&gt;Items-&gt;Count;  // break
        }
    }

    int iTemp = ini-&gt;ReadInteger(&quot;COMPort&quot;,&quot;COMPortSpeed&quot;, 115200);
    for (int i = 0; i&lt;selBaudRate-&gt;Items-&gt;Count; i++) {
        if (selBaudRate-&gt;Items-&gt;Strings[i].ToIntDef(0) == iTemp) {
            selBaudRate-&gt;ItemIndex = i;
            i=selBaudRate-&gt;Items-&gt;Count;  // break
        }
    }

    delete ini;
}

void __fastcall TCommSettings::SaveToINI(void)
{
    TIniFile *ini;
    ini = new TIniFile(ChangeFileExt(Application-&gt;ExeName, &quot;.ini&quot;));

    AnsiString strTemp=selComPort-&gt;Text;
    strTemp = strTemp.SubString(1, strTemp.AnsiPos(&quot;:&quot;)-1);
    ini-&gt;WriteString(&quot;COMPort&quot;, &quot;COMPortNumber&quot;, strTemp);
    ini-&gt;WriteInteger(&quot;COMPort&quot;,&quot;COMPortSpeed&quot;, selBaudRate-&gt;Text.ToIntDef(115200));

    delete ini;
}

//---------------------------------------------------------------------------
namespace Commsettings
{
    void __fastcall PACKAGE Register()
    {
         TComponentClass classes[1] = {__classid(TCommSettings)};
         RegisterComponents(&quot;gsm-dev&quot;, classes, 0);
    }
}
//---------------------------------------------------------------------------
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/659547</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/659547</guid><dc:creator><![CDATA[Acidmrp]]></dc:creator><pubDate>Fri, 26 Nov 2004 05:12:01 GMT</pubDate></item><item><title><![CDATA[Reply to Werte in Hexadezimal an Messgerät senden über RS232 on Fri, 26 Nov 2004 23:25:11 GMT]]></title><description><![CDATA[<p>Hallo Acidmrp,</p>
<p>Ich möchte einige Sachen in deinem Code gerne erklärt bekommen.<br />
Wäre es für dich ein Problem einige Fragen zu beantworten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/660258</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/660258</guid><dc:creator><![CDATA[hermes]]></dc:creator><pubDate>Fri, 26 Nov 2004 23:25:11 GMT</pubDate></item></channel></rss>