<?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[Comport zwar offen, kann aber nicht senden oder empfangen.]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich versuch gerade einen ComPOrt verbindung herzustellen. Die Funktion um zu überprüfen, ob der Comport geöffnet ist, gibt mir ein True zurück, allerdings kann ich weder daten senden noch empfanden. Woran kann das liegen? Was ich auch aus technischer Sicht nicht ganz verstehe sind die iTimeout iTotalTimeout Variablen in der Klasse. Wenn ich über ein andere Tool zuvor eine RS232 Verbindung hergestellt habe, dann klappt's auch danach mit meiner. Mach ich einen Etablierungsfehler?</p>
<p>Hier mein Code im Prog! (isOpen wirft mir ein True zurück, sowie für alle anderen RS232 Tools ist dieser Comport gesperrt!)</p>
<p>Meine Umgebung ist VC++ 7 Win2000!</p>
<p>Ich wäre um Hilfe echt froh!!!! DANKE!!!</p>
<pre><code class="language-cpp">//[...]
    //Comport test

    port.Init(com/*iPort*/,9600/*iBaud*/,8/*iSize*/,0/*iParity*/,1/*stopbit*/,0/*fRtsControl*/,100/*iTimeout*/,1000/*iTotalTimeout*/);
    bool comtest;   
    comtest = port.isOpen();
    port.Send(&quot;*IDN?;\n&quot;,7);
    port.Close();

    //Comport test

//[...]
//Klasse

//HEADER

// Seriellport.h: Schnittstelle für die Klasse CSERIELL.

#if !defined(SERIELLPORT_H)
#define SERIELLPORT_H

#if _MSC_VER &gt; 1000
#pragma once
#endif // _MSC_VER &gt; 1000

#include &lt;windows.h&gt;

class CSERIELL  
{
public:
    CSERIELL();                                     
    ~CSERIELL();    
    bool Init(int iPort, int Baud =9600, int Size =8, int Parity =0, int stopbit=0, int fRtsControl =2, int Timeout =100, int TotalTimeout =1000); 
    int Receive(void *PUFFER, int MAXBYTES);        
    bool Send(void *PUFFER, unsigned int nBYTES);   
    bool Close();
    char* Geterror();

    bool isOpen();                                  

private:
    char* m_error;
    HANDLE m_hPort;
};

#endif 

//Source CPP

// Seriellport.cpp: Implementierung der Klasse CSERIELL.
//

#include &quot;stdafx.h&quot;
#include &quot;Seriellport.h&quot;
#include &lt;stdio.h&gt;
#include &lt;iostream.h&gt;

CSERIELL::CSERIELL()
{
    this-&gt;m_error= NULL;
    this-&gt;m_hPort= 0;                        
}

CSERIELL::~CSERIELL()
{
    this-&gt;Close();                           
}

//sendet Daten zur seriellen Schnittstelle
bool CSERIELL::Send(void *puffer, unsigned int len)
{
    DWORD written= 0;                       
    if(isOpen())
    {                                       
        WriteFile(this-&gt;m_hPort, puffer, len, &amp;written, NULL);
    }
    if(len == written)                      
        return true;

    return false;
}

//holt Daten von der seriellen Schnittstelle
int CSERIELL::Receive(void *puffer, int len)
{
    DWORD receive=0;
    if(m_hPort !=0 &amp;&amp; len &gt;0)
    {
        ReadFile(m_hPort, puffer, len, &amp;receive, NULL);
    }
    if(receive==0)

    return receive;
}

//schließt die serielle Schnittstelle
bool CSERIELL::Close()
{
    if(isOpen())
    {
        CloseHandle(this-&gt;m_hPort);
        this-&gt;m_hPort= 0;    
        return true;
    }
    return false;
}

//Ist serielle Schnittstelle offen
bool CSERIELL::isOpen()
{
    if(m_hPort &gt;0)
        return true;
//  this-&gt;m_error= ERROR_port_init;
    return false;
}

char* CSERIELL::Geterror()
{
    return m_error;
}

bool CSERIELL::Init(int iPort, int iBaud, int iSize, int iParity, int stopbit, int fRtsControl, int iTimeout, int iTotalTimeout)
{
    char port[]= &quot;COM0123456789:&quot;;          
    sprintf(port, &quot;COM%i:&quot;, iPort);

    m_hPort = CreateFile(   port, 
        GENERIC_READ | GENERIC_WRITE, 
        0, 
        NULL, 
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, 
        NULL);
    if((int)this-&gt;m_hPort == -1)         //COMx ist nicht vorhanden
            this-&gt;m_hPort=0;
    if(this-&gt;m_hPort !=0)                    
    {
        COMMTIMEOUTS comtime;   
        GetCommTimeouts(this-&gt;m_hPort, &amp;comtime);
        comtime.ReadIntervalTimeout= iTimeout;
        comtime.ReadTotalTimeoutConstant= iTotalTimeout;
        comtime.WriteTotalTimeoutConstant= iTotalTimeout;
        comtime.ReadTotalTimeoutMultiplier=2;
        comtime.WriteTotalTimeoutMultiplier=0;
        SetCommTimeouts(this-&gt;m_hPort, &amp;comtime);

        DCB dcb;           //Gerätekommunikationsanpassung
        GetCommState(this-&gt;m_hPort, &amp;dcb);
        dcb.BaudRate= iBaud;
        dcb.ByteSize= iSize;
        dcb.DCBlength= 28;
        dcb.EofChar= 0;
        dcb.ErrorChar= 0;
        dcb.fRtsControl= fRtsControl;
        dcb.Parity= iParity;
        dcb.StopBits= stopbit;
        dcb.fInX=0;
        dcb.fOutX=0;

    SetCommState(this-&gt;m_hPort, &amp;dcb);
    return true;
    }

    return false;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/5679/comport-zwar-offen-kann-aber-nicht-senden-oder-empfangen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 04:58:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/5679.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Apr 2003 06:16:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Comport zwar offen, kann aber nicht senden oder empfangen. on Wed, 30 Apr 2003 06:16:00 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich versuch gerade einen ComPOrt verbindung herzustellen. Die Funktion um zu überprüfen, ob der Comport geöffnet ist, gibt mir ein True zurück, allerdings kann ich weder daten senden noch empfanden. Woran kann das liegen? Was ich auch aus technischer Sicht nicht ganz verstehe sind die iTimeout iTotalTimeout Variablen in der Klasse. Wenn ich über ein andere Tool zuvor eine RS232 Verbindung hergestellt habe, dann klappt's auch danach mit meiner. Mach ich einen Etablierungsfehler?</p>
<p>Hier mein Code im Prog! (isOpen wirft mir ein True zurück, sowie für alle anderen RS232 Tools ist dieser Comport gesperrt!)</p>
<p>Meine Umgebung ist VC++ 7 Win2000!</p>
<p>Ich wäre um Hilfe echt froh!!!! DANKE!!!</p>
<pre><code class="language-cpp">//[...]
    //Comport test

    port.Init(com/*iPort*/,9600/*iBaud*/,8/*iSize*/,0/*iParity*/,1/*stopbit*/,0/*fRtsControl*/,100/*iTimeout*/,1000/*iTotalTimeout*/);
    bool comtest;   
    comtest = port.isOpen();
    port.Send(&quot;*IDN?;\n&quot;,7);
    port.Close();

    //Comport test

//[...]
//Klasse

//HEADER

// Seriellport.h: Schnittstelle für die Klasse CSERIELL.

#if !defined(SERIELLPORT_H)
#define SERIELLPORT_H

#if _MSC_VER &gt; 1000
#pragma once
#endif // _MSC_VER &gt; 1000

#include &lt;windows.h&gt;

class CSERIELL  
{
public:
    CSERIELL();                                     
    ~CSERIELL();    
    bool Init(int iPort, int Baud =9600, int Size =8, int Parity =0, int stopbit=0, int fRtsControl =2, int Timeout =100, int TotalTimeout =1000); 
    int Receive(void *PUFFER, int MAXBYTES);        
    bool Send(void *PUFFER, unsigned int nBYTES);   
    bool Close();
    char* Geterror();

    bool isOpen();                                  

private:
    char* m_error;
    HANDLE m_hPort;
};

#endif 

//Source CPP

// Seriellport.cpp: Implementierung der Klasse CSERIELL.
//

#include &quot;stdafx.h&quot;
#include &quot;Seriellport.h&quot;
#include &lt;stdio.h&gt;
#include &lt;iostream.h&gt;

CSERIELL::CSERIELL()
{
    this-&gt;m_error= NULL;
    this-&gt;m_hPort= 0;                        
}

CSERIELL::~CSERIELL()
{
    this-&gt;Close();                           
}

//sendet Daten zur seriellen Schnittstelle
bool CSERIELL::Send(void *puffer, unsigned int len)
{
    DWORD written= 0;                       
    if(isOpen())
    {                                       
        WriteFile(this-&gt;m_hPort, puffer, len, &amp;written, NULL);
    }
    if(len == written)                      
        return true;

    return false;
}

//holt Daten von der seriellen Schnittstelle
int CSERIELL::Receive(void *puffer, int len)
{
    DWORD receive=0;
    if(m_hPort !=0 &amp;&amp; len &gt;0)
    {
        ReadFile(m_hPort, puffer, len, &amp;receive, NULL);
    }
    if(receive==0)

    return receive;
}

//schließt die serielle Schnittstelle
bool CSERIELL::Close()
{
    if(isOpen())
    {
        CloseHandle(this-&gt;m_hPort);
        this-&gt;m_hPort= 0;    
        return true;
    }
    return false;
}

//Ist serielle Schnittstelle offen
bool CSERIELL::isOpen()
{
    if(m_hPort &gt;0)
        return true;
//  this-&gt;m_error= ERROR_port_init;
    return false;
}

char* CSERIELL::Geterror()
{
    return m_error;
}

bool CSERIELL::Init(int iPort, int iBaud, int iSize, int iParity, int stopbit, int fRtsControl, int iTimeout, int iTotalTimeout)
{
    char port[]= &quot;COM0123456789:&quot;;          
    sprintf(port, &quot;COM%i:&quot;, iPort);

    m_hPort = CreateFile(   port, 
        GENERIC_READ | GENERIC_WRITE, 
        0, 
        NULL, 
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, 
        NULL);
    if((int)this-&gt;m_hPort == -1)         //COMx ist nicht vorhanden
            this-&gt;m_hPort=0;
    if(this-&gt;m_hPort !=0)                    
    {
        COMMTIMEOUTS comtime;   
        GetCommTimeouts(this-&gt;m_hPort, &amp;comtime);
        comtime.ReadIntervalTimeout= iTimeout;
        comtime.ReadTotalTimeoutConstant= iTotalTimeout;
        comtime.WriteTotalTimeoutConstant= iTotalTimeout;
        comtime.ReadTotalTimeoutMultiplier=2;
        comtime.WriteTotalTimeoutMultiplier=0;
        SetCommTimeouts(this-&gt;m_hPort, &amp;comtime);

        DCB dcb;           //Gerätekommunikationsanpassung
        GetCommState(this-&gt;m_hPort, &amp;dcb);
        dcb.BaudRate= iBaud;
        dcb.ByteSize= iSize;
        dcb.DCBlength= 28;
        dcb.EofChar= 0;
        dcb.ErrorChar= 0;
        dcb.fRtsControl= fRtsControl;
        dcb.Parity= iParity;
        dcb.StopBits= stopbit;
        dcb.fInX=0;
        dcb.fOutX=0;

    SetCommState(this-&gt;m_hPort, &amp;dcb);
    return true;
    }

    return false;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/27640</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/27640</guid><dc:creator><![CDATA[MrSaint]]></dc:creator><pubDate>Wed, 30 Apr 2003 06:16:00 GMT</pubDate></item><item><title><![CDATA[Reply to Comport zwar offen, kann aber nicht senden oder empfangen. on Mon, 05 May 2003 19:45:00 GMT]]></title><description><![CDATA[<p>also mit VC++6 und Win98, WinNT, Win2K und WinXP funzt das Orginal Deiner Klasse <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="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/27641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/27641</guid><dc:creator><![CDATA[toosten]]></dc:creator><pubDate>Mon, 05 May 2003 19:45:00 GMT</pubDate></item><item><title><![CDATA[Reply to Comport zwar offen, kann aber nicht senden oder empfangen. on Tue, 06 May 2003 04:29:00 GMT]]></title><description><![CDATA[<blockquote>
<p>port.Init(com/*iPort</p>
</blockquote>
<p>Hier solltest du einen Port angeben und nicht com reinschreiben.</p>
<p>Weiters mal einen Debug machen was die einzelnen Funktionen zurückliefern.</p>
<p>[ Dieser Beitrag wurde am 06.05.2003 um 06:30 Uhr von <strong>Unix-Tom</strong> editiert. ]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/27642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/27642</guid><dc:creator><![CDATA[Unix-Tom]]></dc:creator><pubDate>Tue, 06 May 2003 04:29:00 GMT</pubDate></item><item><title><![CDATA[Reply to Comport zwar offen, kann aber nicht senden oder empfangen. on Tue, 06 May 2003 04:38:00 GMT]]></title><description><![CDATA[<p>Also die einzelnen Funktionen liefern jeweils 'ne 1 bzw True zurück. Bei com handelt sich um 'ne Variabel, aber die wird schon richtig gesetzt, ich hab das nu hier aus meinem Code ausgeschnitten. Ich werde mal etwas probeweise unter c++ 6 kompilieren, und wenn es dort klappt habi ch definitiv ein Problem... hmm..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/27643</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/27643</guid><dc:creator><![CDATA[MrSaint]]></dc:creator><pubDate>Tue, 06 May 2003 04:38:00 GMT</pubDate></item><item><title><![CDATA[Reply to Comport zwar offen, kann aber nicht senden oder empfangen. on Tue, 06 May 2003 05:14:00 GMT]]></title><description><![CDATA[<p>Schuss ins Blaue:<br />
Nimm mal den Doppelpunkt aus dem Formatstring raus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/27644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/27644</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Tue, 06 May 2003 05:14:00 GMT</pubDate></item></channel></rss>