VEGA VEGACOM 557 VEGA ASCII protocol Manuel d'utilisation
Page 54

54
VEGACOM 557 VEGA ASCII
Mise en service
Private Sub Form_Load()
Dim i As Integer
' Initialiser la mémoire
For i = 1 To 255
Etat (i) = False
PLS(i) = 0
Next i
' Initialiser le compteur d’erreurs
InAction = 0
' Régler la plage
StartIndex = 1
LenIndex = 30
' Afficher les valeurs
DisplayValues
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Stopoer le timer
Timer.Enabled = False
' Fermer l’interface sérielle.
If MSComm.PortOpen = True Then
MSComm.PortOpen = False
End If
End Sub
Private Sub MSComm_OnComm()
Dim InString As String
' ? Les signes ont-ils été reçus
If MSComm.CommEvent = comEvReceive Then
' Affichage pour communication
If Led.FillColor = Me.BackColor Then
Led.FillColor = RGB(0, 255, 0)
Else
Led.FillColor = Me.BackColor
End If
' Vérifier s’il y a des données.
Do While MSComm.InBufferCount > 0
' Compteur d’erreurs sur 1 Sec
InAction = 10
' Lire les donnés.
Call DecodeFrame(MSComm.Input)
Loop
End If
End Sub
Private Sub Run_Click()
' ? Départ ou Stop
If Run.Tag = "0" Then
' ? Interface ouverte
If MSComm.PortOpen = True Then
' -> fermer
MSComm.PortOpen = False
End If
' Déclencher COM1.
MSComm.CommPort = 1
' 9600 Baud, pas de parité, 8 bits de
données et 1 stopbit
MSComm.Settings = "9600,N,8,1"
' Ouvrir l’interface.
MSComm.PortOpen = True
' Lancer le Timer
Timer.Enabled = True
If MSComm.PortOpen Then
' Changer le bouton
Run.Caption = "&Stop"
Run.Tag = "1"
End If
Else
' ? Interface ouverte
If MSComm.PortOpen = True Then
' -> fermer
MSComm.PortOpen = False
End If
' Arrêter le Timer
Timer.Enabled = False
' Changer le bouton
Run.Caption = "&Start"
Run.Tag = "0"
End If
End Sub
Private Sub Timer_Timer()
If InAction = 0 Then
' Effacer la mémoire
ReceiveBuffer = ""
' Effacer l’état
ClearValues
' Sortie de la requête
MSComm.Output = "%" +
Format(StartIndex, "000") + "L" +
Format$(LenIndex, "000") + Chr$(13)
Else
' Utiliser le compteur d’erreurs
InAction = InAction - 1
' ? Limite atteinte
If InAction = 0 Then
' Aficher les valeurs
DisplayValues
End If
End If
End Sub