📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 7770
ClientLeft = 60
ClientTop = 450
ClientWidth = 9915
LinkTopic = "Form1"
ScaleHeight = 7770
ScaleWidth = 9915
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1000
Left = 1920
Top = 4560
End
Begin VB.CommandButton Command1
Caption = "关闭"
Height = 615
Left = 5400
TabIndex = 2
Top = 3720
Width = 975
End
Begin VB.TextBox Text1
Height = 735
Left = 2880
TabIndex = 1
Top = 2040
Width = 1455
End
Begin VB.CommandButton cmd
Caption = "开始转动"
Height = 495
Left = 3480
TabIndex = 0
Top = 3720
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim hDevice As Long
Dim Para_DI As USB2010_PARA_DI
Dim s1, s2 As Single
Dim dAvg As Single
Dim bStatus As Boolean
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub cmd_Click()
If cmd.Caption = "开始转动" Then
Timer1.Enabled = True
cmd.Caption = "停止转动"
Else
cmd.Caption = "开始转动"
End If
End Sub
Private Sub Form_Load()
Dim s As Single
s = 0
s1 = 0
s2 = 0
hDevice = USB2010_CreateDevice(0)
If hDevice = INVALID_HANDLE_VALUE Then
MsgBox "创建设备对象失败"
Exit Sub
End If
dAvg = 360 / 8192
bStatus = USB2010_GetDeviceDI(hDevice, Para_DI)
If bStatus = False Then
Exit Sub
End If
If (Para_DI.DI0) = 1 Then
s = s + 1
End If
If (Para_DI.DI1) = 1 Then
s = s + 2
End If
If (Para_DI.DI2) = 1 Then
s = s + 4
End If
If (Para_DI.DI3) = 1 Then
s = s + 8
End If
If (Para_DI.DI4) = 1 Then
s = s + 16
End If
If (Para_DI.DI5) = 1 Then
s = s + 32
End If
If (Para_DI.DI6) = 1 Then
s = s + 64
End If
If (Para_DI.DI7) = 1 Then
s = s + 128
End If
If (Para_DI.DI8) = 1 Then
s = s + 256
End If
If (Para_DI.DI9) = 1 Then
s = s + 512
End If
If (Para_DI.DI10) = 1 Then
s = s + 1024
End If
If (Para_DI.DI11) = 1 Then
s = s + 2048
End If
If (Para_DI.DI12) = 1 Then
s = s + 4096
End If
s1 = s
Text1.Text = Format(0, "###0.000")
USB2010_ReleaseDevice hDevice
End Sub
Private Sub Timer1_Timer()
Dim s As Single
s = 0
hDevice = USB2010_CreateDevice(0)
If hDevice = INVALID_HANDLE_VALUE Then
MsgBox "创建设备对象失败"
Timer1.Enabled = False
Exit Sub
End If
bStatus = USB2010_GetDeviceDI(hDevice, Para_DI)
If bStatus = False Then
MsgBox "读数据出错!"
Exit Sub
End If
If (Para_DI.DI0) = 1 Then
s = s + 1
End If
If (Para_DI.DI1) = 1 Then
s = s + 2
End If
If (Para_DI.DI2) = 1 Then
s = s + 4
End If
If (Para_DI.DI3) = 1 Then
s = s + 8
End If
If (Para_DI.DI4) = 1 Then
s = s + 16
End If
If (Para_DI.DI5) = 1 Then
s = s + 32
End If
If (Para_DI.DI6) = 1 Then
s = s + 64
End If
If (Para_DI.DI7) = 1 Then
s = s + 128
End If
If (Para_DI.DI8) = 1 Then
s = s + 256
End If
If (Para_DI.DI9) = 1 Then
s = s + 512
End If
If (Para_DI.DI10) = 1 Then
s = s + 1024
End If
If (Para_DI.DI11) = 1 Then
s = s + 2048
End If
If (Para_DI.DI12) = 1 Then
s = s + 4096
End If
s2 = (s - s1) * dAvg
Text1.Text = Format(s2, "###0.000")
USB2010_ReleaseDevice hDevice
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -