OBD-2 visual basic program to Pbasic
Robban
Posts: 124
Hi
Found this program on the net and now i wonder if it is possible to convert it to Pbasic?
It´s a program that reads speed and rpm from a car computer (OBD-2)
'RPM code 010C
Private Sub cmdRPM_Click()
MyStrg = ""
MSComm1.Output = "010C" & vbCr
··· MyStrg = MSComm1.Input
··· Text1.Text = MyStrg
··· Temp = Mid(MyStrg, 15, 3)
··· If InStr(1, Temp, ">") <> 0 Then
··· 'If Mid(MyStrg, 15, 3) = ">" Then
··· B1 = Mid(MyStrg, 7, 2)
··· B2 = Mid(MyStrg, 10, 2)
···
··· B3 = ("&H" & B1) 'Convert to Hex
··· B4 = ("&H" & B2)
··· RPM = (((B3 * 256) + B4) / 4)
··· RPM = Format(RPM, "0")
··· lblRPM.Caption = RPM & " RPM" 'Output RPM
··· Else
··· 'Do nothing
··· End If
End Sub
Private Sub cmdSpeed_Click()
'Speed Code
MyStrg = ""
MSComm1.Output = "010D" & vbCr
MyStrg = MSComm1.Input
··· Text1.Text = MyStrg
··· Temp = Mid(MyStrg, 12, 3)
··· If InStr(1, Temp, ">") <> 0 Then
··· 'If Mid(MyStrg, 12, 1) = ">" Then
··· B1 = Mid(MyStrg, 7, 2)
'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"
Else
'Do nothing
End If
End Sub
Found this program on the net and now i wonder if it is possible to convert it to Pbasic?
It´s a program that reads speed and rpm from a car computer (OBD-2)
'RPM code 010C
Private Sub cmdRPM_Click()
MyStrg = ""
MSComm1.Output = "010C" & vbCr
··· MyStrg = MSComm1.Input
··· Text1.Text = MyStrg
··· Temp = Mid(MyStrg, 15, 3)
··· If InStr(1, Temp, ">") <> 0 Then
··· 'If Mid(MyStrg, 15, 3) = ">" Then
··· B1 = Mid(MyStrg, 7, 2)
··· B2 = Mid(MyStrg, 10, 2)
···
··· B3 = ("&H" & B1) 'Convert to Hex
··· B4 = ("&H" & B2)
··· RPM = (((B3 * 256) + B4) / 4)
··· RPM = Format(RPM, "0")
··· lblRPM.Caption = RPM & " RPM" 'Output RPM
··· Else
··· 'Do nothing
··· End If
End Sub
Private Sub cmdSpeed_Click()
'Speed Code
MyStrg = ""
MSComm1.Output = "010D" & vbCr
MyStrg = MSComm1.Input
··· Text1.Text = MyStrg
··· Temp = Mid(MyStrg, 12, 3)
··· If InStr(1, Temp, ">") <> 0 Then
··· 'If Mid(MyStrg, 12, 1) = ">" Then
··· B1 = Mid(MyStrg, 7, 2)
'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"
Else
'Do nothing
End If
End Sub
Comments
At second look, it appears you're getting a few serial bytes from the OBD computer, then parsing them into something that can be displayed. And yes, the BS2 can easily do the few bytes you're looking for.
Confusing for sure, since there is both a Prop-1 board:
http://www.efx-tek.com/topics/prop-1.html
and the new Propeller chip - both products which come or came from Parallax development resources. This is the Propeller chip which I suspect is what he's speaking about:
http://www.parallax.com/propeller/index.asp
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->