📄 frmmain.frm
字号:
Begin VB.CommandButton cmdRun
Caption = "&Run"
Height = 375
Left = 120
TabIndex = 3
Top = 2520
Width = 1335
End
End
Begin VB.CommandButton cmdExit
Caption = "E&xit"
Height = 495
Left = 3360
TabIndex = 1
Top = 6000
Width = 3255
End
Begin VB.TextBox Text1
ForeColor = &H80000002&
Height = 2295
Left = 3360
MultiLine = -1 'True
TabIndex = 0
Text = "frmMain.frx":0061
Top = 3600
Width = 3255
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Sub EnableControls(bEnable As Boolean)
Dim i As Integer
'Operation mode controls
For i = 0 To 2
optOperationMode(i).Enabled = bEnable
Next i
'bus's band width, no enable 32 bits DI
For i = 1 To 3
optDataWidth(i).Enabled = bEnable
Next i
'Start/stop type selection
optStartType(0).Enabled = bEnable
optStartType(1).Enabled = bEnable
optStopType(0).Enabled = bEnable
optStopType(1).Enabled = bEnable
'Pacer source controls
lstPacerSource.Enabled = bEnable
txtCounterValue.Enabled = bEnable
'Running controls
chkCyclic.Enabled = bEnable
cmdRun.Enabled = bEnable
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdRun_Click()
Dim i As Long
'Fill data for Fast DO action.
For i = 0 To glBufferSize / 4 - 1
glDataBuf(i) = i
Next
'Enable Fast DO exports events
Device.EventEnable deDoHighBufferTransferred, True
Device.EventEnable deDoLowBufferTransferred, True
Device.EventEnable deDoUnderrun, True
If (Device.EventEnable(deDoTerminated, True) = False) Then Exit Sub
'Start Multi-treading
' gbStopThread = True
Set CheckEventThread = New clsThreading
CheckEventThread.CreateNewThread AddressOf EventThread, tpNormal, False
If CheckEventThread.ThreadHandle = 0 Then GoTo FreeThread
'Start Fast DO function
If (Device.FdoStart(chkCyclic.value, Device.ConvertBufferSizeToCount(glBufferSize), DRV_GetAddress(glDataBuf(0))) = False) Then
GoTo FreeEvent
End If
'User controls setting
cmdStop.Enabled = True
cmdRun.Enabled = False
cmdExit.Enabled = False
cmdSelectDevice.Enabled = False
txtFdoAction.Text = "Running"
txtBufferChange.Text = "None"
txtOverrunCount = "0"
'Resume Multi-trerading
CheckEventThread.Enabled = True
Exit Sub
'Error code controlling
FreeThread:
Set CheckEventThread = Nothing
FreeEvent:
Device.EventEnable deDoHighBufferTransferred, False
Device.EventEnable deDoLowBufferTransferred, False
Device.EventEnable deDoUnderrun, False
Device.EventEnable deDoTerminated, False
End Sub
Private Sub cmdSelectDevice_Click()
Dim dwData(3) As Long
Dim lLength As Long
'Select device
Set Device = Nothing
Set Device = New clsPCI1755
txtDeviceName = Device.Name
'Check this is correct device to use this demo program
cmdStop.Enabled = False 'always disable stop command before running
If (Device.DoesDeviceCorrect = True) Then
EnableControls True
Else
EnableControls False
Exit Sub
End If
'Get device's Property and set to controls
'Get device operation mode
Device.DevicePropertyRead dpDoOperationMode, dwData(0), Len(dwData(0))
optOperationMode(dwData(0)).value = True
'Get device's data width and DIO direction
Device.DevicePropertyRead dpDioFdioDirection, dwData(0), Len(dwData(0))
If (dwData(0) = 0) Then dwData(0) = 1
optDataWidth(dwData(0)).value = True
'Get start method
Device.DevicePropertyRead dpDoStartMethod, dwData(0), Len(dwData(0))
optStartType(dwData(0) - 1).value = True
'Get stop method
Device.DevicePropertyRead dpDoStopMethod, dwData(0), Len(dwData(0))
optStopType(dwData(0) - 1).value = True
'Get pacer source
Device.DevicePropertyRead dpCounterCountValue, dwData(0), Len(dwData(0)) * 3
txtCounterValue = dwData(1)
Device.DevicePropertyRead dpDoPacerSource, dwData(0), Len(dwData(0))
lstPacerSource.ListIndex = dwData(0) - 1
End Sub
Private Sub cmdStop_Click()
'Stop device and let device stop running itself
Device.FdoStop
txtFdoAction.Text = "FIFO emptying"
'Controls setting
cmdStop.Enabled = False
End Sub
Private Sub Form_Load()
cmdSelectDevice_Click
End Sub
Private Sub Form_Unload(Cancel As Integer)
'
' Free multi-thread and device.
'
Set CheckEventThread = Nothing
Set Device = Nothing
'
' The Multi-threading created from VB need call this API to free all resource and
' terminate all process.
' This statement will close the VB development enviroment too. It is better
' to save change before running your program if calling this statement.
'
Call TerminateProcess(GetCurrentProcess, ByVal 0&)
End Sub
Private Sub lstPacerSource_Click()
Dim l As Long
'
' Pacer source change, write changed property to device
'
If lstPacerSource.ListIndex = 3 Then
txtCounterValue.Enabled = True
Else
txtCounterValue.Enabled = False
End If
'Set pacer source selection
l = lstPacerSource.ListIndex + 1
Device.DevicePropertyWrite dpDoPacerSource, l, Len(l)
End Sub
Private Sub optDataWidth_Click(Index As Integer)
Dim l As Long
'Write DIO direction and data width selection
l = Index
Device.DevicePropertyWrite dpDioFdioDirection, l, Len(l)
End Sub
Private Sub optOperationMode_Click(Index As Integer)
Dim l As Long
'Write device operation mode property
l = Index
Device.DevicePropertyWrite dpDoOperationMode, l, Len(l)
End Sub
Private Sub optStartType_Click(Index As Integer)
Dim l As Long
'Write start method selection
l = Index + 1
Device.DevicePropertyWrite dpDoStartMethod, l, Len(l)
End Sub
Private Sub optStopType_Click(Index As Integer)
Dim l As Long
'Write stop method selection
l = Index + 1
Device.DevicePropertyWrite dpDoStopMethod, l, Len(l)
End Sub
Private Sub txtCounterValue_Change()
'
' Check value boundary and set counter 1 value to device.
' Counter 1 is a 8254 counter, and it is a pacer source of Fast DO function.
' The valid 8254 counter value range is 2 - 65535
'
Dim dwData(3) As Long, dwLength As Long
Dim lStart As Long, lLength As Long
lStart = txtCounterValue.SelStart
lLength = txtCounterValue.SelLength
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
txtCounterValue.Tag = Val(txtCounterValue.Text)
'Write setting to device's counter1.
Device.DevicePropertyRead dpCounterCountValue, dwData(0), Len(dwData(0)) * 3
dwData(1) = txtCounterValue.Tag
Device.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 text while got 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -