模块中定义的函数
Declare Function IC_InitComm Lib "DCIC32.DLL" (ByVal Port%) As Long
Declare Function IC_ExitComm% Lib "DCIC32.DLL" (ByVal icdev As Long)
Declare Function IC_Down% Lib "DCIC32.DLL" (ByVal icdev As Long)
Declare Function IC_Pushout% Lib "DCIC32.DLL" (ByVal icdev As Long)
Declare Function IC_InitType% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal TypeNo%)
Declare Function IC_Status% Lib "DCIC32.DLL" (ByVal icdev As Long)
Declare Function IC_Erase% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal l%)
Declare Function IC_Read% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal l%, ByVal Databuffer$)
Declare Function IC_Read_Hex% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal l%, ByVal Databuffer$)
Declare Function IC_Read_Float% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, fdata As Single)
Declare Function IC_Read_Int% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, fdata As Long)
Declare Function IC_Write% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal length%, ByVal Databuffer$)
Declare Function IC_Write_Hex% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal length%, ByVal Databuffer$)
Declare Function IC_Write_Float% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal fdata As Single)
Declare Function IC_Write_Int% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal fdata As Long)
Declare Function IC_Write24% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal length%, ByVal Databuffer$)
Declare Function IC_Write24_Hex% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal length%, ByVal Databuffer$)
Declare Function IC_Write64% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal length%, ByVal Databuffer$)
Declare Function IC_Write64_Hex% Lib "DCIC32.DLL" (ByVal icdev As Long, ByVal offset%, ByVal length%, ByVal Databuffer$)
窗体中
Private InitCardOK As Boolean
Private icdev As Long
Private st%
Private Sub Command1_Click()
If icdev > 0 Then GoTo Out
icdev = IC_InitComm(0)
If icdev < 0 Then
icdev = IC_InitComm(1)
MsgBox " 初始化失败,请确认串口是否正常!"
Exit Sub
End If
InitCardOK = True
Command1.Enabled = False
HaveCard = True
MsgBox "初始化成功!"
Exit Sub
Out:
InitCardOK = False
End Sub
Private Sub Command2_Click()
If Valid Then
WriteToCard
End If
End Sub
Private Function WriteToCard() As Boolean
Dim KK() As String
Dim I, J As Integer
WriteToCard = False
Label4.Caption = "检测中......"
Label4.Refresh
If Not CheckData(0, 9) Then Exit Function
Label4.Caption = "检测完毕!"
Exit Function
ERR:
End Function
Private Function CheckData(ByVal StartAdd As Integer, ByVal EndAdd As Integer) As Boolean
Dim I As Integer
Dim str As String * 30
Dim str1 As String * 30
Dim ReadStr As String * 30
Dim bln As Boolean
Dim ErrType As Integer
str = String((EndAdd - StartAdd + 1) * 2, "7")
str1 = String((EndAdd - StartAdd + 1) * 2, "F")
ReadStr = String((EndAdd - StartAdd + 1) * 2, Chr(32))
CheckData = False
st = IC_Write24_Hex(icdev, StartAdd, EndAdd - StartAdd + 1, str$)
If st < 0 Then ErrType = 1: GoTo ERR
st = IC_Read_Hex(icdev, StartAdd, EndAdd - StartAdd + 1, ReadStr$)
If st < 0 Then ErrType = 2: GoTo ERR
If Mid$(ReadStr, 1, (EndAdd - StartAdd + 1) * 2) <> Mid$(str, 1, (EndAdd - StartAdd + 1) * 2) Then
ErrType = 3
GoTo ERR
End If