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

Développement Windows Discussion :

Communication série entre un logiciel de caisse et un TPE


Sujet :

Développement Windows

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 16
    Points : 9
    Points
    9
    Par défaut Communication série entre un logiciel de caisse et un TPE
    Bonjour,

    Je développe un logiciel de caisse en VB.Net, et je dois communiquer avec un TPE, pour lui envoyer le montant à encaisser.

    J'ai trouvé la documentation du protocole CONCERT à utiliser : https://drive.google.com/file/d/0BxH...NYkFGRUY0/view

    Comme prévu, j'utilise donc un serialport pour ouvrir mon port, et envoyer une requète ENQ.

    Or, même si j'ai bien la réponse ACK du TPE, le terminal affiche "fonction impossible".

    Voici mon code :

    Code : 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
     
        Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            Dim Buffer(SerialPort1.BytesToRead - 1) As Byte
            SerialPort1.Read(Buffer, 0, SerialPort1.BytesToRead)
            If SerialPort1.Encoding.GetString(Buffer) = Chr(vbACK) Then
                Dim checksum As Integer = 0
                Dim ChaineEvoi As String = Chr(vbSTX) & "0100001599100978          " & Chr(vbETX)
                For Each car As Char In ChaineEvoi
                    checksum ^= Convert.ToByte(car)
                Next
                ChaineEvoi &= Chr(checksum)
                SerialPort1.WriteLine(ChaineEvoi)
                Dim toto2 As String = ""
            Else
                If SerialPort1.Encoding.GetString(Buffer) = Chr(15) Then
     
                End If
            End If
        End Sub
     
      Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
            Try
                With SerialPort1
                    .PortName = "COM5"
                    .Handshake = IO.Ports.Handshake.None
                    .ReceivedBytesThreshold = 1
                    .RtsEnable = False
                    .DtrEnable = True
                    .BaudRate = 9600
                    .DataBits = 7
                    .Parity = IO.Ports.Parity.Even
                    .StopBits = IO.Ports.StopBits.One
                    .ReadTimeout = 1000000
                    .Encoding = Encoding.ASCII
                    .Open()
                End With
     
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
     
     
            SerialPort1.Write(Chr(5))
     
        End Sub
    J'ai essayé différentes combinaisons de paramètres d'encoding, de handshake, rtsenable... j'arrive toujours au même résultat.

    Pareil, j'ai essayé d'envoyer un tableau de byte au lieu de chr(5), rien !!!!!

    Mon TPE me répond bien, je passe bien dans ma fonction SerialPort1_DataReceived et la réponse est bien ACK. Mais si je mets à point d'arrêt sur ma ligne Dim checksum As Integer = 0, avant d'envoyer la 2eme requète, le terminal affiche déjà "fonction impossible".

    Apparement, je ne suis pas le seul à avoir eu ce problème, mais sur les différents topics que j'ai pu trouver, soit la solution n'a jamais été trouvée, soit elle n'a pas été partagée....

    Quelqu'un aurait déjà rencontré de problème, et pourrait m'aider à le résoudre ?

    Merci !!!!!!!!!

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Septembre 2007
    Messages
    16
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2007
    Messages : 16
    Points : 9
    Points
    9
    Par défaut Résolu !!!!
    Bonjour,

    J'ai finalement résolu mon problème. Au cas où d'autres personnes le rencontrent, voici ma solution :

    En fait, Le TPE récupérait bien mon ENQ, mais m'affichait fonction impossible parce que je n'envoyait pas assez tôt la requête suivante quand je mettais un point d’arrêt, et sans point d’arrêt, le calcul du checksum n'était pas bon.

    Voici mon code en VB.NET :

    Code : 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
     
    Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
            Try
                With SerialPort1
                    .PortName = "COM5"
                    .Handshake = IO.Ports.Handshake.XOnXOff
                    .BaudRate = 9600
                    .DataBits = 7
                    .Parity = IO.Ports.Parity.Even
                    .StopBits = IO.Ports.StopBits.One
                    .ReadTimeout = 1000000
                    .Encoding = Encoding.ASCII
                    .Open()
                End With
     
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
     
            Etat = 1
            SerialPort1.Write(Chr(5))
     
        End Sub
     
     
     Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            Dim Buffer(SerialPort1.BytesToRead - 1) As Byte
            SerialPort1.Read(Buffer, 0, SerialPort1.BytesToRead)
            If SerialPort1.Encoding.GetString(Buffer) = Chr(vbACK) Then
                If Etat = 1 Then
                    Dim checksum As Integer = 0
                    Dim St_MontantCent As String = CInt(Montant * 100).ToString.PadLeft(8, "0")
     
                    'Dans la partie "constante : 1 indique que le champ REP sera dans la réponse du TPE, et le 0 indique un traitmeent de débit
                    Dim ChaineEvoi As String = Nocaisse & St_MontantCent & "1" & If(PaiementCheque, "C", "1") & "0978          " & Chr(3)
                    Dim byteChecksum As Byte
                    Dim strChar As Char
                    For Each strChar In ChaineEvoi
                        byteChecksum = byteChecksum Xor Convert.ToByte(strChar)
                    Next
                    ChaineEvoi = Chr(2) & ChaineEvoi & Convert.ToChar(byteChecksum)
                    SerialPort1.Write(ChaineEvoi)
                    Etat = 2
                Else
                    Dim tot As String = ""
                End If
            Else
                If SerialPort1.Encoding.GetString(Buffer) = Chr(15) Then
     
                End If
            End If
            SerialPort1.Close()
        End Sub
    Il me reste à traiter le retour du TPE après paiement.

    En espérant que ça dépanne certains !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Communication crypté entre logiciel et web service
    Par fozzeuh dans le forum Langages de programmation
    Réponses: 2
    Dernier message: 06/06/2014, 10h14
  2. Communication série entre 2 PC en python
    Par dayiri dans le forum Bibliothèques tierces
    Réponses: 6
    Dernier message: 06/06/2009, 09h59
  3. Communication entre 2 logiciels?
    Par toutounesan dans le forum MFC
    Réponses: 1
    Dernier message: 27/08/2007, 09h25
  4. [API] Communication série NON-bloquante : OVERLAPPED/Thread
    Par Rodrigue dans le forum C++Builder
    Réponses: 2
    Dernier message: 07/11/2003, 13h43

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