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

187 lines
8.5 KiB

4 years ago
  1. Option Strict Off
  2. Option Explicit On
  3. Imports System.Runtime.InteropServices
  4. Module ControlCAN
  5. '�豸����˵����
  6. Public Const VCI_USBCAN As Int32 = 3
  7. Public Const VCI_USBCAN2 As Int32 = 4
  8. '------------------����ZLG�������������-----------------------
  9. '������Ҫ�õ������ݽṹ
  10. 'USB-CAN�����������忨��Ϣ���������͡�
  11. Public Structure VCI_BOARD_INFO
  12. Dim hw_Version As Short
  13. Dim fw_Version As Short
  14. Dim dr_Version As Short
  15. Dim in_Version As Short
  16. Dim irq_num As Short
  17. Dim can_num As Byte
  18. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=20)> Dim str_Serial_Num() As Byte
  19. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=40)> Dim str_hw_Type() As Byte
  20. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> Dim Reserved() As Short
  21. End Structure
  22. '����CAN��Ϣ֡���������͡�
  23. Public Structure VCI_CAN_OBJ
  24. Dim ID As Integer
  25. Dim TimeStamp As Integer
  26. Dim TimeFlag As Byte
  27. Dim SendType As Byte
  28. Dim RemoteFlag As Byte
  29. Dim ExternFlag As Byte
  30. Dim DataLen As Byte
  31. Dim data0 As Byte
  32. Dim data1 As Byte
  33. Dim data2 As Byte
  34. Dim data3 As Byte
  35. Dim data4 As Byte
  36. Dim data5 As Byte
  37. Dim data6 As Byte
  38. Dim data7 As Byte
  39. Dim Reserved0 As Byte
  40. Dim Reserved1 As Byte
  41. Dim Reserved2 As Byte
  42. End Structure
  43. '����CAN������״̬���������͡�
  44. Public Structure VCI_CAN_STATUS
  45. Dim ErrInterrupt As Byte
  46. Dim regMode As Byte
  47. Dim regStatus As Byte
  48. Dim regALCapture As Byte
  49. Dim regECCapture As Byte
  50. Dim regEWLimit As Byte
  51. Dim regRECounter As Byte
  52. Dim regTECounter As Byte
  53. Dim Reserved As Integer
  54. End Structure
  55. '����������Ϣ���������͡�
  56. Public Structure VCI_ERR_INFO
  57. Dim ErrCode As Integer
  58. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Dim Passive_ErrData() As Byte
  59. Dim ArLost_ErrData As Byte
  60. End Structure
  61. '������ʼ��CAN����������
  62. Public Structure VCI_INIT_CONFIG
  63. Dim AccCode As Integer
  64. Dim AccMask As Integer
  65. Dim Reserved As Integer
  66. Dim Filter_Renamed As Byte '0,1��������֡��2��׼֡�˲���3����չ֡�˲���
  67. Dim Timing0 As Byte
  68. Dim Timing1 As Byte
  69. Dim Mode As Byte 'ģʽ��0��ʾ����ģʽ��1��ʾֻ��ģʽ,2�Բ�ģʽ
  70. End Structure
  71. '��������
  72. '-----------------------------����ZLG���---------------------------------
  73. '����ֵ˵����=1�����ɹ���=0����ʧ�ܣ�=-1Ӳ�����������豸δ�򿪣�
  74. '�����豸�����ڲ���DeviceType��ʾ�豸���ͺţ�DeviceInd��ʾ�豸�����ţ��������ӿں�����ʹ���ֲᣩ�����豸ΪCAN232ʱReserved��ʾ�򿪴��ڵIJ����ʣ���Ϊ�����豸ʱ����������
  75. Declare Function VCI_OpenDevice Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal Reserved As Integer) As Integer
  76. '�ر��豸
  77. Declare Function VCI_CloseDevice Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer) As Integer
  78. '��ʼ��ָ����CAN
  79. Declare Function VCI_InitCAN Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer, ByRef InitConfig As VCI_INIT_CONFIG) As Integer
  80. '��ȡ�豸��Ϣ
  81. Declare Function VCI_ReadBoardInfo Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByRef info As VCI_BOARD_INFO) As Integer
  82. '��ȡ����һ�δ�����Ϣ
  83. Declare Function VCI_ReadErrInfo Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer, ByRef ErrInfo As VCI_ERR_INFO) As Integer
  84. '��ȡCAN״̬
  85. Declare Function VCI_ReadCANStatus Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer, ByRef CANStatus As VCI_CAN_STATUS) As Integer
  86. '��ȡ�豸����Ӧ����
  87. Declare Function VCI_GetReference Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer, ByVal RefType As Integer, ByRef data As Long) As Integer
  88. '�����豸����Ӧ��������Ҫ������ͬ�豸���ض�����
  89. Declare Function VCI_SetReference Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer, ByVal RefType As Integer, ByRef data As Long) As Integer
  90. '��ȡָ�����ջ������н��յ�����δ����ȡ��֡��
  91. Declare Function VCI_GetReceiveNum Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer) As Integer
  92. '����ָ��������
  93. Declare Function VCI_ClearBuffer Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer) As Integer
  94. '����CAN
  95. Declare Function VCI_StartCAN Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer) As Integer
  96. '��λCAN
  97. Declare Function VCI_ResetCAN Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer) As Integer
  98. '��ָ���ĵ��豸��������
  99. Declare Function VCI_Transmit Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer, ByRef Sendbuf As VCI_CAN_OBJ, ByVal length As Integer) As Integer
  100. '��ָ�����豸��ȡ����
  101. Declare Function VCI_Receive Lib "ControlCAN.dll" (ByVal DeviceType As Integer, ByVal DeviceInd As Integer, ByVal CANInd As Integer, ByRef Receive As VCI_CAN_OBJ, ByVal length As Integer, ByVal WaitTime As Integer) As Integer
  102. '-------------------------------�������������ݽṹ����---------------------------------
  103. 'USB-CAN�����������忨��Ϣ����������1�������ݽṹ��VCI_FindUsbDevice������
  104. Public Structure VCI_BOARD_INFO1
  105. Dim hw_Version As Short
  106. Dim fw_Version As Short
  107. Dim dr_Version As Short
  108. Dim in_Version As Short
  109. Dim irq_num As Short
  110. Dim can_num As Byte
  111. Dim reserved As Byte
  112. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Dim str_Serial_Num() As Byte
  113. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Dim str_hw_Type() As Byte
  114. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Dim str_Usb_Serial() As Byte
  115. End Structure
  116. '���峣����������
  117. Public Structure VCI_REF_NORMAL
  118. Dim Mode As Byte '����ģʽ
  119. Dim Filter_Renamed As Byte '�˲���ʽ
  120. Dim AccCode As Integer '�����˲�������
  121. Dim AccMask As Integer '�����˲�������
  122. Dim kBaudRate As Byte '�����������ţ�0-SelfDefine,1-5Kbps(δ��),2-18����Ϊ��10kbps,20kbps,40kbps,50kbps,80kbps,100kbps,125kbps,200kbps,250kbps,400kbps,500kbps,666kbps,800kbps,1000kbps,33.33kbps,66.66kbps,83.33kbps
  123. Dim Timing0 As Byte
  124. Dim Timing1 As Byte
  125. Dim CANRX_EN As Byte '�������
  126. Dim UARTBAUD As Byte '�������
  127. End Structure
  128. '���岨�������ò�������
  129. Public Structure VCI_BAUD_TYPE
  130. Dim Baud As Integer '�洢������ʵ��ֵ
  131. Dim SJW As Byte 'ͬ����ת���ȣ�ȡֵ1-4
  132. Dim BRP As Byte 'Ԥ��Ƶֵ��ȡֵ1-64
  133. Dim SAM As Byte '�����㣬ȡֵ0=����һ�Σ�1=��������
  134. Dim PHSEG2_SEL As Byte '��λ������2ѡ��λ��ȡֵ0=����λ������1ʱ������,1=�ɱ���
  135. Dim PRSEG As Byte '����ʱ���Σ�ȡֵ1-8
  136. Dim PHSEG1 As Byte '��λ������1��ȡֵ1-8
  137. Dim PHSEG2 As Byte '��λ������2��ȡֵ1-8
  138. End Structure
  139. '����Reference��������
  140. Public Structure VCI_REF_STRUCT
  141. Dim RefNormal As VCI_REF_NORMAL
  142. Dim reserved As Byte
  143. Dim BaudType As VCI_BAUD_TYPE
  144. End Structure
  145. Declare Function VCI_GetReference2 Lib "ControlCAN.dll" (ByVal DevType As Integer, ByVal DevIndex As Integer, ByVal CANIndex As Integer, ByVal reserved As Integer, ByRef pRefStruct As VCI_REF_STRUCT) As Integer
  146. Declare Function VCI_SetReference2 Lib "ControlCAN.dll" (ByVal DevType As Integer, ByVal DevIndex As Integer, ByVal CANIndex As Integer, ByVal RefType As Integer, ByRef data As Byte) As Integer
  147. Declare Function VCI_ResumeConfig Lib "ControlCAN.dll" (ByVal DevType As Integer, ByVal DevIndex As Integer) As Integer
  148. Declare Function VCI_ConnectDevice Lib "ControlCAN.dll" (ByVal DevType As Integer, ByVal DevIndex As Integer) As Integer
  149. Declare Function VCI_UsbDeviceReset Lib "ControlCAN.dll" (ByVal DevType As Integer, ByVal DevIndex As Integer, ByVal reserved As Integer) As Integer
  150. Declare Function VCI_FindUsbDevice Lib "ControlCAN.dll" (ByRef pInfo As VCI_BOARD_INFO1) As Integer
  151. Public Sub bytecpy(ByRef desarr() As Byte, ByVal desoff As Long, ByVal srcarr() As Byte, ByVal srcoff As Long, ByVal len As Long)
  152. Dim i As Long
  153. For i = 0 To len - 1
  154. desarr(desoff + i) = srcarr(i + srcoff)
  155. Next
  156. End Sub
  157. End Module