Code:
Option Explicit
Dim B1, B2, B3, B4, Speed, RPM, CLoad, AFlow, TP, CTemp, ITime, AIT, MPres As Double
Dim MyStrg, MyPos As String
Dim OpenWindows
'RPM code
Private Sub cmdRPM_Click()
Comm1.InBufferCount = 0
Do
OpenWindows = DoEvents()
Loop Until Comm1.Input = "S"
Comm1.Output = "010C07"
Do
OpenWindows = DoEvents()
Loop Until Comm1.InBufferCount >= 15
Text1.Text = Comm1.Input
'set
MyStrg = Text1.Text
'Identify position of V in string
MyPos = InStr(1, MyStrg, "V", 1)
'Select first hexidecimal byte in reply
Text1.SelStart = MyPos + 10
Text1.SelLength = 2
B1 = Text1.SelText
'Select second hexidecimal byte in reply
Text1.SelStart = MyPos + 12
Text1.SelLength = 2
B2 = Text1.SelText
B3 = ("&H" & B1)
B4 = ("&H" & B2)
RPM = (((B3 * 256) + B4) / 4)
RPM = Format(RPM, "0")
'display it
lblRPM.Caption = RPM & " RPM"
End Sub
'AIT code
Private Sub cmdAirPressure_Click()
Comm1.InBufferCount = 0
Do
OpenWindows = DoEvents()
Loop Until Comm1.Input = "S"
Comm1.Output = "010B06"
Do
OpenWindows = DoEvents()
Loop Until Comm1.InBufferCount >= 13
Text1.Text = Comm1.Input
MyStrg = Text1.Text
'Identify position of V in string
MyPos = InStr(1, MyStrg, "V", 1)
'Select first hexidecimal byte in reply
Text1.SelStart = MyPos + 10
Text1.SelLength = 2
B1 = Text1.SelText
'Convert slection into decimal
B3 = ("&H" & B1)
'calulate it
MPres = (B3 * 0.29613)
MPres = Format(MPres, "0.0")
'display it
lblAPres.Caption = MPres
End Sub
Private Sub cmdSpeed_Click()
'Speed Code
Comm1.InBufferCount = 0
Do
OpenWindows = DoEvents()
Loop Until Comm1.Input = "S"
Comm1.Output = "010D06"
Do
OpenWindows = DoEvents()
Loop Until Comm1.InBufferCount >= 13
Text1.Text = Comm1.Input
'set MyStrng to contain reply from scanner
MyStrg = Text1.Text
'Identify position of V in string
MyPos = InStr(1, MyStrg, "V", 1)
'Select first hexidecimal byte in reply
Text1.SelStart = MyPos + 10
Text1.SelLength = 2
B1 = Text1.SelText
'convert selection into decimal
B3 = ("&H" & B1)
'Do calculation for speed
Speed = (B3 * 0.6215)
Speed = Format(Speed, "0.0")
'display it!
lblSpeed.Caption = Speed & " MPH"
End Sub
Private Sub cmdAIT_Click()
Comm1.InBufferCount = 0
Do
OpenWindows = DoEvents()
Loop Until Comm1.Input = "S"
Comm1.Output = "010F06"
Do
OpenWindows = DoEvents()
Loop Until Comm1.InBufferCount >= 13
Text1.Text = Comm1.Input
MyStrg = Text1.Text
'Identify position of V in string
MyPos = InStr(1, MyStrg, "V", 1)
'Select first hexidecimal byte in reply
Text1.SelStart = MyPos + 10
Text1.SelLength = 2
B1 = Text1.SelText
'Convert slection into decimal
B3 = ("&H" & B1)
'calulate it
AIT = (B3 - 40) * 1.8 + 32
AIT = Format(AIT, "0.0")
'display it!
lblAIT.Caption = AIT & " F"
End Sub
Private Sub cmdClose_Click()
If Comm1.PortOpen = False Then
MsgBox "Port already closed"
Else
Comm1.PortOpen = False
End If
End Sub
Private Sub cmdCoolent_Click()
Comm1.InBufferCount = 0
Do
OpenWindows = DoEvents()
Loop Until Comm1.Input = "S"
Comm1.Output = "010506"
Do
OpenWindows = DoEvents()
Loop Until Comm1.InBufferCount >= 13
Text1.Text = Comm1.Input
MyStrg = Text1.Text
'Identify position of V in string
MyPos = InStr(1, MyStrg, "V", 1)
'Select first hexidecimal byte in reply
Text1.SelStart = MyPos + 10
Text1.SelLength = 2
B1 = Text1.SelText
'Convert slection into decimal
B3 = ("&H" & B1)
'calulate it
CTemp = ((B3 - 40) * 1.8 + 32)
CTemp = Format(CTemp, "0")
'display it!
lblCoolent.Caption = CTemp & " F"
End Sub
Private Sub cmdCLoad_Click()
Comm1.InBufferCount = 0
Do
OpenWindows = DoEvents()
Loop Until Comm1.Input = "S"
Comm1.Output = "010406"
Do
OpenWindows = DoEvents()
Loop Until Comm1.InBufferCount >= 13
Text1.Text = Comm1.Input
MyStrg = Text1.Text
'Identify position of V in string
MyPos = InStr(1, MyStrg, "V", 1)
'Select first hexidecimal byte in reply
Text1.SelStart = MyPos + 10
Text1.SelLength = 2
B1 = Text1.SelText
'Convert slection into decimal
B3 = ("&H" & B1)
'calulate it
CLoad = ((B3 / 255) * 100)
CLoad = Format(CLoad, "0")
'display it!
lblengineLoad.Caption = CLoad & " %"
End Sub
Private Sub cmdOpen_Click()
If Comm1.PortOpen = True Then
MsgBox "Port already Open"
Else
Comm1.PortOpen = True
End If
End Sub
Private Sub cmdTP_Click()
Comm1.InBufferCount = 0
Do
OpenWindows = DoEvents()
Loop Until Comm1.Input = "S"
Comm1.Output = "011106"
Do
OpenWindows = DoEvents()
Loop Until Comm1.InBufferCount >= 13
Text1.Text = Comm1.Input
MyStrg = Text1.Text
'Identify position of V in string
MyPos = InStr(1, MyStrg, "V", 1)
'Select first hexidecimal byte in reply
Text1.SelStart = MyPos + 10
Text1.SelLength = 2
B1 = Text1.SelText
'Convert slection into decimal
B3 = ("&H" & B1)
'calulate it
TP = (B3 / 256) * 100
TP = Format(TP, "0")
'output
lblTP.Caption = TP & " %"
End Sub
Bookmarks