VEGA VEGASCAN 850 VEGA-ASCII signal output Manuale d'uso
Pagina 18

18
Uscita del segnale VEGA-ASCII VEGASCAN 850
Esempio di un programma di richiesta VEGASCAN 850
Private Sub Form_Load()
Dim i As Integer
' Inizializzare memoria
For i = 1 To 255
Status(i) = False
PLS(i) = 0
Next i
' Inizializzare conteggio errori
InAction = 0
' Impostare campo
StartIndex = 1
LenIndex = 30
' Indicare valori
DisplayValues
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Timer stoppen
Timer.Enabled = False
' Chiudere interfaccia seriale
If MSComm.PortOpen = True Then
MSComm.PortOpen = False
End If
End Sub
Private Sub MSComm_OnComm()
Dim InString As String
' ? Sono stati recepiti i caratteri
If MSComm.CommEvent = comEvReceive Then
' Indicazione per comunicazione
If Led.FillColor = Me.BackColor Then
Led.FillColor = RGB(0, 255, 0)
Else
Led.FillColor = Me.BackColor
End If
' Controllare se i dati sono disponibili
Do While MSComm.InBufferCount > 0
' Conteggio errori su 1 sec
InAction = 10
' Leggere dati.
Call DecodeFrame(MSComm.Input)
Loop
End If
End Sub
Private Sub Run_Click()
' ? Start oder Stop
If Run.Tag = "0" Then
' ? Interfaccia aperta
If MSComm.PortOpen = True Then
' -> chiudere
MSComm.PortOpen = False
End If
' Utilizzare COM1.
MSComm.CommPort = 1
' 9600 Baud, nessuna parità, 8
bit dinformazione e 1 impulso di
arresto
MSComm.Settings = "9600,N,8,1"
' Aprire interfaccia.
MSComm.PortOpen = True
' Avviare timer
Timer.Enabled = True
If MSComm.PortOpen Then
' Commutare pulsante
Run.Caption = "&Stop"
Run.Tag = "1"
End If
Else
' ? Interfaccia aperta
If MSComm.PortOpen = True Then
' -> chiudere
MSComm.PortOpen = False
End If
' Disinserire timer
Timer.Enabled = False
' Commutare pulsante
Run.Caption = "&Start"
Run.Tag = "0"
End If
End Sub
Private Sub Timer_Timer()
If InAction = 0 Then
' Cancellare memoria
ReceiveBuffer = ""
' Cancellare stato
ClearValues
' Emissione della richiesta
MSComm.Output = "%" +
Format(StartIndex, "000") + "L" +
Format$(LenIndex, "000") + Chr$(13)
Else
' Utilizzare conteggio errori
InAction = InAction - 1
' ? Limite raggiunto
If InAction = 0 Then
' Indicare valori
DisplayValues
End If
End If
End Sub