📄 doform.vb
字号:
Exit Sub
End If
If DAQDO1.MaxPortNumber = 0 Then
MsgBox("Function Not Supported", MsgBoxStyle.OKOnly)
DAQDO1.CloseDevice()
Exit Sub
End If
cmbPort.Enabled = True
bOpen = True
' Add Port number to list box
cmbPort.Items.Clear()
For i = 0 To DAQDO1.MaxPortNumber - 1
cmbPort.Items.Add((Str(i)))
Next i
If DAQDO1.MaxPortNumber Then
cmbPort.SelectedIndex = DAQDO1.Port
End If
End Sub
Private Sub UpdateMask()
Dim i As Integer
Dim mask As Short
For i = 0 To 7
If (chkMaskArray(i).Checked) Then
mask = mask Or (1 << i)
Else
mask = mask Or (0 << i)
End If
Next i
DAQDO1.Mask = mask
txtMask.Text = Hex(DAQDO1.Mask)
End Sub
Private Sub ChkMask0_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask0.CheckedChanged
UpdateMask()
End Sub
Private Sub ChkMask1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask1.CheckedChanged
UpdateMask()
End Sub
Private Sub ChkMask2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask2.CheckedChanged
UpdateMask()
End Sub
Private Sub ChkMask3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask3.CheckedChanged
UpdateMask()
End Sub
Private Sub ChkMask4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask4.CheckedChanged
UpdateMask()
End Sub
Private Sub ChkMask5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask5.CheckedChanged
UpdateMask()
End Sub
Private Sub ChkMask6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask6.CheckedChanged
UpdateMask()
End Sub
Private Sub ChkMask7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkMask7.CheckedChanged
UpdateMask()
End Sub
Private Sub txtMask_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMask.TextChanged
Dim lStart As Long, lLength As Long
Dim sHex As String
If (isInitializing) Then
Exit Sub
End If
'
' Bound the value in 0 ~ FFh
'
If (Len(txtMask.Text) > 2) Then
'Out of value bound
lStart = txtMask.SelectionStart
lLength = txtMask.SelectionLength
If lStart <> 0 Then lStart = lStart - 1
txtMask.Text = Hex(txtMask.Tag)
txtMask.SelectionStart = lStart
txtMask.SelectionLength = lLength
End If
If (Len(txtMask.Text) = 0) Then
' 0 Value
txtMask.Text = "0"
txtMask.SelectionStart = 0
End If
'
' Valid Patterm Match value,write this new property value to device.
'
sHex = "&H" + txtMask.Text
lStart = Val(sHex)
txtMask.Tag = lStart
Dim i As Integer
Dim mask As Short
mask = lStart
For i = 0 To 7
If (mask And (1 << i)) Then
chkMaskArray(i).Checked = True
Else
chkMaskArray(i).Checked = False
End If
Next i
DAQDO1.Mask = mask
End Sub
Private Sub txtMask_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMask.KeyPress
End Sub
Private Sub UpdateStatus()
Dim i As Integer
Dim Status As Integer
Status = DAQDO1.ByteReadBack()
For i = 0 To 7
If (Status And (1 << i)) Then
cmdChannelArray(i).BackColor = Color.Red
StatusBits.Set(i, True)
Else
cmdChannelArray(i).BackColor = Color.Blue
StatusBits.Set(i, False)
End If
Next
txtReadBack.Text = Hex(Status)
End Sub
Private Sub cmdChannel7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel7.Click
DAQDO1.Bit = 7
StatusBits.Set(7, Not StatusBits.Get(7))
DAQDO1.BitOutput(StatusBits.Get(7))
UpdateStatus()
End Sub
Private Sub cmdChannel6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel6.Click
DAQDO1.Bit = 6
StatusBits.Set(6, Not StatusBits.Get(6))
DAQDO1.BitOutput(StatusBits.Get(6))
UpdateStatus()
End Sub
Private Sub cmdChannel5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel5.Click
DAQDO1.Bit = 5
StatusBits.Set(5, Not StatusBits.Get(5))
DAQDO1.BitOutput(StatusBits.Get(5))
UpdateStatus()
End Sub
Private Sub cmdChannel4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel4.Click
DAQDO1.Bit = 4
StatusBits.Set(4, Not StatusBits.Get(4))
DAQDO1.BitOutput(StatusBits.Get(4))
UpdateStatus()
End Sub
Private Sub cmdChannel3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel3.Click
DAQDO1.Bit = 3
StatusBits.Set(3, Not StatusBits.Get(3))
DAQDO1.BitOutput(StatusBits.Get(3))
UpdateStatus()
End Sub
Private Sub cmdChannel2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel2.Click
DAQDO1.Bit = 2
StatusBits.Set(2, Not StatusBits.Get(2))
DAQDO1.BitOutput(StatusBits.Get(2))
UpdateStatus()
End Sub
Private Sub cmdChannel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel1.Click
DAQDO1.Bit = 1
StatusBits.Set(1, Not StatusBits.Get(1))
DAQDO1.BitOutput(StatusBits.Get(1))
UpdateStatus()
End Sub
Private Sub cmdChannel0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdChannel0.Click
DAQDO1.Bit = 0
StatusBits.Set(0, Not StatusBits.Get(0))
DAQDO1.BitOutput(StatusBits.Get(0))
UpdateStatus()
End Sub
Private Sub txtReadBack_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
Me.Close()
End Sub
Private Sub cmdReadBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReadBack.Click
UpdateStatus()
End Sub
Private Sub cmdByteOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdByteOut.Click
DAQDO1.Mask = CShort("&H" & txtMask.Text)
DAQDO1.ByteOutput(CShort("&H" & txtoutByte.Text))
End Sub
Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbPort.SelectedIndexChanged
If (isInitializing) Then
Exit Sub
End If
DAQDO1.Port = cmbPort.SelectedIndex
cmdReadBack_Click(cmdReadBack, New System.EventArgs)
End Sub
Private Sub txtOutByte_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtOutByte.TextChanged
Dim lStart As Long, lLength As Long
Dim sHex As String
If (isInitializing) Then
Exit Sub
End If
'
' Bound the value in 0 ~ FFh
'
If (Len(txtOutByte.Text) > 2) Then
'Out of value bound
lStart = txtOutByte.SelectionStart
lLength = txtOutByte.SelectionLength
If lStart <> 0 Then lStart = lStart - 1
txtOutByte.Text = Hex(txtOutByte.Tag)
txtOutByte.SelectionStart = lStart
txtOutByte.SelectionLength = lLength
End If
If (Len(txtOutByte.Text) = 0) Then
' 0 Value
txtOutByte.Text = "0"
txtOutByte.SelectionStart = 0
End If
'
' Valid Patterm Match value,write this new property value to device.
'
sHex = "&H" + txtOutByte.Text
lStart = Val(sHex)
txtOutByte.Tag = lStart
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -