下面的代码可能是用来串口通讯的,是一个模块,看了很久,不知道具体是什么意思,用了哪些函数,每个函数是什么意思。不好意思,是刚接触,希望大家不吝指教一二,在此不胜感激
Public m_devtype As Long
Public m_connect As Byte
Public m_devind As Long
Public m_cannum As Long
Public m_idx As String
Public m_passcode As String
Public UserName As String
Public strpass(6) As String
Public m_modeselc As String
Public m_NODEID As String
Public m_btnNODE As Boolean
Public m_Timing0 As String
Public m_Timing1 As String
Declare Function VCI_OpenDevice Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal Reserved As Long) As Long
Declare Function VCI_CloseDevice Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long) As Long
Declare Function VCI_InitCAN Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef InitConfig As VCI_INIT_CONFIG) As Long
Declare Function VCI_ReadBoardInfo Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByRef info As VCI_BOARD_INFO) As Long
Declare Function VCI_ReadErrInfo Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef ErrInfo As VCI_ERR_INFO) As Long
Declare Function VCI_ReadCANStatus Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef CANStatus As VCI_CAN_STATUS) As Long
Declare Function VCI_GetReference Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByVal RefType As Long, ByRef data As Any) As Long
Declare Function VCI_SetReference Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByVal RefType As Long, ByRef data As Any) As Long
Declare Function VCI_GetReceiveNum Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long
Declare Function VCI_ClearBuffer Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long
Declare Function VCI_StartCAN Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long
Declare Function VCI_ResetCAN Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long) As Long
Declare Function VCI_Transmit Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef Send As VCI_CAN_OBJ, ByVal length As Long) As Long
Declare Function VCI_Receive Lib "ControlCAN.dll" (ByVal DeviceType As Long, ByVal DeviceInd As Long, ByVal CANInd As Long, ByRef Receive As VCI_CAN_OBJ, ByVal length As Long, ByVal WaitTime As Long) As Long
'定义需要用到的数据结构
Public Type VCI_BOARD_INFO
hw_Version As Integer
fw_Version As Integer
dr_Version As Integer
in_Version As Integer
irq_num As Integer
can_num As Byte
str_Serial_Num(19) As Byte
str_hw_Type(39) As Byte
Reserved(3) As Integer
End Type
Public Type VCI_CAN_OBJ
ID As Long
TimeStamp As Long
TimeFlag As Byte
SendType As Byte
RemoteFlag As Byte
ExternFlag As Byte
DataLen As Byte
data(7) As Byte
Reserved(2) As Byte
End Type
Public Type VCI_CAN_STATUS
ErrInterrupt As Byte
regMode As Byte
regStatus As Byte
regALCapture As Byte
regECCapture As Byte
regEWLimit As Byte
regRECounter As Byte
regTECounter As Byte
Reserved As Long
End Type
Public Type VCI_ERR_INFO
ErrCode As Long
Passive_ErrData(2) As Byte
ArLost_ErrData As Byte
End Type
Public Type VCI_INIT_CONFIG
AccCode As Long
AccMask As Long
Reserved As Long
Filter As Byte
Timing0 As Byte
Timing1 As Byte
Mode As Byte
End Type
Public Function ConnectString() As String
Dim strAppPath As String
strAppPath = App.Path
If Right(strAppPath, 1) <> "\" Then
strAppPath = strAppPath & "\"
End If
strAppPath = strAppPath & "Data\object.mdb"
ConnectString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & strAppPath & ";PWD=phase.com.cn" '& strAppPath &
End Function
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & " query successful"
Else
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & " 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误: " & Err.Description
Resume ExecuteSQL_Exit
End Function