IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Delphi Discussion :

Aucun événement TComPort


Sujet :

Langage Delphi

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2016
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2016
    Messages : 48
    Points : 32
    Points
    32
    Par défaut Aucun événement TComPort
    Bonjour !

    J'ai un soucis avec l'utilisation du TComPort.

    Je reçoit une trame qui commence par un $ et qui se termine par un CR,LF. Je souhaite donc utiliser TComDataPacket et son événement OnPacket pour lire ma trame plus facilement en fixant mon StartString ET/OU StopString (j'ai fait les deux).

    Mais Delphi ne reçoit rien ! J'ai bien une réception car j'ai mon outil qui active une LED quand je reçois ou émet. Quand je lance la Com avec le le soft je vois bien que la communication se lance. Aucun soucis avec le baudrate ou autre bit de stop ou parité.

    Avec d'autre soft qui se contente de lire, je vois les trames. Avec un arduino j'ai simulé ma trame et ça fonctionne.

    J'ai donc mis un Timer avec lequel je vais lire manuellement le port avec TComPort::ReadStr et LA ! J'ai bien ma trame....

    Est ce que quelqu'un serait m'expliquer pourquoi ??? Quelqu'un a une solution ? Pourquoi je n'ai aucun événement ?

    Merci pour votre soutient

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 447
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 447
    Points : 24 849
    Points
    24 849
    Par défaut
    Je ne l'ai pas en Delphi, mais dans un petit projet, j'ai utilisé le TComPort et comme je ne voulais pas l'installer dans la palette, je l'ai instancié manuellement et je me souviens qu'il m'avait donné un peu plus de fil à retordre

    Si tu as une version UNICODE de Delphi
    Comment est pris en compte le StartString et StopString ? AnsiString ? RawByteString ? UnicodeString
    J'espère que c'est du AnsiString ou RawByteString !

    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    //---------------------------------------------------------------------------
    void __fastcall TPortComXXXMainForm::BtnOpenPortCOMClick(TObject *Sender)
    {
      BtnClosePortCOM->Click();
     
      if (cbxPortComSelector->ItemIndex >= 0)
      {
        if ( ! FComPort)
        {
          FComPort = new TComPort(NULL);
     
          TComDataPacket *TmpComDataPacket = new TComDataPacket(FComPort);
          TmpComDataPacket->ComPort = FComPort;
          TmpComDataPacket->StartString = (char)02;
          TmpComDataPacket->StopString = (char)0x0d;
          TmpComDataPacket->IncludeStrings = true;
          TmpComDataPacket->OnPacket = ComDataPacketEventHandler;
     
          TComLed *TmpComLed = new TComLed(FComPort);
          TmpComLed->ComPort = FComPort;
          TmpComLed->LedSignal = lsConn;
          TmpComLed->Left = ImageConnected->Left + ImageConnected->Width;
          TmpComLed->Top = ImageConnected->Top;
          TmpComLed->Parent = GroupBoxComSelector;
          TmpComLed->Visible = true;
     
          LabelComLedLegend->Top = TmpComLed->Top + TmpComLed->Height + 2;
          LabelComLedLegend->Left = TmpComLed->Left;
     
          TmpComLed = new TComLed(FComPort);
          TmpComLed->ComPort = FComPort;
          TmpComLed->LedSignal = lsRx;
          TmpComLed->Left = ImageConnected->Left + ImageConnected->Width + TmpComLed->Width;
          TmpComLed->Top = ImageConnected->Top;
          TmpComLed->Parent = GroupBoxComSelector;
          TmpComLed->Visible = true;
     
          TmpComLed = new TComLed(FComPort);
          TmpComLed->ComPort = FComPort;
          TmpComLed->LedSignal = lsTx;
          TmpComLed->Left = ImageConnected->Left + ImageConnected->Width + (2 * TmpComLed->Width);
          TmpComLed->Top = ImageConnected->Top;
          TmpComLed->Parent = GroupBoxComSelector;  
          TmpComLed->Visible = true;
     
          FComTerminal = new TComTerminal(FComPort);
          FComTerminal->ComPort = FComPort;
          FComTerminal->Emulation = teNone;
          FComTerminal->LocalEcho = true;
          FComTerminal->AppendLF = true;
          FComTerminal->ClearScreen();
     
          FComTerminal->Align = alClient;
          FComTerminal->Parent = TabSheetTerminal;
          FComTerminal->Visible = true;
        }
     
        FComPort->Port = cbxPortComSelector->Items->Strings[cbxPortComSelector->ItemIndex];
     
        if (RadioGroupComProtocol->ItemIndex == 0)
        {
          FComPort->BaudRate = br9600;
          FComPort->DataBits = dbSeven;
          FComPort->Parity->Bits = prEven;
          FComPort->StopBits = sbOneStopBit;
        }
        else
        {
          FComPort->BaudRate = br19200;
          FComPort->DataBits = dbEight;
          FComPort->Parity->Bits = prNone;
          FComPort->StopBits = sbOneStopBit;
        }
        FComPort->Open();
     
        GroupBoxComOperations->Visible = true;
        ImageConnected->Visible = true;
        ImageDisonnected->Visible = false;
     
        GroupBoxComOperations->Caption = "Opérations sur le Port COM Ouvert : " + FComPort->Port;
      }
      else
      {
        lblErrorPortComSelector->Caption = "Port non sélectionné !";
        lblErrorPortComSelector->Visible = true;
      }
    }

    Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    //---------------------------------------------------------------------------
    void __fastcall TPortComXXXMainForm::ComDataPacketEventHandler(System::TObject* Sender, const ComStringParam Str)
    {
      RawByteString RawStr = Str;
      int BufSize = RawStr.Length();
      char* Buffer = new char[BufSize * 2 + 1];
      ZeroMemory(Buffer, BufSize * 2 + 1);
      BinToHex(RawStr.c_str(), Buffer, BufSize);
      String HexaStr = Buffer;
      delete [] Buffer;
     
      String Traduction;
      TXXXCOMMessage Msg;
      TXXXCOMMessageData MsgData;
      if (CXXXCOMToolHelp::ParseXXXCOMResponse(Msg, MsgData, RawStr))
      {
        switch (Msg.Header.CodeCommand.Fourth4Bit)
        {
          case CC_POLLING :
            Traduction = AnsiString("Polling - Liaison Clef : ") + ((((TXXXCOMMessageData*)Msg.Data.Value)->Polling.Recv.LiaisonClef == D_AIGUILLAGE_ESCLAVE) ? "Esclave" : "Maître");
            Traduction += AnsiString(", Clef USB : ") + ((((TXXXCOMMessageData*)Msg.Data.Value)->Polling.Recv.ClefUSB == D_CLEF_USB_ACTIVE) ? "Active" : "Verrouillée");
            Traduction += AnsiString( ", Code Clavier : ") + ((((TXXXCOMMessageData*)Msg.Data.Value)->Polling.Recv.CodeClavier == D_CODE_CLAVIER_MODIFIE) ? "Modifié" : "Usine");
          break;
     
          case CC_AIGUILLAGE :
            Traduction = AnsiString("Aiguillage - ") + ((((TXXXCOMMessageData*)Msg.Data.Value)->Aiguillage.Recv.ACK == D_ACK) ? "ACK" : "NOK");
          break;
     
          case CC_VEROUILLAGE :
            Traduction = AnsiString("Verouillage - ") + ((((TXXXCOMMessageData*)Msg.Data.Value)->Verrouillage.Recv.ACK == D_ACK) ? "ACK" : "NOK");
          break;
     
          case CC_CODE_CLAVIER :
            Traduction = AnsiString("Code Clavier - ") + ((((TXXXCOMMessageData*)Msg.Data.Value)->CodeClavier.Recv.ACK == D_ACK) ? "ACK" : "NOK");
          break;
     
          default :
            Traduction = "Type de Message Inconnu !";
        }
      }
      else
        Traduction = "Erreur de Parsage";
     
      MemoCOMResponse->Lines->Add(HexaStr + " : " + Traduction);
    }
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2016
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2016
    Messages : 48
    Points : 32
    Points
    32
    Par défaut
    Merci ShaiLeTroll mais je n'aurai pas le temps de comprendre et m'embarquer sur ce chemin. j'aurais préféré rester avec le TComPort dans la palette et comprendre pourquoi ça ne marche pas.

  4. #4
    Membre chevronné

    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    1 288
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Août 2002
    Messages : 1 288
    Points : 1 936
    Points
    1 936
    Par défaut
    Es-tu sûr du CR LF en StopString, que ce ne soit pas qu'un CR? (les données reçues sont à analyser avec un logiciel qui permet de voir la différence, notepad++ par exemple)

    Le ComDatapacket est bien relié au comport?
    Delphi 7/XE2/XE3
    C#
    Oracle 9i à 12c
    SQL Server 2008 à 2014

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2016
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2016
    Messages : 48
    Points : 32
    Points
    32
    Par défaut
    Je suis sûr de moi, j'ai une doc en plus fourni...

    De toute façon j'ai tenté avec un simple CR ou LF ou mettre seulement un startString avec un des caractère présent dans la trame et rien du tout. Et ce problème le fait avec deux équipements ! Sauf l'arduino...

Discussions similaires

  1. [OL-2003] Aucun script ne s'exécute sur évènements NewMail et NewMailEx
    Par Pierre.SRI dans le forum VBA Outlook
    Réponses: 1
    Dernier message: 05/04/2012, 16h54
  2. Réponses: 4
    Dernier message: 23/06/2011, 15h52
  3. Réponses: 4
    Dernier message: 27/04/2010, 20h20
  4. Probleme évènement, aucune interaction !
    Par Erolgamer dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 13/07/2009, 00h38
  5. Comment ne rater aucun événement avec des sémaphores ?
    Par vince3147 dans le forum Langage
    Réponses: 4
    Dernier message: 15/08/2007, 12h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo