📄 half.frm
字号:
VERSION 5.00
Begin VB.Form Half
Caption = "PCI8613_AD_Half"
ClientHeight = 4185
ClientLeft = 60
ClientTop = 450
ClientWidth = 5910
LinkTopic = "Form1"
ScaleHeight = 4185
ScaleWidth = 5910
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox TextVolt
Enabled = 0 'False
Height = 270
Index = 3
Left = 3720
TabIndex = 10
Top = 2400
Width = 975
End
Begin VB.TextBox TextVolt
Enabled = 0 'False
Height = 270
Index = 2
Left = 1680
TabIndex = 9
Top = 2400
Width = 975
End
Begin VB.TextBox TextVolt
Enabled = 0 'False
Height = 270
Index = 1
Left = 3720
TabIndex = 8
Top = 1680
Width = 975
End
Begin VB.CommandButton Command_Start
Caption = "采集"
Height = 375
Left = 2040
TabIndex = 7
Top = 3240
Width = 1695
End
Begin VB.TextBox TextVolt
Enabled = 0 'False
Height = 270
Index = 0
Left = 1680
TabIndex = 6
Top = 1680
Width = 975
End
Begin VB.ComboBox Combo_InputRange
Height = 300
ItemData = "Half.frx":0000
Left = 2520
List = "Half.frx":000D
Style = 2 'Dropdown List
TabIndex = 1
Top = 840
Width = 1695
End
Begin VB.Label Label5
Caption = "CH3:"
Height = 255
Left = 3240
TabIndex = 5
Top = 2400
Width = 375
End
Begin VB.Label Label4
Caption = "CH2:"
Height = 255
Left = 1200
TabIndex = 4
Top = 2400
Width = 375
End
Begin VB.Label Label3
Caption = "CH1:"
Height = 255
Left = 3240
TabIndex = 3
Top = 1680
Width = 375
End
Begin VB.Label Label2
Caption = "CH0:"
Height = 255
Left = 1200
TabIndex = 2
Top = 1680
Width = 375
End
Begin VB.Label Label1
Caption = "选择量程:"
Height = 255
Left = 1560
TabIndex = 0
Top = 840
Width = 855
End
End
Attribute VB_Name = "Half"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim InputRange As Integer
Dim ADBuffer(0 To 8191) As Long ' 分配缓冲区(存储原始数据)
Dim hDevice As Long
Dim DeviceLgcID As Integer
Dim dwErrorCode As Integer
Dim strDwError As String
Dim strErrorMsg As String
Dim ADPara As PCI8613_PARA_AD ' 硬件参数
Dim ADStatus As PCI8613_STATUS_AD
Dim nReadSizeWords As Long ' 每次读取AD数据的长度(字)
Dim nRetSizeWords As Long
Dim nADChannel As Integer
Dim ADData As Integer
Dim fVolt As Double
Dim strTemp As String
Private Sub Command_Start_Click()
DeviceLgcID = 0
hDevice = PCI8613_CreateDevice(DeviceLgcID) ' 创建设备对象
If hDevice = INVALID_HANDLE_VALUE Then
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_CreateDevice", strErrorMsg)
strDwError = dwErrorCode
MsgBox "dwErrorCode =" + strDwError + strErrorMsg
Exit Sub
End If
InputRange = Me.Combo_InputRange.ListIndex ' 用户选择输入量程
' 预置硬件参数
ADPara.ADMode = PCI8613_ADMODE_SEQUENCE ' AD模式为连续模式
ADPara.FirstChannel = 0 ' 首通道
ADPara.LastChannel = 3 ' 末通道
ADPara.Frequency = 25000 ' 采样频率(Hz)
ADPara.GroupInterval = 50 ' 组间间隔(uS)
ADPara.LoopsOfGroup = 1 ' 组内各通道点数
ADPara.InputRange = InputRange ' 模拟量输入量程范围
ADPara.TriggerMode = PCI8613_TRIGMODE_SOFT ' 触发模式为软件触发
ADPara.TriggerSource = PCI8613_TRIGSRC_ATR ' 触发源
ADPara.TriggerType = PCI8613_TRIGTYPE_EDGE ' 触发类型为边沿触发
ADPara.TriggerDir = PCI8613_TRIGDIR_NEGATIVE ' 触发方向为负向
ADPara.TrigWindow = 40 ' 触发灵敏度
ADPara.ClockSource = PCI8613_CLOCKSRC_IN ' 时钟源选用板内时钟源
ADPara.bClockOutput = False ' 禁止时钟输出
ADPara.TimeoutForNpt = 10 ' 在非空方式下,设置超时时间为10秒钟(只在非空查询方式下有效)
If PCI8613_InitDeviceProAD(hDevice, ADPara) = False Then ' 初始化硬件
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_InitDeviceProAD", strErrorMsg)
strDwError = dwErrorCode
MsgBox "dwErrorCode =" + strDwError + strErrorMsg
End If
nReadSizeWords = 4096 ' 将数据长度字转换为双字
If PCI8613_StartDeviceProAD(hDevice) = False Then ' 启动设备
MsgBox "StartDeviceAD Error..."
End If
While (True) ' 查询当前物理缓冲区数据是否已准备就绪
If PCI8613_GetDevStatusProAD(hDevice, ADStatus) = False Then
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_GetDevStatusProAD", strErrorMsg)
strDwError = dwErrorCode
MsgBox "dwErrorCode =" + strDwError + strErrorMsg
GoTo ExitRead
End If
If ADStatus.bHalf = 1 Then
GoTo Read
End If
Wend
Read:
If PCI8613_ReadDeviceProAD_Half(hDevice, ADBuffer(0), nReadSizeWords, nRetSizeWords) = False Then
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_ReadDeviceProAD_Half", strErrorMsg)
strDwError = dwErrorCode
MsgBox "dwErrorCode =" + strDwError + strErrorMsg
GoTo ExitRead
End If
Dim Index As Integer
For Index = 0 To 3 Step 1
' 将原码转换为电压值
Select Case InputRange
Case PCI8613_INPUT_N10000_P10000mV ' -10V - +10V
fVolt = (20000# / 4096) * (ADBuffer(Index) And 4095) - 10000#
Case PCI8613_INPUT_N5000_P5000mV ' -5V - +5V
fVolt = (10000# / 4096) * (ADBuffer(Index) And 4095) - 5000#
Case PCI8613_INPUT_0_P10000mV ' 0V - +10V
fVolt = (10000# / 4096) * (ADBuffer(Index) And 4095)
Case Else:
MsgBox "量程选择错误...."
End Select
strTemp = fVolt
Me.TextVolt(Index).Text = Format(strTemp, "00.00")
Next Index
ExitRead:
If PCI8613_ReleaseDeviceProAD(hDevice) = False Then ' 释放AD
MsgBox "PCI8613_ReleaseDeviceProAD Error.."
End If
If PCI8613_ReleaseDevice(hDevice) = False Then ' 释放设备对象
MsgBox "PCI8613_ReleaseDevice Error..."
End If
End Sub
Private Sub Form_Load()
Me.Combo_InputRange.ListIndex = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -