fork(2) download
  1. Public Class KWP2000_data_mobitor
  2.  
  3. 'KWP2000 datamonitor for Hayabusa by PetriK
  4. 'Copyright (C) 2009, MacMadigan Oy, PetriK
  5.  
  6. 'This program is free software: you can redistribute it and/or modify
  7. 'it under the terms of the GNU General Public License as published by
  8. 'the Free Software Foundation, either version 3 of the License, or
  9. '(at your option) any later version.
  10.  
  11. 'This program is distributed in the hope that it will be useful,
  12. 'but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. 'GNU General Public License for more details.
  15.  
  16. 'GNU General Public License can be found at: http://w...content-available-to-author-only...u.org/licenses/
  17.  
  18. Public Declare Function FT_SetBreakOn Lib "FTD2XX.DLL" (ByVal lnghandle As Integer) As Integer
  19. Public Declare Function FT_SetBreakOff Lib "FTD2XX.DLL" (ByVal lnghandle As Integer) As Integer
  20. Public Declare Function FT_Open Lib "FTD2XX.DLL" (ByVal iDevice As Integer, ByRef lnghandle As Integer) As Integer
  21. Public Declare Function FT_GetNumberOfDevices Lib "FTD2XX.DLL" Alias "FT_ListDevices" (ByRef lngNumberofdevices As Integer, ByVal pvarg2 As String, ByVal lngflags As Integer) As Integer
  22. Public Declare Function FT_ListDevices Lib "FTD2XX.DLL" (ByRef lngNumberofdevices As Integer, ByVal pvarg2 As String, ByVal lngflags As Integer) As Integer
  23. Public Declare Function FT_Close Lib "FTD2XX.DLL" (ByVal lnghandle As Integer) As Integer
  24. Public Declare Function FT_GetComPortNumber Lib "FTD2XX.DLL" (ByVal lnghandle As Integer, ByRef portnumber As Integer) As Integer
  25. Public Declare Function FT_SetBaudRate Lib "FTD2XX.DLL" (ByVal lngHandle As Integer, ByVal lngBaudRate As Integer) As Integer
  26. Public Declare Function FT_Write_Bytes Lib "FTD2XX.DLL" Alias "FT_Write" (ByVal lngHandle As Integer, ByRef lpvBuffer As Byte, ByVal lngBufferSize As Integer, ByRef lngBytesWritten As Integer) As Integer
  27. Public Declare Function FT_Read_Bytes Lib "FTD2XX.DLL" Alias "FT_Read" (ByVal lngHandle As Integer, ByRef lpvBuffer As Byte, ByVal lngBufferSize As Integer, ByRef lngBytesReturned As Integer) As Integer
  28. Public Declare Function FT_GetStatus Lib "FTD2XX.DLL" (ByVal lngHandle As Integer, ByRef lngamountInRxQueue As Integer, ByRef lngAmountInTxQueue As Integer, ByRef lngEventStatus As Integer) As Integer
  29.  
  30. Public lngHandle As Integer
  31. Public comportnum As Integer
  32. Public rxbyte As Byte
  33. Public ticking As Integer
  34. Public FT_status As Integer
  35. Public rxqueue, txqueue, eventstat As Integer
  36. Public rxsptr As Integer
  37. Public rxs(128) As Byte
  38.  
  39. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  40. '
  41. ' Initialize the program, input for everything is serialport.portname
  42. '
  43.  
  44. serialport.PortName = "COM5" ' this will be used for FTDI device handle, important to have correct value here
  45.  
  46. TextBox1.Text = "Program started... "
  47. comportnum = Val(Mid$(serialport.PortName, 4)) ' com port address
  48. If ((comportnum < 0) Or (comportnum > 8)) Then MsgBox("USB FTDI COMport is non existing or out of range, program may not work")
  49. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & "Using comport =" & comportnum
  50. Timer1.Enabled = False
  51. Timer1.Interval = 250
  52. Button1.Enabled = True
  53. ListBox1.SelectedIndex = 1
  54.  
  55. End Sub
  56.  
  57. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  58. '
  59. ' Connect to ecu
  60. '
  61. Dim i, x, y As Integer
  62. Dim txbyte As Byte
  63. Dim bytecount As Integer
  64.  
  65.  
  66. '
  67. ' Initialize required values
  68. '
  69. Button1.Enabled = False ' do not allow port reopened while monitoring data
  70. '
  71. ' Get the FTDI device handle based on com port number
  72. '
  73. FT_status = FT_GetNumberOfDevices(i, 0, &H80000000)
  74. If FT_status <> 0 Then MsgBox("Can not get number of FTDI devices, error:" & FT_status)
  75. TextBox1.Text = "Number of FTDI devices connected =" & i
  76. i = i - 1
  77. For x = 0 To i
  78. FT_status = FT_Open(i, lngHandle) ' only one
  79. If FT_status <> 0 Then MsgBox("Can not open FTDI USB device, error:" & FT_status)
  80. FT_status = FT_GetComPortNumber(lngHandle, y)
  81. If FT_status <> 0 Then MsgBox("Can not get FTDI com port number, error:" & FT_status)
  82. If y = comportnum Then x = i
  83. Next
  84. If FT_status <> 0 Then MsgBox("Can not open FTDI USB device, error:" & FT_status)
  85. FT_status = FT_SetBaudRate(lngHandle, 10400)
  86. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & "FTDI USB device opened for 10400 baud, id=" & i & ", port=" & comportnum
  87. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & "Initiating 5baud fast initialization"
  88. i = Val(ListBox1.Text)
  89.  
  90. ticking = 0
  91. '
  92. ' 5 Baud Init using FTDI usb driver
  93. '
  94. System.Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.Highest
  95. FT_status = FT_SetBreakOff(lngHandle) ' K-line high
  96. System.Threading.Thread.Sleep(300)
  97. FT_status = FT_SetBreakOn(lngHandle) ' K-line low
  98. System.Threading.Thread.Sleep(i)
  99. FT_status = FT_SetBreakOff(lngHandle) ' K-line high
  100. System.Threading.Thread.Sleep(i)
  101. '
  102. ' Capture &H00 from ECU
  103. '
  104. System.Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.Normal
  105. rxbyte = &HFF
  106. bytecount = 0
  107. While (ticking < 100) And (rxbyte <> 0) And (bytecount = 0)
  108. ticking = ticking + 1
  109. FT_status = FT_Read_Bytes(lngHandle, rxbyte, 1, bytecount)
  110. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & "Captured &H00 from ECU" & " using " & i & "ms"
  111. i = 25 ' break the for next loop when &H00 found
  112. End While
  113.  
  114. '
  115. ' Send init request to ecu if &H00 read succesfully
  116. '
  117. If ticking < 100 Then
  118. txbyte = &H81
  119. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  120. txbyte = &H12
  121. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  122. txbyte = &HF1
  123. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  124. txbyte = &H81
  125. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  126. txbyte = &H5
  127. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  128. '
  129. ' Pass control timer to read bytes continously
  130. '
  131. Timer1.Enabled = True
  132. ticking = 0
  133. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & "Completed 5baud fast initialization" & Chr(13) & Chr(10)
  134. Else
  135. Timer1.Enabled = False
  136. ticking = 0
  137. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & "Failed 5baud initialization" & Chr(13) & Chr(10)
  138. End If
  139.  
  140.  
  141. End Sub
  142.  
  143. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  144. '
  145. ' first send close connection to ecu and then close comms port
  146. '
  147. FT_status = FT_GetStatus(lngHandle, rxqueue, txqueue, eventstat)
  148. If FT_status = 0 Then
  149. '
  150. ' add here code to send close connection to ecu before closing the comport
  151. '
  152. Timer1.Enabled = False
  153. Button1.Enabled = True
  154. ticking = 0
  155. FT_status = FT_Close(lngHandle)
  156. End If
  157.  
  158. End Sub
  159.  
  160. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  161. Dim i As Integer
  162. Dim txbyte As Byte
  163.  
  164. '
  165. ' This timer is used to read any bytes after initialization sequence
  166. '
  167. FT_status = FT_GetStatus(lngHandle, rxqueue, txqueue, eventstat)
  168.  
  169. If FT_status = 0 And rxqueue > 0 Then
  170. For i = 1 To rxqueue
  171. FT_Read_Bytes(lngHandle, rxbyte, 1, 1)
  172. rxs(rxsptr) = rxbyte
  173. rxsptr = rxsptr + 1
  174. TextBox1.Text = TextBox1.Text & Format(rxbyte, "x2") & " "
  175. Next
  176. ticking = 0
  177. End If
  178.  
  179. ticking = ticking + 1
  180. '
  181. ' It is time ask sensor data from ECU
  182. '
  183. txbyte = &H80
  184. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  185. txbyte = &H12
  186. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  187. txbyte = &HF1
  188. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  189. txbyte = &H2
  190. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  191. txbyte = &H21
  192. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  193. txbyte = &H8
  194. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  195. txbyte = &HAE
  196. FT_Write_Bytes(lngHandle, txbyte, 1, 1)
  197. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10)
  198. rxsptr = 0
  199. For x = 0 To 50
  200. Select Case x
  201. Case 26
  202. L_TPS.Text = Format(rxs(x), "000")
  203. Case 27
  204. L_IAP.Text = Format(rxs(x), "000")
  205. Case 28
  206. L_CLT.Text = Format(rxs(x), "000")
  207. End Select
  208. Next
  209. '
  210. ' No response from the line for a while, lets kill the comms
  211. '
  212. If ticking > 100 Then
  213. Timer1.Enabled = False
  214. Button1.Enabled = True
  215. ticking = 0
  216. rxsptr = 0
  217. FT_status = FT_Close(lngHandle)
  218. TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & "No traffic, killing listening process"
  219. End If
  220. End Sub
  221.  
  222. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  223. TextBox1.Text = ""
  224. End Sub
  225.  
  226. End Class
  227.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Visual Basic.Net Compiler version 0.0.0.5914 (Mono 2.4.2 - r)
Copyright (C) 2004-2008 Rolf Bjarne Kvinge. All rights reserved.


/home/CflKz8/prog.vb (39,102) : Error VBNC30590: Cannot find the event 'Load'.
/home/CflKz8/prog.vb (44,20) : Error VBNC30451: Could not resolve the name 'serialport'
/home/CflKz8/prog.vb (46,18) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (47,42) : Error VBNC30451: Could not resolve the name 'serialport'
/home/CflKz8/prog.vb (49,18) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (49,33) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (50,16) : Error VBNC30451: Could not resolve the name 'Timer1'
/home/CflKz8/prog.vb (51,16) : Error VBNC30451: Could not resolve the name 'Timer1'
/home/CflKz8/prog.vb (52,17) : Error VBNC30451: Could not resolve the name 'Button1'
/home/CflKz8/prog.vb (53,18) : Error VBNC30451: Could not resolve the name 'ListBox1'
/home/CflKz8/prog.vb (57,107) : Error VBNC30451: Could not resolve the name 'Button1'
/home/CflKz8/prog.vb (69,17) : Error VBNC30451: Could not resolve the name 'Button1'
/home/CflKz8/prog.vb (75,18) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (86,18) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (86,33) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (87,18) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (87,33) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (88,26) : Error VBNC30451: Could not resolve the name 'ListBox1'
/home/CflKz8/prog.vb (110,22) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (110,37) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (131,20) : Error VBNC30451: Could not resolve the name 'Timer1'
/home/CflKz8/prog.vb (133,22) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (133,37) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (135,20) : Error VBNC30451: Could not resolve the name 'Timer1'
/home/CflKz8/prog.vb (137,22) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (137,37) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (143,107) : Error VBNC30451: Could not resolve the name 'Button2'
/home/CflKz8/prog.vb (152,20) : Error VBNC30451: Could not resolve the name 'Timer1'
/home/CflKz8/prog.vb (153,21) : Error VBNC30451: Could not resolve the name 'Button1'
/home/CflKz8/prog.vb (160,104) : Error VBNC30451: Could not resolve the name 'Timer1'
/home/CflKz8/prog.vb (174,26) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (174,41) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (197,18) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (197,33) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (199,16) : Error VBNC30451: Could not resolve the name 'x'
/home/CflKz8/prog.vb (213,20) : Error VBNC30451: Could not resolve the name 'Timer1'
/home/CflKz8/prog.vb (214,21) : Error VBNC30451: Could not resolve the name 'Button1'
/home/CflKz8/prog.vb (218,22) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (218,37) : Error VBNC30451: Could not resolve the name 'TextBox1'
/home/CflKz8/prog.vb (222,107) : Error VBNC30451: Could not resolve the name 'Button4'
/home/CflKz8/prog.vb (223,18) : Error VBNC30451: Could not resolve the name 'TextBox1'
There were 41 errors and 0 warnings.
Compilation took 00:00:01.0543040
stdout
Standard output is empty