创新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.

592 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 = 7245
  8. LinkTopic = "Form1"
  9. ScaleHeight = 6480
  10. ScaleWidth = 7245
  11. Begin VB.CommandButton Command4
  12. Caption = "�����б�"
  13. Height = 375
  14. Left = 6000
  15. TabIndex = 34
  16. Top = 3360
  17. Width = 975
  18. End
  19. Begin VB.ComboBox Combo2
  20. Height = 315
  21. ItemData = "Form1.frx":0000
  22. Left = 3720
  23. List = "Form1.frx":000A
  24. Style = 2 'Dropdown List
  25. TabIndex = 19
  26. Top = 430
  27. Width = 1185
  28. End
  29. Begin VB.TextBox Text1
  30. Height = 285
  31. Left = 4800
  32. TabIndex = 18
  33. Text = "00000080"
  34. Top = 2820
  35. Width = 975
  36. End
  37. Begin VB.Timer Timer1
  38. Interval = 10
  39. Left = 6480
  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 = 1935
  49. End
  50. Begin VB.ComboBox Combo5
  51. Height = 315
  52. ItemData = "Form1.frx":001C
  53. Left = 3000
  54. List = "Form1.frx":0026
  55. Style = 2 'Dropdown List
  56. TabIndex = 14
  57. Top = 2805
  58. Width = 1215
  59. End
  60. Begin VB.ComboBox Combo4
  61. Height = 315
  62. ItemData = "Form1.frx":003A
  63. Left = 960
  64. List = "Form1.frx":0044
  65. Style = 2 'Dropdown List
  66. TabIndex = 13
  67. Top = 2820
  68. Width = 1215
  69. End
  70. Begin VB.CommandButton Command3
  71. Caption = "��λCAN"
  72. Height = 330
  73. Left = 6000
  74. TabIndex = 12
  75. Top = 3000
  76. Width = 1005
  77. End
  78. Begin VB.CommandButton Command2
  79. Caption = "����CAN"
  80. Height = 330
  81. Left = 6000
  82. TabIndex = 11
  83. Top = 2640
  84. Width = 1005
  85. End
  86. Begin VB.ComboBox Combo1
  87. Height = 315
  88. ItemData = "Form1.frx":0058
  89. Left = 1200
  90. List = "Form1.frx":0062
  91. Style = 2 'Dropdown List
  92. TabIndex = 10
  93. Top = 420
  94. Width = 1290
  95. End
  96. Begin VB.CommandButton Connect
  97. Caption = "����"
  98. Height = 330
  99. Left = 5400
  100. TabIndex = 1
  101. Top = 430
  102. Width = 1005
  103. End
  104. Begin VB.Frame Frame1
  105. Caption = " ��������֡ "
  106. Height = 1230
  107. Left = 120
  108. TabIndex = 0
  109. Top = 2520
  110. Width = 5835
  111. Begin VB.CommandButton Command1
  112. Caption = "����"
  113. Height = 330
  114. Left = 4680
  115. TabIndex = 6
  116. Top = 720
  117. Width = 870
  118. End
  119. Begin VB.Label Label3
  120. Caption = "���͸�ʽ��"
  121. Height = 240
  122. Left = 120
  123. TabIndex = 33
  124. Top = 360
  125. Width = 960
  126. End
  127. Begin VB.Label Label7
  128. Caption = "���ݣ�"
  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 = 4200
  139. TabIndex = 4
  140. Top = 360
  141. Width = 585
  142. End
  143. Begin VB.Label Label5
  144. Caption = "֡��ʽ��"
  145. Height = 195
  146. Left = 2160
  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 = "�豸����"
  162. Height = 2295
  163. Left = 120
  164. TabIndex = 7
  165. Top = 120
  166. Width = 6855
  167. Begin VB.Frame Frame3
  168. Caption = "��ʼ��CAN����"
  169. Height = 1335
  170. Left = 120
  171. TabIndex = 20
  172. Top = 840
  173. Width = 6615
  174. Begin VB.ComboBox Combo7
  175. Height = 315
  176. ItemData = "Form1.frx":0079
  177. Left = 5280
  178. List = "Form1.frx":0086
  179. Style = 2 'Dropdown List
  180. TabIndex = 32
  181. Top = 840
  182. Width = 1215
  183. End
  184. Begin VB.ComboBox Combo6
  185. Height = 315
  186. ItemData = "Form1.frx":00A8
  187. Left = 5280
  188. List = "Form1.frx":00B5
  189. Style = 2 'Dropdown List
  190. TabIndex = 30
  191. Top = 360
  192. Width = 1215
  193. End
  194. Begin VB.TextBox Text6
  195. Height = 285
  196. Left = 3360
  197. TabIndex = 28
  198. Text = "14"
  199. Top = 840
  200. Width = 855
  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 = 3360
  213. TabIndex = 24
  214. Text = "FFFFFFFF"
  215. Top = 360
  216. Width = 855
  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 = "ģʽ��"
  228. Height = 255
  229. Left = 4680
  230. TabIndex = 31
  231. Top = 885
  232. Width = 615
  233. End
  234. Begin VB.Label Label12
  235. Caption = "�˲���ʽ��"
  236. Height = 255
  237. Left = 4320
  238. TabIndex = 29
  239. Top = 400
  240. Width = 975
  241. End
  242. Begin VB.Label Label11
  243. Caption = "��ʱ��1��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 = "��ʱ��0��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 = "�����룺0x"
  260. Height = 255
  261. Left = 2400
  262. TabIndex = 23
  263. Top = 360
  264. Width = 975
  265. End
  266. Begin VB.Label Label1
  267. Caption = "�����룺0x"
  268. Height = 255
  269. Left = 240
  270. TabIndex = 21
  271. Top = 360
  272. Width = 975
  273. End
  274. End
  275. Begin VB.Label Label10
  276. Caption = "CANͨ����"
  277. Height = 255
  278. Left = 2520
  279. TabIndex = 9
  280. Top = 360
  281. Width = 1095
  282. End
  283. Begin VB.Label Label9
  284. Caption = "�豸���ͣ�"
  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 = "��Ϣ"
  294. Height = 2535
  295. Left = 120
  296. TabIndex = 16
  297. Top = 3840
  298. Width = 6975
  299. Begin VB.ListBox List1
  300. Height = 2040
  301. Left = 120
  302. TabIndex = 17
  303. Top = 240
  304. Width = 6735
  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 ("���ȴ򿪶˿�")
  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 ("��������ʧ��")
  369. Else
  370. str = "�������ݳɹ�: "
  371. tmpstr = "ʱ����ʶ:�� "
  372. str = str + tmpstr
  373. tmpstr = " ֡ID:0x" + Hex(frameinfo.ID)
  374. str = str + tmpstr
  375. str = str + " ֡��ʽ:"
  376. If frameinfo.RemoteFlag = 0 Then
  377. tmpstr = "����֡ "
  378. Else
  379. tmpstr = "Զ��֡ "
  380. End If
  381. str = str + tmpstr
  382. str = str + " ֡����:"
  383. If frameinfo.ExternFlag = 0 Then
  384. tmpstr = "��׼֡ "
  385. Else
  386. tmpstr = "��չ֡ "
  387. End If
  388. str = str + tmpstr
  389. List1.AddItem str, List1.ListCount
  390. If frameinfo.RemoteFlag = 0 Then
  391. str = " ����:"
  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 ("���ȴ򿪶˿�")
  408. Exit Sub
  409. End If
  410. If VCI_StartCAN(m_devtype, 0, m_cannum) <> 1 Then
  411. MsgBox ("����CAN����")
  412. Else
  413. List1.AddItem "����CAN�ɹ�", 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 ("���ȴ򿪶˿�")
  420. Exit Sub
  421. End If
  422. If VCI_ResetCAN(m_devtype, 0, m_cannum) <> 1 Then
  423. MsgBox ("��λCAN����")
  424. Else
  425. List1.AddItem "��λCAN�ɹ�", 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 = "����"
  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 ("�����豸����")
  463. Else
  464. If VCI_InitCAN(m_devtype, 0, cannum, InitConfig) = 1 Then
  465. m_connect = 1
  466. m_cannum = cannum
  467. Connect.Caption = "�Ͽ�"
  468. Else
  469. MsgBox ("��ʼ��CAN����")
  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 "ͨ��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. VCI_ReadErrInfo m_devtype, 0, m_cannum, ErrInfo 'ע�⣺����û�ж����������������ô˺�������ȡ����ǰ�Ĵ����룬
  525. 'ǧ������ʡ����һ������ʹ�����ܲ���֪����������ʲô��
  526. Timer1.Enabled = True
  527. Exit Sub
  528. End If
  529. For i = 0 To Length - 1
  530. str = "���յ�����֡: "
  531. If frameinfo(i).TimeFlag = 0 Then
  532. tmpstr = "ʱ����ʶ:�� "
  533. Else
  534. tmpstr = "ʱ����ʶ:0x" + Hex(frameinfo(i).TimeStamp)
  535. End If
  536. str = str + tmpstr
  537. tmpstr = " ֡ID:0x" + Hex(frameinfo(i).ID)
  538. str = str + tmpstr
  539. str = str + " ֡��ʽ:"
  540. If frameinfo(i).RemoteFlag = 0 Then
  541. tmpstr = "����֡ "
  542. Else
  543. tmpstr = "Զ��֡ "
  544. End If
  545. str = str + tmpstr
  546. str = str + " ֡����:"
  547. If frameinfo(i).ExternFlag = 0 Then
  548. tmpstr = "��׼֡ "
  549. Else
  550. tmpstr = "��չ֡ "
  551. End If
  552. str = str + tmpstr
  553. List1.AddItem str, List1.ListCount
  554. If frameinfo(i).RemoteFlag = 0 Then
  555. str = " ����:"
  556. If frameinfo(i).DataLen > 8 Then
  557. frameinfo(i).DataLen = 8
  558. End If
  559. For j = 0 To frameinfo(i).DataLen - 1
  560. tmpstr = Hex(frameinfo(i).data(j)) + " "
  561. str = str + tmpstr
  562. Next
  563. List1.AddItem str, List1.ListCount
  564. End If
  565. List1.ListIndex = List1.ListCount - 1
  566. Next
  567. Timer1.Enabled = True
  568. End Sub