创新can调试器Linux版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

591 lines
17 KiB

4 years ago
  1. VERSION 5.00
  2. Begin VB.Form Form1
  3. Caption = "USB_CAN Demo(��о�����Ƽ����޹�˾)"
  4. ClientHeight = 6480
  5. ClientLeft = 7155
  6. ClientTop = 2280
  7. ClientWidth = 9420
  8. LinkTopic = "Form1"
  9. ScaleHeight = 6480
  10. ScaleWidth = 9420
  11. Begin VB.CommandButton Command4
  12. Caption = "Clear List"
  13. Height = 375
  14. Left = 7920
  15. TabIndex = 34
  16. Top = 3480
  17. Width = 1335
  18. End
  19. Begin VB.ComboBox Combo2
  20. Height = 300
  21. ItemData = "Form1.frx":0000
  22. Left = 4920
  23. List = "Form1.frx":000A
  24. Style = 2 'Dropdown List
  25. TabIndex = 19
  26. Top = 600
  27. Width = 1185
  28. End
  29. Begin VB.TextBox Text1
  30. Height = 285
  31. Left = 6120
  32. TabIndex = 18
  33. Text = "00000080"
  34. Top = 2880
  35. Width = 975
  36. End
  37. Begin VB.Timer Timer1
  38. Interval = 10
  39. Left = 7920
  40. Top = 480
  41. End
  42. Begin VB.TextBox Text4
  43. Height = 285
  44. Left = 720
  45. TabIndex = 15
  46. Text = "01 02 03 04 05 06 07 08 "
  47. Top = 3360
  48. Width = 2415
  49. End
  50. Begin VB.ComboBox Combo5
  51. Height = 300
  52. ItemData = "Form1.frx":0022
  53. Left = 3600
  54. List = "Form1.frx":002C
  55. Style = 2 'Dropdown List
  56. TabIndex = 14
  57. Top = 2805
  58. Width = 1695
  59. End
  60. Begin VB.ComboBox Combo4
  61. Height = 300
  62. ItemData = "Form1.frx":004A
  63. Left = 960
  64. List = "Form1.frx":0054
  65. Style = 2 'Dropdown List
  66. TabIndex = 13
  67. Top = 2820
  68. Width = 1815
  69. End
  70. Begin VB.CommandButton Command3
  71. Caption = "Reset CAN"
  72. Height = 330
  73. Left = 7920
  74. TabIndex = 12
  75. Top = 3120
  76. Width = 1245
  77. End
  78. Begin VB.CommandButton Command2
  79. Caption = "Start CAN"
  80. Height = 330
  81. Left = 7920
  82. TabIndex = 11
  83. Top = 2640
  84. Width = 1125
  85. End
  86. Begin VB.ComboBox Combo1
  87. Height = 300
  88. ItemData = "Form1.frx":0078
  89. Left = 1680
  90. List = "Form1.frx":0082
  91. Style = 2 'Dropdown List
  92. TabIndex = 10
  93. Top = 480
  94. Width = 1290
  95. End
  96. Begin VB.CommandButton Connect
  97. Caption = "Connection"
  98. Height = 330
  99. Left = 6360
  100. TabIndex = 1
  101. Top = 480
  102. Width = 1485
  103. End
  104. Begin VB.Frame Frame1
  105. Caption = "Transmitting data frames"
  106. Height = 1230
  107. Left = 120
  108. TabIndex = 0
  109. Top = 2520
  110. Width = 7635
  111. Begin VB.CommandButton Command1
  112. Caption = "Send"
  113. Height = 330
  114. Left = 6600
  115. TabIndex = 6
  116. Top = 720
  117. Width = 870
  118. End
  119. Begin VB.Label Label3
  120. Caption = "Type��"
  121. Height = 240
  122. Left = 120
  123. TabIndex = 33
  124. Top = 360
  125. Width = 960
  126. End
  127. Begin VB.Label Label7
  128. Caption = "Data��"
  129. Height = 240
  130. Left = 120
  131. TabIndex = 5
  132. Top = 840
  133. Width = 555
  134. End
  135. Begin VB.Label Label6
  136. Caption = "ID��"
  137. Height = 195
  138. Left = 5280
  139. TabIndex = 4
  140. Top = 360
  141. Width = 585
  142. End
  143. Begin VB.Label Label5
  144. Caption = "Format��"
  145. Height = 195
  146. Left = 2760
  147. TabIndex = 3
  148. Top = 360
  149. Width = 765
  150. End
  151. Begin VB.Label Label4
  152. Caption = "֡���ͣ�"
  153. Height = 195
  154. Left = 120
  155. TabIndex = 2
  156. Top = 360
  157. Width = 810
  158. End
  159. End
  160. Begin VB.Frame Frame2
  161. Caption = "Device Parameters"
  162. Height = 2295
  163. Left = 120
  164. TabIndex = 7
  165. Top = 120
  166. Width = 8895
  167. Begin VB.Frame Frame3
  168. Caption = "CAN initialization parameters"
  169. Height = 1335
  170. Left = 120
  171. TabIndex = 20
  172. Top = 840
  173. Width = 8415
  174. Begin VB.ComboBox Combo7
  175. Height = 300
  176. ItemData = "Form1.frx":0099
  177. Left = 6360
  178. List = "Form1.frx":00A6
  179. Style = 2 'Dropdown List
  180. TabIndex = 32
  181. Top = 720
  182. Width = 2055
  183. End
  184. Begin VB.ComboBox Combo6
  185. Height = 300
  186. ItemData = "Form1.frx":00D9
  187. Left = 6360
  188. List = "Form1.frx":00E6
  189. Style = 2 'Dropdown List
  190. TabIndex = 30
  191. Top = 360
  192. Width = 1935
  193. End
  194. Begin VB.TextBox Text6
  195. Height = 285
  196. Left = 3720
  197. TabIndex = 28
  198. Text = "14"
  199. Top = 840
  200. Width = 1095
  201. End
  202. Begin VB.TextBox Text5
  203. Height = 285
  204. Left = 1200
  205. TabIndex = 26
  206. Text = "00"
  207. Top = 840
  208. Width = 855
  209. End
  210. Begin VB.TextBox Text3
  211. Height = 285
  212. Left = 3720
  213. TabIndex = 24
  214. Text = "FFFFFFFF"
  215. Top = 360
  216. Width = 1095
  217. End
  218. Begin VB.TextBox Text2
  219. Height = 285
  220. Left = 1200
  221. TabIndex = 22
  222. Text = "00000000"
  223. Top = 360
  224. Width = 855
  225. End
  226. Begin VB.Label Label13
  227. Caption = "Mode��"
  228. Height = 255
  229. Left = 5640
  230. TabIndex = 31
  231. Top = 720
  232. Width = 615
  233. End
  234. Begin VB.Label Label12
  235. Caption = "Filter methods��"
  236. Height = 255
  237. Left = 4800
  238. TabIndex = 29
  239. Top = 405
  240. Width = 1575
  241. End
  242. Begin VB.Label Label11
  243. Caption = "Timer1��0x"
  244. Height = 255
  245. Left = 2280
  246. TabIndex = 27
  247. Top = 840
  248. Width = 975
  249. End
  250. Begin VB.Label Label8
  251. Caption = "Timer0:0x"
  252. Height = 255
  253. Left = 120
  254. TabIndex = 25
  255. Top = 840
  256. Width = 975
  257. End
  258. Begin VB.Label Label2
  259. Caption = "MASK code:0x"
  260. Height = 255
  261. Left = 2400
  262. TabIndex = 23
  263. Top = 360
  264. Width = 1335
  265. End
  266. Begin VB.Label Label1
  267. Caption = "ACC code��0x"
  268. Height = 255
  269. Left = 120
  270. TabIndex = 21
  271. Top = 360
  272. Width = 1095
  273. End
  274. End
  275. Begin VB.Label Label10
  276. Caption = "CAN channels"
  277. Height = 255
  278. Left = 3360
  279. TabIndex = 9
  280. Top = 360
  281. Width = 1095
  282. End
  283. Begin VB.Label Label9
  284. Caption = "Device Type"
  285. Height = 255
  286. Left = 240
  287. TabIndex = 8
  288. Top = 360
  289. Width = 1095
  290. End
  291. End
  292. Begin VB.Frame Frame6
  293. Caption = "List"
  294. Height = 2535
  295. Left = 0
  296. TabIndex = 16
  297. Top = 3840
  298. Width = 9255
  299. Begin VB.ListBox List1
  300. Height = 2040
  301. Left = 120
  302. TabIndex = 17
  303. Top = 240
  304. Width = 8895
  305. End
  306. End
  307. End
  308. Attribute VB_Name = "Form1"
  309. Attribute VB_GlobalNameSpace = False
  310. Attribute VB_Creatable = False
  311. Attribute VB_PredeclaredId = True
  312. Attribute VB_Exposed = False
  313. Dim m_devtype As Long
  314. Dim m_connect As Byte
  315. Dim m_cannum As Long
  316. Dim m_bRun As Boolean
  317. Public Function EnableUI(bEnable As Boolean)
  318. Label1.Enabled = bEnable
  319. Label2.Enabled = bEnable
  320. Label12.Enabled = bEnable
  321. Label8.Enabled = bEnable
  322. Label11.Enabled = bEnable
  323. Label13.Enabled = bEnable
  324. Text2.Enabled = bEnable
  325. Text3.Enabled = bEnable
  326. Text5.Enabled = bEnable
  327. Text6.Enabled = bEnable
  328. Combo1.Enabled = bEnable
  329. Combo2.Enabled = bEnable
  330. Combo6.Enabled = bEnable
  331. Combo7.Enabled = bEnable
  332. End Function
  333. Private Sub Command1_Click()
  334. If m_connect = 0 Then
  335. MsgBox ("Please open the port first")
  336. Exit Sub
  337. End If
  338. Dim SendType, frameformat, frametype As Byte
  339. Dim ID As Long
  340. Dim data(7) As Byte
  341. Dim frameinfo As VCI_CAN_OBJ
  342. Dim str, tmpstr As String
  343. SendType = 0
  344. frameformat = Combo5.ListIndex
  345. frametype = Combo4.ListIndex
  346. str = "&H"
  347. str = str + Text1.Text
  348. ID = Val(str)
  349. str = Text4.Text
  350. strdata = " "
  351. i = 0
  352. For i = 0 To 7
  353. strdata = Left(str, 2)
  354. If Len(strdata) = 0 Then
  355. Exit For
  356. End If
  357. str = Right(str, Len(str) - 3)
  358. data(i) = Val("&H" + strdata)
  359. Next
  360. frameinfo.DataLen = i
  361. frameinfo.ExternFlag = frametype
  362. frameinfo.RemoteFlag = frameformat
  363. frameinfo.ID = ID
  364. For j = 0 To i - 1
  365. frameinfo.data(j) = data(j)
  366. Next
  367. If VCI_Transmit(m_devtype, 0, m_cannum, frameinfo, 1) <> 1 Then
  368. MsgBox ("Failed to send data")
  369. Else
  370. str = "Successful sending of data: "
  371. tmpstr = "Time Mark: None "
  372. str = str + tmpstr
  373. tmpstr = " ID:0x" + Hex(frameinfo.ID)
  374. str = str + tmpstr
  375. str = str + " Type:"
  376. If frameinfo.RemoteFlag = 0 Then
  377. tmpstr = "data frame "
  378. Else
  379. tmpstr = "Remote Frame "
  380. End If
  381. str = str + tmpstr
  382. str = str + " Format:"
  383. If frameinfo.ExternFlag = 0 Then
  384. tmpstr = "Standard frame "
  385. Else
  386. tmpstr = "Extended frame "
  387. End If
  388. str = str + tmpstr
  389. List1.AddItem str, List1.ListCount
  390. If frameinfo.RemoteFlag = 0 Then
  391. str = " data:"
  392. If frameinfo.DataLen > 8 Then
  393. frameinfo.DataLen = 8
  394. End If
  395. For j = 0 To frameinfo.DataLen - 1
  396. tmpstr = Hex(frameinfo.data(j)) + " "
  397. str = str + tmpstr
  398. Next
  399. List1.AddItem str, List1.ListCount
  400. End If
  401. List1.ListIndex = List1.ListCount - 1
  402. End If
  403. List1.ListIndex = List1.ListCount - 1
  404. End Sub
  405. Private Sub Command2_Click()
  406. If m_connect = 0 Then
  407. MsgBox ("Please open the port first")
  408. Exit Sub
  409. End If
  410. If VCI_StartCAN(m_devtype, 0, m_cannum) <> 1 Then
  411. MsgBox ("Start CAN Error")
  412. Else
  413. List1.AddItem "Start CAN Successfully", List1.ListCount
  414. Command1.Enabled = True
  415. End If
  416. End Sub
  417. Private Sub Command3_Click()
  418. If m_connect = 0 Then
  419. MsgBox ("Please open the port first")
  420. Exit Sub
  421. End If
  422. If VCI_ResetCAN(m_devtype, 0, m_cannum) <> 1 Then
  423. MsgBox ("Reset CAN error")
  424. Else
  425. List1.AddItem "Reset CAN Successfully", List1.ListCount
  426. Command1.Enabled = False
  427. End If
  428. End Sub
  429. Private Sub Command4_Click()
  430. Dim i As Integer
  431. For i = 0 To List1.ListCount - 1
  432. List1.RemoveItem 0
  433. Next
  434. End Sub
  435. Private Sub Connect_Click()
  436. Dim cannum As Long
  437. Dim code, mask As Long
  438. Dim Timing0, Timing1, filtertype, Mode As Byte
  439. Dim InitConfig As VCI_INIT_CONFIG
  440. If m_connect = 1 Then
  441. m_connect = 0
  442. Connect.Caption = "Connect"
  443. VCI_CloseDevice m_devtype, 0
  444. EnableUI True
  445. Exit Sub
  446. End If
  447. If Combo1.ListIndex <> -1 And Combo2.ListIndex <> -1 Then
  448. cannum = Combo2.ListIndex
  449. filtertype = Combo6.ListIndex + 1
  450. Mode = Combo7.ListIndex
  451. code = Val("&H" + Text2.Text)
  452. mask = Val("&H" + Text3.Text)
  453. Timing0 = Val("&H" + Text5.Text)
  454. Timing1 = Val("&H" + Text6.Text)
  455. InitConfig.AccCode = code
  456. InitConfig.AccMask = mask
  457. InitConfig.Filter = filtertype
  458. InitConfig.Mode = Mode
  459. InitConfig.Timing0 = Timing0
  460. InitConfig.Timing1 = Timing1
  461. If VCI_OpenDevice(m_devtype, 0, 0) <> 1 Then
  462. MsgBox ("Error opening device")
  463. Else
  464. If VCI_InitCAN(m_devtype, 0, cannum, InitConfig) = 1 Then
  465. m_connect = 1
  466. m_cannum = cannum
  467. Connect.Caption = "Disconnect"
  468. Else
  469. MsgBox ("Initialization CAN error")
  470. End If
  471. End If
  472. End If
  473. EnableUI False
  474. End Sub
  475. Private Sub Form_Activate()
  476. m_bRun = True
  477. End Sub
  478. Private Sub Form_Load()
  479. Me.Left = (Screen.Width - Me.Width) / 2
  480. Me.Top = (Screen.Height - Me.Height) / 2
  481. m_bRun = False
  482. m_devtype = 4 'USB_CAN2���ͺ�
  483. m_connect = 0
  484. m_cannum = 0
  485. Combo1.ListIndex = 1
  486. Combo2.ListIndex = 0
  487. Combo4.ListIndex = 0
  488. Combo5.ListIndex = 0
  489. Combo6.ListIndex = 0
  490. Combo7.ListIndex = 0
  491. EnableUI True
  492. Command1.Enabled = False
  493. End Sub
  494. Private Sub Form_Unload(Cancel As Integer)
  495. If m_connect = 1 Then
  496. m_connect = 0
  497. VCI_CloseDevice m_devtype, 0
  498. End If
  499. End Sub
  500. Private Sub Combo1_Click()
  501. If m_bRun = True Then
  502. m_devtype = Combo1.ListIndex + 3
  503. If m_devtype = 3 Then
  504. Combo2.RemoveItem 1
  505. m_cannum = 0
  506. Combo2.ListIndex = 0
  507. Else
  508. Combo2.AddItem "Channel 2"
  509. End If
  510. End If
  511. End Sub
  512. Private Sub Timer1_Timer()
  513. Timer1.Enabled = False
  514. Dim ErrInfo As VCI_ERR_INFO
  515. If m_connect = 0 Then
  516. Timer1.Enabled = True
  517. Exit Sub
  518. End If
  519. Dim Length As Long
  520. Dim frameinfo(49) As VCI_CAN_OBJ
  521. Dim str As String
  522. Length = VCI_Receive(m_devtype, 0, m_cannum, frameinfo(0), 50, 10)
  523. If Length <= 0 Then
  524. Timer1.Enabled = True
  525. Exit Sub
  526. End If
  527. For i = 0 To Length - 1
  528. str = "Received data frame: "
  529. If frameinfo(i).TimeFlag = 0 Then
  530. tmpstr = "Time Mark: None "
  531. Else
  532. tmpstr = "Time Mark:0x" + Hex(frameinfo(i).TimeStamp)
  533. End If
  534. str = str + tmpstr
  535. tmpstr = " ID:0x" + Hex(frameinfo(i).ID)
  536. str = str + tmpstr
  537. str = str + " frame format:"
  538. If frameinfo(i).RemoteFlag = 0 Then
  539. tmpstr = "data frame "
  540. Else
  541. tmpstr = "Remote Frame "
  542. End If
  543. str = str + tmpstr
  544. str = str + " Frame type:"
  545. If frameinfo(i).ExternFlag = 0 Then
  546. tmpstr = "Standard frame "
  547. Else
  548. tmpstr = "Extended frame "
  549. End If
  550. str = str + tmpstr
  551. List1.AddItem str, List1.ListCount
  552. If frameinfo(i).RemoteFlag = 0 Then
  553. str = " data:"
  554. If frameinfo(i).DataLen > 8 Then
  555. frameinfo(i).DataLen = 8
  556. End If
  557. For j = 0 To frameinfo(i).DataLen - 1
  558. tmpstr = Hex(frameinfo(i).data(j)) + " "
  559. str = str + tmpstr
  560. Next
  561. List1.AddItem str, List1.ListCount
  562. End If
  563. List1.ListIndex = List1.ListCount - 1
  564. Next
  565. Timer1.Enabled = True
  566. End Sub