1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Private Sub cmdRead_Click ()
Dim ErrCde As Long ' Error code
Dim szErrMsg As String * 80' Error string
Dim DriverHandle As Long Dim AiConfig As PT_AIConfig
Dim AiVoltageIn As PT_AIVoltageIn
Dim voltage As Single
'Step 1: open device
ErrCde = DRV_DeviceOpen (0, DriverHandle)' Make sure device number = 0
If (ErrCde <> 0) Then
DRV_GetErrorMessage ErrCde,szErrMsg
Response = MsgBox (szErrMsg, vbOKOnly, "Error!!")
Exit Sub
End If
'Step 2: configure input range
AiConfig.DasChan = 0 ' channel: 0
AiConfig.DasGain = 0 ' gain code: 0
ErrCde = DRV_AIConfig (DriverHandle, AiConfig)
If (ErrCde <> 0) Then
DRV_GetErrorMessage ErrCde,szErrMsg
Response = MsgBox (szErrMsg, vbOKOnly, "Error!!")
Exit Sub
End If
'Step 3: read value
AiVoltageIn.chan = AiConfig.DasChan
AiVoltageIn.gain = AiConfig.DasGain
AiVoltageIn.TrigMode = 0
AiVoltageIn.voltage = DRV_GetAddress (voltage)
ErrCde = DRV_AIVoltageIn (DriverHandle, AiVoltageIn)
If (ErrCde <> 0) Then
DRV_GetErrorMessage ErrCde, szErrMsg
Response = MsgBox (szErrMsg, vbOKOnly, "Error!!")
Exit Sub
End If
'Step 4: display value
txtAIValue.Text = Format (voltage, "####0.00")
'Step 5: close device
ErrCde = DRV_DeviceClose (DriverHandle)
If (ErrCde <> 0) Then
DRV_GetErrorMessage ErrCde,szErrMsg
Response = MsgBox (szErrMsg, vbOKOnly, "Error!!")
End If
End Sub |
Partager