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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
Dim WithEvents port1 As New SerialPort("COM3", 9600, Parity.None, 8, StopBits.One)
Dim WithEvents port2 As New SerialPort("COM4", 9600, Parity.None, 8, StopBits.One)
Dim WithEvents port3 As New SerialPort("COM5", 9600, Parity.None, 8, StopBits.One)
Dim poidsnetPort1 As Single
Dim poidsnetPort2 As Single
Dim poidsnetport3 As Single
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'GESTION DE LA RECEPTION DES DONNEES VIA LES 3 PORT COM VIRTUELS'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub port1_DataReceived(ByVal sender As Object, ByVal e As _
System.IO.Ports.SerialDataReceivedEventArgs) Handles port1.DataReceived
'Des detection d'une reception sur le port com, on lit tous les caracteres jusqu'a "FIN"
Dim textport1 As String
textport1 = ""
Try
textport1 = port1.ReadTo("FIN")
'Decoupage de la trame reçu et identification de chaque parametres...
'Dim tableau2(11) As String
'tableau2 = textport1.Split(Chr(13) & Chr(10))
textport1 = Replace(textport1, "kg", "")
textport1 = Replace(textport1, "NET", "")
textport1 = Replace(textport1, "(", "")
textport1 = Replace(textport1, ")", "")
textport1 = Replace(textport1, Chr(13) & Chr(10), "")
textport1 = LTrim(textport1)
textport1 = RTrim(textport1)
Catch ex As Exception
MsgBox(ex.Message)
End Try
If Me.InvokeRequired Then
Me.Invoke(New deleg1(AddressOf InsererDansText), textport1)
End If
port1.DiscardInBuffer()
End Sub
Private Sub port2_DataReceived(ByVal sender As Object, ByVal e As _
System.IO.Ports.SerialDataReceivedEventArgs) Handles port2.DataReceived
'Des detection d'une reception sur le port com, on lit tous les caracteres jusqu'a "<>"
Dim textport2 As String
textport2 = ""
Try
textport2 = port2.ReadTo("FIN")
'Decoupage de la trame reçu et identification de chaque parametres...
'Dim tableau2(11) As String
'tableau2 = textport2.Split(Chr(13) & Chr(10))
textport2 = Replace(textport2, "kg", "")
textport2 = Replace(textport2, "NET", "")
textport2 = Replace(textport2, "(", "")
textport2 = Replace(textport2, ")", "")
textport2 = Replace(textport2, Chr(13) & Chr(10), "")
textport2 = LTrim(textport2)
textport2 = RTrim(textport2)
Catch ex As Exception
MsgBox(ex.Message)
End Try
If Me.InvokeRequired Then
Me.Invoke(New deleg2(AddressOf InsererDansText), textport2)
End If
port2.DiscardInBuffer()
End Sub
Private Sub port3_DataReceived(ByVal sender As Object, ByVal e As _
System.IO.Ports.SerialDataReceivedEventArgs) Handles port3.DataReceived
'Des detection d'une reception sur le port com, on lit tous les caracteres jusqu'a "<>"
Dim textport3 As String
textport3 = ""
Try
textport3 = port3.ReadTo("FIN")
' MsgBox(textport3)
'Decoupage de la trame reçu et identification de chaque parametres...
'Dim tableau2(11) As String
'tableau2 = textport3.Split(Chr(13) & Chr(10))
textport3 = Replace(textport3, "kg", "")
textport3 = Replace(textport3, "NET", "")
textport3 = Replace(textport3, "(", "")
textport3 = Replace(textport3, ")", "")
textport3 = Replace(textport3, Chr(13) & Chr(10), "")
textport3 = LTrim(textport3)
textport3 = RTrim(textport3)
Catch ex As Exception
MsgBox(ex.Message)
End Try
If Me.InvokeRequired Then
Me.Invoke(New deleg3(AddressOf InsererDansText), textport3)
End If
port3.DiscardInBuffer()
End Sub |
Partager