📄 frmmain.frm
字号:
Top = 6360
Width = 3255
End
Begin VB.TextBox txtNotes
ForeColor = &H8000000D&
Height = 2295
Left = 3360
MultiLine = -1 'True
TabIndex = 0
Text = "frmMain.frx":0061
Top = 3960
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
For i = 0 To 2
'Operation mode controls
optOperationMode(i).Enabled = bEnable
'Start/stop type selection
optStartType(i).Enabled = bEnable
optStopType(i).Enabled = bEnable
Next i
'bus's band width, no enable 32 bits
For i = 0 To 3
optDataWidth(i).Enabled = bEnable
Next i
optDataWidth(1).Enabled = False
'Pacer source controls
lstPacerSource.Enabled = bEnable
txtCounterValue.Enabled = bEnable
'Pattern Match controls
txtPatternMatch.Enabled = bEnable
'Running controls
chkCyclic.Enabled = bEnable
cmdRun.Enabled = bEnable
cmdStop.Enabled = False 'always disable stop command before running
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdRun_Click()
'Enable Fast DI exports events
Device.EventEnable deDiHighBufferReady, True
Device.EventEnable deDiLowBufferReady, True
Device.EventEnable deDiOverrun, True
If (Device.EventEnable(deDiTerminated, True) = False) Then Exit Sub
'Start Multi-treading
Set CheckEventThread = New clsThreading
CheckEventThread.CreateNewThread AddressOf EventThread, tpNormal, False
If CheckEventThread.ThreadHandle = 0 Then GoTo FreeEvent
'Start Fast DI function
If (Device.FdiStart(chkCyclic.value, Device.ConvertBufferSizeToCount(glBufferSize), DRV_GetAddress(glDataBuf(0))) = False) Then
GoTo FreeThread
End If
'User controls setting
cmdStop.Enabled = True
cmdRun.Enabled = False
cmdExit.Enabled = False
cmdSelectDevice.Enabled = False
txtFdiAction.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 deDiHighBufferReady, False
Device.EventEnable deDiLowBufferReady, False
Device.EventEnable deDiOverrun, False
Device.EventEnable deDiTerminated, False
End Sub
Private Sub cmdSelectDevice_Click()
Dim dwData(3) As Long
Dim lLength As Long
'
' Select device from device selection dialog box
'
Set Device = Nothing
Set Device = New clsPCI1755
txtDeviceName = Device.Name
'Check this is correct device for using this demo program or not.
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 dpDiOperationMode, dwData(0), Len(dwData(0))
optOperationMode(dwData(0)).value = True
'Get device's data width and DIO direction,
'Force change to 32 bits DI if default setting is 32 bits DO
Device.DevicePropertyRead dpDioFdioDirection, dwData(0), Len(dwData(0))
If (dwData(0) = 1) Then dwData(0) = 0 'Forcre to change to 32 bits DI
optDataWidth(dwData(0)).value = True
'Get Pattern match value
Device.DevicePropertyRead dpDiPatternMatchValue, dwData(0), Len(dwData(0))
txtPatternMatch.Text = Hex(dwData(0))
'Get start method
Device.DevicePropertyRead dpDiStartMethod, dwData(0), Len(dwData(0))
optStartType(dwData(0) - 1).value = True
'Get stop method
Device.DevicePropertyRead dpDiStopMethod, 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(0)
Device.DevicePropertyRead dpDiPacerSource, dwData(0), Len(dwData(0))
lstPacerSource.ListIndex = dwData(0) - 1
End Sub
Private Sub cmdShow_Click()
frmShowData.Show 1
End Sub
Private Sub cmdStop_Click()
'Stop device and let device stop running itself
Device.FdiStop
'Controls setting
cmdStop.Enabled = False
End Sub
Private Sub Form_Load()
cmdSelectDevice_Click
End Sub
Private Sub Form_Unload(Cancel As Integer)
'
' Close 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
'
' Change the Fast DI pacer source selection. Write the selection to driver.
'
If lstPacerSource.ListIndex = 3 Then
txtCounterValue.Enabled = True
Else
txtCounterValue.Enabled = False
End If
'Set pacer source selection
l = lstPacerSource.ListIndex + 1
Device.DevicePropertyWrite dpDiPacerSource, 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 dpDiOperationMode, l, Len(l)
'Using external trigger is more making sense in Burst handshaking mode.
If l = 2 Then
lstPacerSource.ListIndex = 4
End If
End Sub
Private Sub optStartType_Click(Index As Integer)
Dim l As Long
'Write start method selection
l = Index + 1
Device.DevicePropertyWrite dpDiStartMethod, 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 dpDiStopMethod, l, Len(l)
End Sub
Private Sub txtCounterValue_Change()
'
' Check value boundary and set counter 0 value to device
' Counter 0 is a pacer source of Fast DI function
'
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
'Ensure user input value should larger than 2
txtCounterValue.Text = txtCounterValue.Tag
txtCounterValue.SelStart = 0
txtCounterValue.SelLength = 5
ElseIf (Val(txtCounterValue.Text) > 65535) Then
'Ensure user input smaller than 65535
If lStart <> 0 Then lStart = lStart - 1
txtCounterValue.Text = txtCounterValue.Tag
txtCounterValue.SelStart = lStart
txtCounterValue.SelLength = lLength
Else
'Record current setting and write changed value to device
txtCounterValue.Tag = Val(txtCounterValue.Text)
txtCounterValue.Text = txtCounterValue.Tag
txtCounterValue.SelStart = lStart
txtCounterValue.SelLength = lLength
'Write setting to device's counter1.
Device.DevicePropertyRead dpCounterCountValue, dwData(0), Len(dwData(0)) * 3
dwData(0) = txtCounterValue.Tag
Device.DevicePropertyWrite dpCounterCountValue, dwData(0), Len(dwData(0)) * 3
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
Private Sub txtPatternMatch_Change()
Dim lStart As Long, lLength As Long
Dim sHex As String
'
' Bound the Pattern Match value in 0 ~ FFFFFFFFh
'
If (Len(txtPatternMatch.Text) > 8) Then
'Out of value bound
lStart = txtPatternMatch.SelStart
lLength = txtPatternMatch.SelLength
If lStart <> 0 Then lStart = lStart - 1
txtPatternMatch.Text = Hex(txtPatternMatch.Tag)
txtPatternMatch.SelStart = lStart
txtPatternMatch.SelLength = lLength
End If
If (Len(txtPatternMatch.Text) = 0) Then
' 0 Value
txtPatternMatch.Text = "0"
txtPatternMatch.SelStart = 0
End If
'
' Valid Patterm Match value,write this new property value to device.
'
sHex = "&H" + txtPatternMatch.Text
lStart = Val(sHex)
txtPatternMatch.Tag = lStart
Device.DevicePropertyWrite dpDiPatternMatchValue, lStart, Len(lStart)
End Sub
Private Sub txtPatternMatch_GotFocus()
'Select all string for easy modify
txtPatternMatch.SelStart = 0
txtPatternMatch.SelLength = 8
End Sub
Private Sub txtPatternMatch_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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -