Public feed
#601411
Sub mainloop()
Dim sendcmd() As Char = {Chr(153), Chr(3), Chr(192), Chr(54), Chr(0), Chr(2), Chr(4), Chr(29), Chr(10)}
Dim sw As New Stopwatch
Dim deleg As updatelabel
Dim c As Long = 0
Try
sp.Open()
deleg = New updatelabel(AddressOf updatelbl)
Do Until st = True Or sp.IsOpen = False
sendcomplete=false
while not SendComplete
sw.Start()
sp.Write(sendcmd)
Do Until sp.BytesToRead >= 16 Or st = True Or sw.ElapsedMilliseconds > 99
System.Threading.Thread.Sleep(delay)
Loop
if sp.BytesToRead>=16 then
sendcomplete=true
else
sw.stop
endif
end while
Try
If sp.BytesToRead = 0 Then
End If
Dim intnumbytes As Integer = sp.BytesToRead
Dim bytCharData(intnumbytes - 1) As Byte
sp.Read(bytCharData, 0, intnumbytes)
sw.Stop()
sw.Reset()
Dim v1 As Integer = (bytCharData(14) And &HF) * 256
Dim v2 As Integer = bytCharData(15) + v1
c = c + 1
Me.Invoke(deleg, New Object() {v2, bytCharData(14), bytCharData(15), c})
Catch invopex As InvalidOperationException
mainloop()
Catch outofrangeex As IndexOutOfRangeException
MessageBox.Show("Please ensure the device is connected and there is no interference")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Loop
Catch ioex As System.InvalidOperationException
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub