This is the code of a little programm that makes you able to read measuring block. this little tool communicates directly with atmega in the interface. so in simple, we just need to take this code and implement it in our data logging software and use the bluetooth interface of wbhdiag.. its not so beautiful, but simple
Code: Select all
; This program reads data from a WBH-Diag Pro VAG KW1281 protocol chip
; http://www.blafusel.de/misc/wbhdiagpro.html
Procedure.q Hex2Dec(Hex.s)
Protected result.q, n, temp, pow.q=1
hex=UCase(hex)
For n=MemoryStringLength(@Hex)-1 To 0 Step -1
temp=PeekC(@Hex+n*SizeOf(Character))-48
If temp >= 17 And temp <= 22
temp-7
ElseIf temp < 0 Or temp > 9
Break
EndIf
result+temp*pow
pow*16
Next
ProcedureReturn result
EndProcedure
If OpenWindow(0, 100, 150, 260, 330, "WBH-Diag Pro Demo", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
; Das Fenster wurde erfolgreich geöffnet
If CreateGadgetList(WindowID(0)) ; ermittelt die eindeutige WindowID und erstellt
; auf diesem Fenster die neue Gadgetliste
TextGadget (7, 20, 14, 30, 20, "Port:")
StringGadget (2, 50, 10, 50, 20, "COM17")
TextGadget (8, 120, 14, 40, 20, "Group:")
StringGadget (5, 160, 10, 30, 20, "05")
ButtonGadget (1, 20, 40, 80, 20, "Connect")
ProgressBarGadget (3, 20, 70, 220, 20,0,100)
TextGadget (4, 20, 100, 220, 140, "",#PB_Text_Border)
TextGadget (6, 20,260,220,280, "", #PB_Text_Center)
If LoadFont(0, "Arial", 30)
SetGadgetFont(6, FontID(0)) ; geladenen Arial 16 Zeichensatz als neuen Standard festlegen
EndIf
EndIf
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_Event_Gadget
If EventGadget() = 1
SetGadgetText(4, "")
SetGadgetState(3, 0)
MyCom.s = GetGadgetText(2)+": baud=19200 parity=N Data=8 stop=1"
Hcom.l
Hcom = ComOpen(MyCom,#HandShakeModeNone ,255,255)
If Hcom
Car.s = " "
Ausgabe.s = ""
Repeat ; wait for ID
MyBuffer1.s = "ati" + Chr(13)
ComWrite(Hcom,@MyBuffer1,Len(MyBuffer1)) ;Write the data
Delay (100)
While ComInputBufferCount(HCom) > 0
If ComRead(Hcom,@Car,1)
Ausgabe = Ausgabe + Car
EndIf
Wend
Until FindString(Ausgabe,"WBH-Diag Pro",1)
; MessageRequester("WBH-Diag Pro",Ausgabe)
; try to connect to ECU
MyBuffer1.s = "atd01" + Chr(13) ; send ATDnn
ComWrite(Hcom,@MyBuffer1,Len(MyBuffer1)) ;Write the data
Ausgabe = ""
count.I = 0
While ComInputBufferCount(HCom) = 0
Delay (100)
count = count+1
If count = 101
count=0
EndIf
SetGadgetState(3, count)
Wend
Repeat ; wait for connect data
While ComInputBufferCount(HCom) > 0
If ComRead(Hcom,@Car,1)
Ausgabe = Ausgabe + Car
SetGadgetText(4, GetGadgetText(4)+Car)
EndIf
Wend
Until FindString(Ausgabe,Chr(13)+">",1) ; until ">" and a CR received
SetGadgetText(4, GetGadgetText(4)+Chr(13))
;MessageRequester("WBH-Diag Pro","Data: " + Ausgabe)
Repeat ; endless unitl window close
Delay (100)
If Hcom=False ; maybe connection lost
Hcom = ComOpen(MyCom,#HandShakeModeNone ,255,255)
EndIf
EventID = WindowEvent()
; read group
MyBuffer1.s = "08" + GetGadgetText(5) + Chr(13) ; read group command 08 + which group
ComWrite(Hcom,@MyBuffer1,Len(MyBuffer1)) ;Write the data
Ausgabe = ""
count.I = 0
Repeat ; wait for data
While ComInputBufferCount(HCom) > 0
If ComRead(Hcom,@Car,1)
Ausgabe = Ausgabe + Car
SetGadgetText(4, GetGadgetText(4)+Car)
EndIf
Wend
Until FindString(Ausgabe,Chr(13)+">",1) ; until ">" and a CR received
; find Block 07 (Km/h)
pos.I = FindString(Ausgabe,"07",1) ; search for a block starting with 07 (vehicle speed)
If pos>0
;MessageRequester ("OK", Str(pos))
ByteA.I = Hex2Dec(Mid (Ausgabe, pos+3, 2)) ; next two bytes are the speed data
ByteB.I = Hex2Dec(Mid (Ausgabe, pos+6, 2))
;MessageRequester ("OK", Str(ByteA)+" "+Str(ByteB)+" " +Str(0.01*ByteA*ByteB))
SetGadgetText (6, Str(0.01*ByteA*ByteB)+" km/h") ;calculate speed
SetGadgetText(4, "")
EndIf
Until EventID = #PB_Event_CloseWindow ; endless until window close
ComClose(Hcom)
Else
MessageRequester ("Error", "Error during open "+GetGadgetText(2)+": Port")
EndIf
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Else; Fehler beim Öffnen des Fensters
End
EndIf
End