?? 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 ' 分配緩沖區(qū)(存儲原始數(shù)據(jù))
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 ' 硬件參數(shù)
Dim ADStatus As PCI8613_STATUS_AD
Dim nReadSizeWords As Long ' 每次讀取AD數(shù)據(jù)的長度(字)
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) ' 創(chuàng)建設(shè)備對象
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 ' 用戶選擇輸入量程
' 預(yù)置硬件參數(shù)
ADPara.ADMode = PCI8613_ADMODE_SEQUENCE ' AD模式為連續(xù)模式
ADPara.FirstChannel = 0 ' 首通道
ADPara.LastChannel = 3 ' 末通道
ADPara.Frequency = 25000 ' 采樣頻率(Hz)
ADPara.GroupInterval = 50 ' 組間間隔(uS)
ADPara.LoopsOfGroup = 1 ' 組內(nèi)各通道點(diǎn)數(shù)
ADPara.InputRange = InputRange ' 模擬量輸入量程范圍
ADPara.TriggerMode = PCI8613_TRIGMODE_SOFT ' 觸發(fā)模式為軟件觸發(fā)
ADPara.TriggerSource = PCI8613_TRIGSRC_ATR ' 觸發(fā)源
ADPara.TriggerType = PCI8613_TRIGTYPE_EDGE ' 觸發(fā)類型為邊沿觸發(fā)
ADPara.TriggerDir = PCI8613_TRIGDIR_NEGATIVE ' 觸發(fā)方向?yàn)樨?fù)向
ADPara.TrigWindow = 40 ' 觸發(fā)靈敏度
ADPara.ClockSource = PCI8613_CLOCKSRC_IN ' 時(shí)鐘源選用板內(nèi)時(shí)鐘源
ADPara.bClockOutput = False ' 禁止時(shí)鐘輸出
ADPara.TimeoutForNpt = 10 ' 在非空方式下,設(shè)置超時(shí)時(shí)間為10秒鐘(只在非空查詢方式下有效)
If PCI8613_InitDeviceProAD(hDevice, ADPara) = False Then ' 初始化硬件
dwErrorCode = PCI8613_GetLastErrorEx("PCI8613_InitDeviceProAD", strErrorMsg)
strDwError = dwErrorCode
MsgBox "dwErrorCode =" + strDwError + strErrorMsg
End If
nReadSizeWords = 4096 ' 將數(shù)據(jù)長度字轉(zhuǎn)換為雙字
If PCI8613_StartDeviceProAD(hDevice) = False Then ' 啟動設(shè)備
MsgBox "StartDeviceAD Error..."
End If
While (True) ' 查詢當(dāng)前物理緩沖區(qū)數(shù)據(jù)是否已準(zhǔn)備就緒
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
' 將原碼轉(zhuǎn)換為電壓值
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 "量程選擇錯(cuò)誤...."
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 ' 釋放設(shè)備對象
MsgBox "PCI8613_ReleaseDevice Error..."
End If
End Sub
Private Sub Form_Load()
Me.Combo_InputRange.ListIndex = 0
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -