📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form frmDAQ
BorderStyle = 1 'Fixed Single
Caption = "Capacitance Measurement"
ClientHeight = 5535
ClientLeft = 915
ClientTop = 3060
ClientWidth = 7470
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5535
ScaleWidth = 7470
Begin VB.CommandButton cmdStopCap
Caption = "Stop Reading"
Height = 375
Left = 360
TabIndex = 13
Top = 2040
Width = 1575
End
Begin VB.CommandButton cmdStopHumid
Caption = "Stop Reading"
Height = 375
Left = 5160
TabIndex = 10
Top = 2040
Width = 1575
End
Begin VB.Frame frameJumpers
Caption = "Jumper Position"
Height = 1455
Left = 2400
TabIndex = 5
Top = 1200
Width = 1815
Begin VB.OptionButton Jumper3
Caption = "10 pF / Count"
Height = 375
Left = 240
TabIndex = 8
Top = 960
Width = 1455
End
Begin VB.OptionButton Jumper2
Caption = "1.0 pF / Count"
Height = 375
Left = 240
TabIndex = 7
Top = 600
Width = 1455
End
Begin VB.OptionButton Jumper1
Caption = "0.1 pF / Count"
Height = 375
Left = 240
TabIndex = 6
Top = 240
Value = -1 'True
Width = 1455
End
End
Begin VB.CommandButton cmdReadHumidity
Caption = "Read Humidity"
Height = 375
Left = 5160
TabIndex = 4
Top = 1440
Width = 1575
End
Begin VB.CommandButton cmdReadCapacitance
Caption = "Read Capacitance"
Height = 375
Left = 360
TabIndex = 1
Top = 1440
Width = 1575
End
Begin VB.Frame Frame2
Caption = "Status"
Height = 2655
Left = 120
TabIndex = 0
Top = 2760
Width = 7215
Begin VB.CommandButton cmdVersion
Caption = "Firmware Version"
Height = 375
Left = 2040
TabIndex = 11
Top = 240
Width = 1575
End
Begin VB.CommandButton cmdClearStatusWindow
Caption = "Clear Status Window"
Height = 375
Left = 120
TabIndex = 3
Top = 240
Width = 1815
End
Begin VB.TextBox MessageBox
Height = 1815
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Top = 720
Width = 6975
End
End
Begin VB.Shape shapeHumid
FillColor = &H000000FF&
FillStyle = 0 'Solid
Height = 255
Left = 6960
Shape = 3 'Circle
Top = 720
Width = 255
End
Begin VB.Line Line1
BorderWidth = 2
X1 = 4560
X2 = 4560
Y1 = 0
Y2 = 2640
End
Begin VB.Label lblCapDisplay
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "-- pF"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 495
Left = 1200
TabIndex = 12
Top = 600
Width = 1935
End
Begin VB.Label lblHumidityDisplay
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "-- % RH"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 495
Left = 5040
TabIndex = 9
Top = 600
Width = 1815
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "Capacitance"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 14
Top = 0
Width = 4215
End
Begin VB.Label Label2
Alignment = 2 'Center
Caption = "Humidity"
BeginProperty Font
Name = "MS Sans Serif"
Size = 18
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4680
TabIndex = 15
Top = 0
Width = 2535
End
Begin VB.Shape shapeCap
FillColor = &H000000FF&
FillStyle = 0 'Solid
Height = 255
Left = 3240
Shape = 3 'Circle
Top = 720
Width = 255
End
Begin VB.Menu MnuFileActions
Caption = "File"
Begin VB.Menu mnuReadFile
Caption = "&Read"
Enabled = 0 'False
Visible = 0 'False
End
Begin VB.Menu mnuExportFile
Caption = "E&xport File"
Enabled = 0 'False
Visible = 0 'False
End
Begin VB.Menu mnuSaveAs
Caption = "Save &As"
Enabled = 0 'False
Visible = 0 'False
End
Begin VB.Menu mnuExit
Caption = "&Exit"
End
End
Begin VB.Menu mnuDataloggerActions
Caption = "Datalogger"
Enabled = 0 'False
Visible = 0 'False
Begin VB.Menu mnuStartRecording
Caption = "Start Recording"
End
Begin VB.Menu mnuReadData
Caption = "Read Datalogger"
End
End
Begin VB.Menu mnuDebug
Caption = "Debug"
Enabled = 0 'False
Visible = 0 'False
Begin VB.Menu mnuEnableDebug
Caption = "Enable Debug Mode"
End
End
Begin VB.Menu cmdAbout
Caption = "About"
Enabled = 0 'False
Visible = 0 'False
End
End
Attribute VB_Name = "frmDAQ"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Global Variables
Dim StopButtonPress As Boolean
' Commands
Const GETFROM = &H67 ' g - Get n bytes from device
Const TRANSFERTO = &H74 ' t - Transfer n bytes to device
Const NULLCMD = &H5A ' Z - NOP, used to fill out the 8 byte packets
Const VERSION = 0
Const CMD01 = 1
Const CMD02 = 2
Const CMD03 = 3
Const CMD04 = 4
Const CMD05 = 5
Const CMD06 = 6
Const GETSTATUS = 7
' Acknowledgement Values
Const VERSION_ACK = &H10
Const CMD01_ACK = &H11
Const CMD02_ACK = &H12
Const CMD03_ACK = &H13
Const CMD04_ACK = &H14
Const CMD05_ACK = &H15
Const CMD06_ACK = &H16
Private Sub Form_Load()
StopButtonPress = True
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Function WaitForAck() As Byte
Dim i As Integer
WaitForAck = &HFF
For i = 1 To 100
Call WriteToDevice(TRANSFERTO, 1, GETSTATUS, GETFROM, 1, NULLCMD, NULLCMD, NULLCMD)
ReadReport
If ReadBuffer(1) > 0 And ReadBuffer(1) < &HFF Then
WaitForAck = ReadBuffer(1)
Exit For
End If
Next i
End Function
Private Sub cmdClearStatusWindow_Click()
MessageBox.Text = ""
End Sub
Private Sub cmdStopCap_Click()
StopButtonPress = True
MessageBox = MessageBox + "Stop Reading" + vbCrLf
shapeCap.FillColor = vbRed
shapeHumid.FillColor = vbRed
frameJumpers.Enabled = True
Jumper1.Enabled = True
Jumper2.Enabled = True
Jumper3.Enabled = True
End Sub
Private Sub cmdStopHumid_Click()
StopButtonPress = True
MessageBox = MessageBox + "Stop Reading" + vbCrLf
shapeHumid.FillColor = vbRed
shapeCap.FillColor = vbRed
frameJumpers.Enabled = True
Jumper1.Enabled = True
Jumper2.Enabled = True
Jumper3.Enabled = True
End Sub
Private Sub cmdVersion_Click()
Dim VersionMajor As Integer
Dim VersionMinor As Integer
' Get firmware version
Call WriteToDevice(TRANSFERTO, 1, VERSION, GETFROM, 1, NULLCMD, NULLCMD, NULLCMD)
ReadReport
If ReadBuffer(1) >= 0 And ReadBuffer(1) < &HFF Then
VersionMajor = ReadBuffer(1) \ &H10
VersionMinor = ReadBuffer(1) And &HF
End If
If WaitForAck() = VERSION_ACK Then
MessageBox = MessageBox + "Firmware Version: " + Chr$(VersionMajor + Asc("0")) + "." + Chr$(VersionMinor + Asc("0")) + vbCrLf
Else
MessageBox = MessageBox + "No Version Acknowledgement" + vbCrLf
End If
DoEvents
End Sub
Private Sub cmdReadCapacitance_Click()
Dim CapMSB As Integer
Dim CapLSB As Integer
Dim Capacitance As Double
MessageBox = MessageBox + "Start Reading Capacitance" + vbCrLf
lblHumidityDisplay.Caption = "-- % RH"
StopButtonPress = False
shapeCap.FillColor = vbGreen
shapeHumid.FillColor = vbRed
Do
' Read Capacitance
Call WriteToDevice(TRANSFERTO, 1, CMD01, NULLCMD, NULLCMD, NULLCMD, NULLCMD, NULLCMD)
Sleep 200
If WaitForAck() = CMD01_ACK Then
' MessageBox = MessageBox + "Cmd01 Acknowledgement" + vbCrLf
Else
MessageBox = MessageBox + "No Cmd01 Acknowledgement" + vbCrLf
Exit Do
End If
' Get Capacitance
Call WriteToDevice(TRANSFERTO, 1, CMD02, GETFROM, 2, NULLCMD, NULLCMD, NULLCMD)
ReadReport
CapMSB = ReadBuffer(1)
CapLSB = ReadBuffer(2)
Capacitance = CapMSB * 256 + CapLSB
If Jumper1 = True Then
Capacitance = Capacitance / 10
End If
If Jumper2 = True Then
Capacitance = Capacitance
End If
If Jumper3 = True Then
Capacitance = Capacitance * 10
End If
If WaitForAck() = CMD02_ACK Then
' MessageBox = MessageBox + Str(Capacitance) + " pF" + vbCrLf
lblCapDisplay.Caption = Format(Str(Capacitance), "0.0") + " pF"
Else
MessageBox = MessageBox + "No Cmd02 Acknowledgement" + vbCrLf
Exit Do
End If
DoEvents
Sleep 200
Loop Until StopButtonPress
End Sub
Private Sub cmdReadHumidity_Click()
Dim CapMSB As Integer
Dim CapLSB As Integer
Dim Capacitance As Double
Dim Humidity As Double
MessageBox = MessageBox + "Start Reading Humidity" + vbCrLf
StopButtonPress = False
shapeHumid.FillColor = vbGreen
shapeCap.FillColor = vbGreen
frameJumpers.Enabled = False
Jumper1.Enabled = False
Jumper2.Enabled = False
Jumper3.Enabled = False
Do
' Read Capacitance
Call WriteToDevice(TRANSFERTO, 1, CMD01, NULLCMD, NULLCMD, NULLCMD, NULLCMD, NULLCMD)
Sleep 200
If WaitForAck() = CMD01_ACK Then
' MessageBox = MessageBox + "Cmd01 Acknowledgement" + vbCrLf
Else
MessageBox = MessageBox + "No Cmd01 Acknowledgement" + vbCrLf
Exit Do
End If
' Get Capacitance
Call WriteToDevice(TRANSFERTO, 1, CMD02, GETFROM, 2, NULLCMD, NULLCMD, NULLCMD)
ReadReport
CapMSB = ReadBuffer(1)
CapLSB = ReadBuffer(2)
Capacitance = CapMSB * 256 + CapLSB
Capacitance = Capacitance / 10
If WaitForAck() = CMD02_ACK Then
' MessageBox = MessageBox + Str(Capacitance) + " pF" + vbCrLf
lblCapDisplay.Caption = Format(Str(Capacitance), "0.0") + " pF"
Else
MessageBox = MessageBox + "No Cmd02 Acknowledgement" + vbCrLf
Exit Do
End If
' Read Humidity
Call WriteToDevice(TRANSFERTO, 1, CMD03, GETFROM, 2, NULLCMD, NULLCMD, NULLCMD)
ReadReport
CapMSB = ReadBuffer(1)
CapLSB = ReadBuffer(2)
Humidity = CapMSB * 256 + CapLSB
Humidity = Humidity / 100
Humidity = Int(Humidity)
If WaitForAck() = CMD03_ACK Then
' MessageBox = MessageBox + Str(Humidity) + " % RH" + vbCrLf
lblHumidityDisplay.Caption = Str(Humidity) + " % RH"
Else
MessageBox = MessageBox + "No Cmd03 Acknowledgement" + vbCrLf
Exit Do
End If
DoEvents
Sleep 200
Loop Until StopButtonPress
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -