Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit Dim bal1 As New Balance Dim test As String Dim Time_start As Variant Dim Time_cur As Variant Dim texte As String Dim ret As Variant Private mycomm As Object Private Buffer As Variant 'String Private Lgbuffer As Integer Private reponse As String Dim i As Integer Public Const Time_out As Long = 10 Sub Main() 'comm_container.Show 'With bal1 '.port = 3 '.refart = "article" '.reflot = "lot" '.typepesee = "T" 'test = .reponse 'End With Set mycomm = CreateObject("MSCommLib.Mscomm") 'Set Mycomm = comm_container.Mycomm mycomm.CommPort = 3 'port 'on utilise le port passé en argument mycomm.Handshaking = 0 mycomm.RThreshold = 0 mycomm.InBufferSize = 1024 mycomm.DTREnable = False mycomm.RTSEnable = False mycomm.EOFEnable = False mycomm.Settings = "9600,N,8,1" mycomm.SThreshold = 1 mycomm.InputMode = 0 mycomm.PortOpen = True If mycomm.PortOpen = True Then 'MsgBox ("Port com ouvert") Else MsgBox ("Port com pas ouvert ") End If 'MsgBox (Mycomm.Settings) Stop Buffer = "" Time_start = Time() envoi: DoEvents texte = "" mycomm.Output = Chr$(1) + Chr$(13) + Chr$(10) 'i200_soh 'Mycomm.Output = vbCrLf 'i200_crlf 'MSComm1.Input Text 'Text = "Coucou " + Chr$(13) + Chr$(10) + Text Do While mycomm.OutBufferCount ret = DoEvents() Time_cur = Time() If DateDiff("s", Time_start, Time_cur) > Time_out Then Select Case MsgBox("Impossible de transmettre les données", 34) ' Annuler. Case 3 MsgBox ("Erreur envoi au port com") Exit Sub ' Réessayer. Case 4 Time_start = Time() ' Ignorer. Case 5 Exit Do End Select End If Loop 'Ret = DoEvents() 'mycomm.InputLen = 0 Buffer = mycomm.Input Lgbuffer = Len(Buffer) 'Buffer = "" 'For i = 0 To Mycomm.InputLen ' Buffer = Buffer + Mycomm.Input(i) 'Next i 'lgbuffer = Mycomm.InBufferCount If Lgbuffer = 0 Then Time_cur = Time() If DateDiff("s", Time_start, Time_cur) > Time_out Then MsgBox ("Erreur time out dépassé " + Str(Time_cur) + " / " + Str(Time_start)) Exit Sub End If GoTo envoi Else Do Buffer = Buffer & mycomm.Input Lgbuffer = mycomm.InBufferCount Loop Until Lgbuffer = 0 End If If Not InStr(Buffer, vbCrLf) Then GoTo envoi mycomm.PortOpen = False reponse = texte 'reponse = refart + "/" + reflot + "/" + typepesee + "/" + valpesee + "/" + dsd End Sub
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) lecture_commande = Chr$(1) + Chr$(5) + query_bloc + "L" + Chr$(13) + Chr$(10) 'i200_soh mycomm.Output = lecture_commande Sleep (50) Buffer = mycomm.Input
Set mycomm = CreateObject("MSCommLib.Mscomm")