📄 form1.frm
字号:
Top = 1740
Width = 870
End
Begin VB.Label Label2
Caption = "计数器1:"
Height = 285
Index = 0
Left = 450
TabIndex = 18
Top = 825
Width = 930
End
Begin VB.Label Label2
Caption = "计数器2:"
Height = 285
Index = 1
Left = 405
TabIndex = 17
Top = 1305
Width = 930
End
Begin VB.Label Label2
Caption = "计数器3:"
Height = 285
Index = 2
Left = 420
TabIndex = 16
Top = 1785
Width = 930
End
Begin VB.Label Label2
Caption = "当前值"
Height = 285
Index = 3
Left = 1650
TabIndex = 15
Top = 420
Width = 855
End
Begin VB.Label Label2
Caption = "工作方式"
Height = 285
Index = 4
Left = 2715
TabIndex = 14
Top = 435
Width = 1005
End
Begin VB.Label Label2
Caption = "初值"
Height = 285
Index = 5
Left = 4065
TabIndex = 13
Top = 450
Width = 615
End
Begin VB.Label lblCurrCTval
BorderStyle = 1 'Fixed Single
Caption = "当前值1"
Height = 330
Index = 0
Left = 1440
TabIndex = 12
Top = 750
Width = 1125
End
Begin VB.Label lblCurrCTval
BorderStyle = 1 'Fixed Single
Caption = "当前值2"
Height = 330
Index = 1
Left = 1440
TabIndex = 11
Top = 1245
Width = 1125
End
Begin VB.Label lblCurrCTval
BorderStyle = 1 'Fixed Single
Caption = "当前值3"
Height = 330
Index = 2
Left = 1440
TabIndex = 10
Top = 1740
Width = 1125
End
End
Begin VB.Timer Timer5
Enabled = 0 'False
Interval = 200
Left = 8190
Top = 165
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "选择板卡:"
Height = 225
Index = 0
Left = 375
TabIndex = 60
Top = 270
Width = 1020
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "板卡基地址:"
Height = 225
Index = 1
Left = 3930
TabIndex = 59
Top = 300
Width = 1245
End
Begin VB.Label lblBaseAddr
BorderStyle = 1 'Fixed Single
Caption = "板卡基地址"
Height = 360
Left = 5295
TabIndex = 58
Top = 240
Width = 1800
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "AD量程选择:"
Height = 225
Index = 1
Left = 405
TabIndex = 55
Top = 1140
Width = 1260
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "显示方式:"
Height = 225
Index = 0
Left = 4215
TabIndex = 53
Top = 1125
Width = 1020
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public m_timer1Finish As Boolean
Public m_timer2Finish As Boolean
Public m_timer3Finish As Boolean
Const m_ADchCount As Long = 32
Private Sub cmdCT_Click(Index As Integer)
'停止或启动计数器
'把initVal As Double,防止用户输入很大的数造成溢出
Dim initVal As Double, ctMode As Long
initVal = Val(txtInitCTval(Index).Text)
ctMode = Val(Right(cobCTmode(Index).Text, 1))
If initVal < 0 Or initVal > 65535 Then
MsgBox "计数器初值不能 < 0 或 > 65535"
Exit Sub
End If
If cmdCT(Index).Caption = "启动" Then
'设置计数通道1工作方式及初值
ZT8360V_CTStart m_cardNO, Index + 1, ctMode, initVal
m_timer3Finish = True
Timer3.Interval = 100
Timer3.Enabled = True
txtInitCTval(Index).Enabled = False
cobCTmode(Index).Enabled = False
cmdCT(Index).Caption = "停止"
Else
ZT8360V_CTStop m_cardNO, Index + 1
txtInitCTval(Index).Enabled = True
cobCTmode(Index).Enabled = True
cmdCT(Index).Caption = "启动"
End If
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub cmdStartAD_Click()
'启动AD
cobADrange.Enabled = False
cobShowMode.Enabled = False
If m_showMode < 2 Then
Call ZT8360V_AIinit(m_cardNO, 1, m_ADchCount, AI.Range_initCode, 0, 0, 0, 0, 0, 100)
Else
Call ZT8360V_AIinit(m_cardNO, 1, m_ADchCount, m_AIrange, 0, 0, 0, 0, 0, 100)
End If
m_timer1Finish = True
Timer1.Interval = 100
Timer1.Enabled = True
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub cmdStopAD_Click()
'停止AD
cobADrange.Enabled = True
cobShowMode.Enabled = True
Timer1.Enabled = False
m_timer1Finish = False
End Sub
Private Sub cobCardNO_Click()
'选择板卡
m_cardNO = cobCardNO.ListIndex + ZT8360V_GetBaseNO
If ZT8360V_OpenDevice(m_cardNO) <> 0 Then
MsgBox "打开设备失败,找不到指定的板卡。"
Exit Sub
End If
lblBaseAddr.Caption = Hex(ZT8360V_GetBaseAddr(m_cardNO))
End Sub
Private Sub cobADrange_Click()
'选择AD量程
Select Case cobADrange.ListIndex
Case 0: '
m_AIrange = AI.Range_0__10000mV
Case 1: '
m_AIrange = AI.Range_N5000__P5000mV
End Select
End Sub
Private Sub cobShowMode_Click()
'选择显示方式
m_showMode = cobShowMode.ListIndex
End Sub
Private Sub Command1_Click()
'单端,通道1采集(双端采集与此类似)
MsgBox "结果 :" & ZT8360V_AIonce(m_cardNO, 0, 1, AI.Range_0__10000mV, 0, 60) '通道1,采集范围0--10V
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub Form_Load()
'find form load
'打开设备
If ZT8360V_GetCardCount() <= 0 Then
MsgBox "打开设备失败,找不到此类板卡。" & vbCrLf & _
"可能是未插卡或未安装驱动"
'使所有控件失效
'For Each ctl In Me.Controls
' ctl.Enabled = False
'Next ctl
'Exit Sub
End
End If
Me.Caption = "系统中已识别的此类板卡的数量为:" & ZT8360V_GetCardCount & " 块"
For i = 0 To ZT8360V_GetCardCount - 1
cobCardNO.AddItem "第 " & i + 1 & " 块卡"
Next i
If ZT8360V_GetCardCount > 0 Then cobCardNO.ListIndex = 0
' m_cardNO = 1 'pci卡的板卡索引号,与原驱动不同,第1块PCI卡的索引号为1
'Exit Sub
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 3
cobADrange.ListIndex = 0
cobShowMode.ListIndex = 2
'初始化开关量
ZT8360V_DOAll m_cardNO, &H0
Timer5.Enabled = True
'初始化计数器
For i = 0 To 3 - 1
txtInitCTval(i).Text = 10 ^ (i + 1)
ZT8360V_CTStop m_cardNO, i + 1
cobCTmode(i).ListIndex = 2
Next i
Me.Caption = "PCI8360V测试程序(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
'Timer1.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
'关闭设备
If ZT8360V_CloseDevice(m_cardNO) <> 0 Then
MsgBox "关闭设备失败"
End If
End Sub
Private Sub Timer1_Timer()
'用于AD,成批读数
If m_timer1Finish = False Then Exit Sub
m_timer1Finish = False
Dim retCount As Long, currCount As Long, countPerCh As Long, AIrange As Long
Dim sum(32 - 1) As Double
wantCount = 2000 '4096 '0
retCount = ZT8360V_AI(m_cardNO, m_saveData(0), wantCount)
' For k = 0 To 32 - 1
' Text1(k) = m_saveData(k)
' Next k
' m_timer1Finish = True
'Exit Sub
'输出到文件
' Dim writeFile As String
' writeFile = App.Path & "\test.txt"
' If Dir(writeFile, vbNormal) <> "" Then Kill writeFile
' Open writeFile For Output As #1
' For i = 0 To retCount - 1
' Print #1, "CH" & (i Mod 32) + 1 & " 采集结果 = " & m_saveData(i)
' Next i
' Close
' MsgBox "finish"
' Exit Sub
' Timer1.Enabled = False
'Exit Sub
'MsgBox retCount
'retCount = ZT8360v_ReadSFifo(m_cardNO, m_saveData(0), 40960) '819200
'求平均值
countPerCh = (retCount / 10) \ m_ADchCount
If countPerCh > 0 Then
If m_showMode < 2 Then
For k = 0 To m_ADchCount - 1
For i = 0 To countPerCh - 1
Dim tempVal As Long
tempVal = m_saveData(i * m_ADchCount + k)
tempVal = IIf(tempVal < 0, tempVal + 65536, tempVal)
sum(k) = sum(k) + tempVal
Next i
tempVal = CLng(sum(k) / countPerCh)
Text1(k) = IIf(m_showMode = 0, Hex(tempVal), tempVal)
Next k
Else
For k = 0 To m_ADchCount - 1
For i = 0 To countPerCh - 1
sum(k) = sum(k) + m_saveData(i * m_ADchCount + k)
Next i
Text1(k) = Format(sum(k) / countPerCh, "0.##")
Next k
End If
End If
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
m_timer1Finish = True
End Sub
Private Sub Timer3_Timer()
'用于读计数器的当前值
If m_timer3Finish = False Then Exit Sub
m_timer3Finish = False
For i = 0 To 3 - 1
lblCurrCTval(i).Caption = ZT8360V_CTRead(m_cardNO, i + 1, 0)
Next i
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
m_timer3Finish = True
End Sub
'============================ 开关量相关 ==================================
Private Sub Timer5_Timer()
'用于读开关量输入
Command7_Click
readAllDI
End Sub
Private Sub readAllDI()
'所有通道开关量输入,从32到1,十六进制显示
Dim tempStr As String
tempStr = Hex(ZT8360V_DIAll(m_cardNO))
lblDIhex.Caption = "DI数据十六进制显示:" & Left("0000", 4 - Len(tempStr)) & tempStr
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub Command7_Click()
'所有通道开关量输入,从16到1,二进制显示
Dim outStr As String
outStr = ""
For i = 15 To 0 Step -1
outStr = outStr & "" & ZT8360V_DIBit(m_cardNO, i + 1)
If i Mod 4 = 0 Then outStr = outStr & " , "
Next i
outStr = IIf(Right(outStr, 3) = " , ", Left(outStr, Len(outStr) - 3), outStr)
lblDIbinary.Caption = "DI数据 二进制 显示:" & outStr
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub cmdDOAllHigh_Click()
'所有DO通道全部输出高电平
ZT8360V_DOAll m_cardNO, &HFFFF
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
End Sub
Private Sub cmdDOAllLow_Click()
'所有DO通道全部输出低电平
ZT8360V_DOAll m_cardNO, &H0
Me.Caption = "PCI8360V测试(错误号: " & ZT8360V_GetLastErr & ")" '返回函数执行的状态
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -