frmmain.frm
来自「16 relay output channels and 16 isolated」· FRM 代码 · 共 987 行 · 第 1/3 页
FRM
987 行
Private Sub cmdSelectDevice_Click()
Dim dwData(3) As Long, lBitTracing As Long
Dim i As Integer
'Close all previouse open events.
CloseCreatedEvents
'
' Get new device from device selection dialog box
'
' Create new device object, and it will pop-up device selection dialog box
Set DaqDevice = Nothing 'Clear previous open
Set DaqDevice = New clsPCI1755
txtDeviceName = DaqDevice.Name
'Check this is correct device to use this demo program
cmdStop.Enabled = False 'always disable stop command before running
If (DaqDevice.DoesDeviceCorrect = True) Then
EnableControls True
Else
EnableControls False
Exit Sub
End If
'
' Get concerned property setting from driver that set in
' "Advantech Device Management".
'
'Get Timer interrupt setting
DaqDevice.DevicePropertyRead dpCounterCountValue, dwData(0), Len(dwData(0)) * 3
txtCounterValue.Text = dwData(2)
txtCounterEvent.Text = "0"
'Get Pattern match interrupt setting
DaqDevice.DevicePropertyRead dpDiPatternMatchValue, dwData(0), Len(dwData(0))
txtPatternMatchValue.Text = Hex(dwData(0))
txtPatternMatchEvent.Text = "0"
'Get Status change interrupt setting
DaqDevice.DevicePropertyRead dpIrqDiChangeStatusChannel, dwData(0), Len(dwData(0))
txtChangeStatusChannel.Text = dwData(0)
txtStatusChangeEvent.Text = "0"
'Get Auxiliary DI interrupt setting.
DaqDevice.DevicePropertyRead dpIrqDiTriggerSignals, dwData(0), Len(dwData(0))
lBitTracing = 1
For i = 0 To 7
If ((lBitTracing And dwData(0)) = 0) Then
lstDiSignalCondition(i).ListIndex = 0
Else
lstDiSignalCondition(i).ListIndex = 1
End If
txtDiInterrupt(i).Text = "0"
lBitTracing = lBitTracing * 2
Next i
End Sub
Private Sub cmdStart_Click()
Dim i As Integer
'
' Clear previous value
'
txtCounterEvent.Text = "0"
txtPatternMatchEvent.Text = "0"
txtStatusChangeEvent.Text = "0"
For i = 0 To 7
txtDiInterrupt(i).Text = "0"
Next i
'
' Create thread to check events
'
Set CheckEventThread = New clsThreading
CheckEventThread.CreateNewThread AddressOf EventThread, tpNormal, True
If CheckEventThread.ThreadHandle = 0 Then Exit Sub
'
'User controls setting
'
cmdStop.Enabled = True
cmdExit.Enabled = False
cmdStart.Enabled = False
cmdSelectDevice.Enabled = False
End Sub
Private Sub cmdStop_Click()
'Stop thread
gbStopThread = True
cmdStop.Enabled = False
End Sub
Private Sub Form_Load()
cmdSelectDevice_Click
End Sub
Private Sub Form_Unload(Cancel As Integer)
'
' Stop still working events and close device.
'
CloseCreatedEvents
Set DaqDevice = Nothing
Set CheckEventThread = Nothing
Call TerminateProcess(GetCurrentProcess, ByVal 0&)
End Sub
Private Sub lstDiSignalCondition_Click(Index As Integer)
Dim lValue As Long, i As Integer
'
' Setup Auxiliary DI interrupt signal condition.
'
lValue = lstDiSignalCondition(7).ListIndex
For i = 6 To 0 Step -1
lValue = lValue * 2 + lstDiSignalCondition(i).ListIndex
Next i
DaqDevice.DevicePropertyWrite dpIrqDiTriggerSignals, lValue, Len(lValue)
End Sub
Private Sub txtChangeStatusChannel_Change()
Dim lStart As Long, lLength As Long, lValue As Long
Dim lData As Long
'
' Change status channel setting.
'
lValue = Val(txtChangeStatusChannel.Text)
If (lValue > 31) Then
'Out of value bound, only support upto 31 DI channel
lStart = txtChangeStatusChannel.SelStart
lLength = txtChangeStatusChannel.SelLength
If lStart <> 0 Then lStart = lStart - 1
txtChangeStatusChannel.Text = Str(txtChangeStatusChannel.Tag)
txtChangeStatusChannel.SelStart = lStart
txtChangeStatusChannel.SelLength = lLength
Exit Sub
End If
If (lValue = 0) Then
' 0 Value
txtChangeStatusChannel.Text = "0"
txtChangeStatusChannel.SelStart = 0
End If
'
' Before setting CFG_IrqDiChangeStatusChannel, the user must set CFG_DioFdioDirection
' and CFG_DiPacerSource.
' CFG_DioFdioDirection can be set 32-bit DI, 16-bit DIO or 8-bit DIO, depending
' on the channel which the user want to monitor.
' NOTE: 32-bit DO is not support.
' If the user doesn't choose a pacer clock, 10MHz internal pacer clock is the default.
'
lData = 0
DaqDevice.DevicePropertyWrite dpDioFdioDirection, lData, Len(lData) ' 32-bit DI
lData = 3
DaqDevice.DevicePropertyWrite dpDiPacerSource, lData, Len(lData) ' 10MHz
txtChangeStatusChannel.Tag = lValue
DaqDevice.DevicePropertyWrite dpIrqDiChangeStatusChannel, lValue, Len(lValue) ' CD
End Sub
Private Sub txtChangeStatusChannel_GotFocus()
'
' Select all text while get focus.
'
txtChangeStatusChannel.SelStart = 0
txtChangeStatusChannel.SelLength = 2
End Sub
Private Sub txtChangeStatusChannel_KeyPress(KeyAscii As Integer)
'
' Key pressing filter, only passing 0 - 9 and backspace keys
'
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then Exit Sub
If KeyAscii = 8 Then Exit Sub
KeyAscii = 0
End Sub
Private Sub txtCounterValue_Change()
'
' Check value boundary and set counter 2 value to device.
' Counter 2 is the timer interrupt source, base frequency on 10 Mhz.
'
Dim dwData(3) As Long, dwLength As Long
Dim lStart As Long, lLength As Long
lStart = txtCounterValue.SelStart
lLength = txtCounterValue.SelLength
'
' Bound the input value between 2 ~ 65535.
'
If (Val(txtCounterValue.Text) < 2) Then
txtCounterValue.Text = txtCounterValue.Tag
txtCounterValue.SelStart = 0
txtCounterValue.SelLength = 5
ElseIf (Val(txtCounterValue.Text) > 65535) Then
If lStart <> 0 Then lStart = lStart - 1
txtCounterValue.Text = txtCounterValue.Tag
txtCounterValue.SelStart = lStart
txtCounterValue.SelLength = lLength
Else
'
' Counter 2 value chaged, write new value to device.
'
txtCounterValue.Tag = Val(txtCounterValue.Text)
'Write setting to device's counter1.
DaqDevice.DevicePropertyRead dpCounterCountValue, dwData(0), Len(dwData(0)) * 3
dwData(2) = txtCounterValue.Tag
DaqDevice.DevicePropertyWrite dpCounterCountValue, dwData(0), Len(dwData(0)) * 3
txtCounterValue.Text = txtCounterValue.Tag
txtCounterValue.SelStart = lStart
txtCounterValue.SelLength = lLength
End If
End Sub
Private Sub txtCounterValue_GotFocus()
'Select all string while get focus.
txtCounterValue.SelStart = 0
txtCounterValue.SelLength = 5
End Sub
Private Sub txtCounterValue_KeyPress(KeyAscii As Integer)
'
' Key pressing filter, only passing 0 - 9 and backspace keys
'
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then Exit Sub
If KeyAscii = 8 Then Exit Sub
KeyAscii = 0
End Sub
Private Sub txtPatternMatchValue_Change()
Dim lStart As Long, lLength As Long
Dim sHex As String
Dim lData As Long
'
' Bound the Pattern Match value in 0 ~ FFFFFFFFh
'
If (Len(txtPatternMatchValue.Text) > 8) Then
'Out of value bound
lStart = txtPatternMatchValue.SelStart
lLength = txtPatternMatchValue.SelLength
If lStart <> 0 Then lStart = lStart - 1
txtPatternMatchValue.Text = Hex(txtPatternMatchValue.Tag)
txtPatternMatchValue.SelStart = lStart
txtPatternMatchValue.SelLength = lLength
End If
If (Len(txtPatternMatchValue.Text) = 0) Then
' 0 Value
txtPatternMatchValue.Text = "0"
txtPatternMatchValue.SelStart = 0
End If
'
' Valid Patterm Match value,write this new property value to device.
'
sHex = "&H" + txtPatternMatchValue.Text
lStart = Val(sHex)
txtPatternMatchValue.Tag = lStart
'
' Before setting CFG_DiPatternMatchValue, the user must set CFG_DioFdioDirection
' and CFG_DiPacerSource.
' CFG_DioFdioDirection can be set 32-bit DI, 16-bit DIO or 8-bit DIO, depending
' on the data wides.
' NOTE: 32-bit DO is not support.
' If the user doesn't choose a pacer clock, 10MHz internal pacer clock is the default.
'
lData = 0
DaqDevice.DevicePropertyWrite dpDioFdioDirection, lData, Len(lData) ' 32-bit DI
lData = 3
DaqDevice.DevicePropertyWrite dpDiPacerSource, lData, Len(lData) ' 10MHz
DaqDevice.DevicePropertyWrite dpDiPatternMatchValue, lStart, Len(lStart) ' PM
End Sub
Private Sub txtPatternMatchValue_GotFocus()
'Select all string for easy modify
txtPatternMatchValue.SelStart = 0
txtPatternMatchValue.SelLength = 8
End Sub
Private Sub txtPatternMatchValue_KeyPress(KeyAscii As Integer)
'
' Key pressing filter, only passing 0-9, A-F and backspace keys
'
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then Exit Sub
If KeyAscii = 8 Then Exit Sub
If KeyAscii >= Asc("A") And KeyAscii <= Asc("F") Then Exit Sub
If KeyAscii >= Asc("a") And KeyAscii <= Asc("f") Then
KeyAscii = KeyAscii + Asc("A") - Asc("a")
Exit Sub
End If
KeyAscii = 0
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?