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
| 'Gestion des ports com pour les douchettes
Public WithEvents portCom As New System.IO.Ports.SerialPort
Public Function Init_douchettes(ByVal strPort As String) As Boolean
Try
'Si le nom est vide -> pas d'ouverture
If strPort <> "" Then
If Me.portCom.IsOpen = False Then
'Init des parametres
portCom.BaudRate = 38400
portCom.Parity = IO.Ports.Parity.None
portCom.Handshake = IO.Ports.Handshake.None
portCom.StopBits = IO.Ports.StopBits.One
portCom.PortName = strPort
'Initialise le buffer
portCom.DiscardNull = True
'Ouverture
portCom.Open()
End If
End If
Catch ex As Exception
MsgBox("Erreur dans la configuration de la douchette." & vbCrLf & ex.Message)
End Try
End Function
'Gestion reception code barre douchette
Public Sub Reception_Data(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles portCom.DataReceived
Dim strTmp As String = ""
Try
If portCom.ReadBufferSize > 0 Then
'Recupere les donnees
strTmp = portCom.ReadExisting
'Vide le buffer
portCom.DiscardInBuffer()
'Affichage de la trame reçu
TextBox1.Invoke(New AfficheDataReadDeleg(AddressOf AfficheDataRead), New Object() {strTmp})
End If
Catch ex As Exception
MsgBox("Erreur durant la réception" & vbCrLf & vbCrLf & ex.ToString)
End Try
End Sub
'Création d'une délégation pour gestion des threads pour l'affichage
Delegate Sub AfficheDataReadDeleg(ByVal StrTmp As String)
'affichage de la trame reçu
Public Sub AfficheDataRead(ByVal StrTmp As String)
TextBox1.Text = StrTmp
End Sub |