?? form1.frm
字號:
End
End If
End If
End Sub
Private Sub Command7_Click()
Dim myRequest As VENDOR_REQUEST_IN
Dim bResult As Boolean
Dim ReData(8) As Byte
Dim nBytes As Long
Dim HidDevice As Long
Dim DevicePathName As String
Dim HighTemper As String
HighTemper = InputBox(" 請輸入DS1620的THIGH值(℃): " + _
Chr(13) & Chr(10) + _
" (取值范圍為0-70)", "DS1620設置", "20")
If (HighTemper = "") Then
Exit Sub
Else
If (Not IsNumeric(HighTemper) Or Val(HighTemper) < 0 Or Val(HighTemper) > 70) Then
MsgBox "THIGH的取值范圍為0℃-70℃", 16, "THigh錯誤"
Exit Sub
End If
End If
DevicePathName = "\\.\Cyusb-0"
If (OpenDevice(HidDevice, DevicePathName) = True) Then
myRequest.bRequest = &H9
myRequest.wValue = Val(HighTemper) * 2
myRequest.wIndex = &H0
myRequest.wLength = &H8
myRequest.bData = &H0
myRequest.direction = &H1
bResult = DeviceIoControl _
(HidDevice, _
IOCTL_Cyusb_VENDOR_REQUEST, _
myRequest, _
10, _
ReData(0), _
8, _
nBytes, _
0)
If (bResult = True) Then
THightemper = ReData(2) / 2
MsgBox "THIGH =" + Str(ReData(2) / 2) + "℃", 0, "設置成功"
CloseHandle (HidDevice)
Else
MsgBox " 與USB設備通信失敗!" + _
Chr(13) & Chr(10) + _
"USB數據傳輸錯誤,請重新啟動硬件!", _
16, "THigh錯誤"
CloseHandle (HidDevice)
Unload Form1
End
End If
End If
End Sub
Private Sub Command8_Click()
Dim myRequest As VENDOR_REQUEST_IN
Dim bResult As Boolean
Dim ReData(8) As Byte
Dim nBytes As Long
Dim HidDevice As Long
Dim DevicePathName As String
Dim RamAddress As String
RamAddress = InputBox(" 請輸入CY7C63001 RAM的地址值: " + _
Chr(13) & Chr(10) + _
" (取值范圍為0-127)", "CY7C63001設置", "43")
If (RamAddress = "") Then
Exit Sub
Else
If (Not IsNumeric(RamAddress) Or Val(RamAddress) < 0 Or Val(RamAddress) > 127) Then
MsgBox "CY7C63001 RAM地址的范圍為0-127", 16, "RAM錯誤"
Exit Sub
End If
End If
DevicePathName = "\\.\Cyusb-0"
If (OpenDevice(HidDevice, DevicePathName) = True) Then
myRequest.bRequest = &H2
myRequest.wValue = Val(RamAddress)
myRequest.wIndex = &H0
myRequest.wLength = &H8
myRequest.bData = &H0
myRequest.direction = &H1
bResult = DeviceIoControl _
(HidDevice, _
IOCTL_Cyusb_VENDOR_REQUEST, _
myRequest, _
10, _
ReData(0), _
8, _
nBytes, _
0)
If (bResult = True) Then
MsgBox "RAM地址" + RamAddress + "處的值為:" + Str(ReData(1)), 0, "CY7C63001"
CloseHandle (HidDevice)
Else
MsgBox " 與USB設備通信失敗!" + _
Chr(13) & Chr(10) + _
"USB數據傳輸錯誤,請重新啟動硬件!", _
16, "RAM錯誤"
CloseHandle (HidDevice)
Unload Form1
End
End If
End If
End Sub
Private Sub Command9_Click()
Dim myRequest As VENDOR_REQUEST_IN
Dim bResult As Boolean
Dim ReData(8) As Byte
Dim nBytes As Long
Dim HidDevice As Long
Dim DevicePathName As String
Dim RamAddress As String
Dim RamData As String
RamAddress = InputBox(" 請輸入CY7C63001 RAM的地址: " + _
Chr(13) & Chr(10) + _
" (取值范圍為0-127)" + _
Chr(13) & Chr(10) + _
" 小心,該操作可能會破壞整個系統! ", "CY7C63001設置", "46")
If (RamAddress = "") Then
Exit Sub
Else
If (Not IsNumeric(RamAddress) Or Val(RamAddress) < 0 Or Val(RamAddress) > 127) Then
MsgBox "CY7C63001 RAM地址的范圍為0-127", 16, "RAM錯誤"
Exit Sub
End If
End If
RamData = InputBox(" 請輸入要寫入該RAM地址的數值: " + _
Chr(13) & Chr(10) + _
" (取值范圍為0-255)" + _
Chr(13) & Chr(10) + _
" 小心,該操作可能會破壞整個系統! ", "CY7C63001設置", "1")
If (RamData = "") Then
Exit Sub
Else
If (Not IsNumeric(RamData) Or Val(RamData) < 0 Or Val(RamData) > 255) Then
MsgBox "CY7C63001 RAM地址" + RamAddress + "處的取值范圍為0-255", 16, "RAM錯誤"
Exit Sub
End If
End If
DevicePathName = "\\.\Cyusb-0"
If (OpenDevice(HidDevice, DevicePathName) = True) Then
myRequest.bRequest = &H3
myRequest.wValue = Val(RamAddress)
myRequest.wIndex = Val(RamData)
myRequest.wLength = &H8
myRequest.bData = &H0
myRequest.direction = &H1
bResult = DeviceIoControl _
(HidDevice, _
IOCTL_Cyusb_VENDOR_REQUEST, _
myRequest, _
10, _
ReData(0), _
8, _
nBytes, _
0)
If (bResult = True) Then
MsgBox "向RAM地址" + RamAddress + "處寫入了值" + RamData, , "寫入成功"
CloseHandle (HidDevice)
Else
MsgBox " 與USB設備通信失敗!" + _
Chr(13) & Chr(10) + _
"USB數據傳輸錯誤,請重新啟動硬件!", _
16, "RAM錯誤"
CloseHandle (HidDevice)
Unload Form1
End
End If
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim DrawStyle As Integer
Dim DrawWidth As Integer
Dim FontSize As Integer
Dim ForeColor As Integer
IOCTL_Cyusb_GET_DEVICE_DESCRIPTOR = CTL_CODE(FILE_DEVICE_UNKNOWN, Cyusb_IOCTL_INDEX + 1, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_Cyusb_GET_CONFIGURATION_DESCRIPTOR = CTL_CODE(FILE_DEVICE_UNKNOWN, Cyusb_IOCTL_INDEX + 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_Cyusb_GET_STRING_DESCRIPTOR = CTL_CODE(FILE_DEVICE_UNKNOWN, Cyusb_IOCTL_INDEX + 3, METHOD_BUFFERED, FILE_ANY_ACCESS)
IOCTL_Cyusb_VENDOR_REQUEST = CTL_CODE(FILE_DEVICE_UNKNOWN, Cyusb_IOCTL_INDEX + 4, METHOD_BUFFERED, FILE_ANY_ACCESS)
DrawStyle = 2
DrawWidth = 1
FontSize = 8
ForeColor = QBColor(4)
MinTemper = 0
MaxTemper = 70
TemperScale = (Shape4.Height - 50) / (MaxTemper - MinTemper - 1)
DrawScale = (Shape4.Height - 50) / 7
Option4.Value = True
Command1.Visible = True
Command2.Visible = False
Command18.Enabled = False
Command19.Enabled = True
Command17.Enabled = False
Form1.Width = 1960
PushBut = 1
Form1.Show
If (Initialize() = True) Then
Form1.Shape6.Height = (MaxTemper - CurTemper) * TemperScale
Form1.Caption = Str(CurTemper) + " ℃"
If (CurTemper < TLowtemper) Then
Image1.Picture = Image3.Picture
End If
If (CurTemper > THightemper) Then
Image2.Picture = Image4.Picture
End If
Command18_Click
Timer2.Enabled = False
Timer1.Enabled = True
End If
End Sub
Private Sub Option4_Click()
Dim i As Integer
Cls
Label2.Caption = "℃"
For i = 0 To 7
Line (Shape4.Left - 150, Shape4.Top + Shape4.Height - 50 - DrawScale * i)-Step(150, 0), RGB(255, 0, 0)
CurrentX = Shape4.Left - 150 - TextWidth(Str(i * 10)) - 20
CurrentY = Shape4.Top + Shape4.Height - 50 - DrawScale * i - TextHeight(Str(i * 10)) / 2
Print i * 10
Next i
Form1.Caption = Str(CurTemper) + " ℃"
End Sub
Private Sub Option5_Click()
Dim i As Integer
Cls
Label2.Caption = "℉"
For i = 0 To 7
Line (Shape4.Left - 150, Shape4.Top + Shape4.Height - 50 - DrawScale * i)-Step(150, 0), RGB(255, 0, 0)
CurrentX = Shape4.Left - 150 - TextWidth(Str((i * 10) * 9 / 5 + 32)) - 20
CurrentY = Shape4.Top + Shape4.Height - 50 - DrawScale * i - TextHeight(Str((i * 10) * 9 / 5 + 32)) / 2
Print (i * 10) * 9 \ 5 + 32
Next i
Form1.Caption = Str(CurTemper * 9 / 5 + 32) + " ℉"
End Sub
Private Sub Timer1_Timer()
Dim myRequest As VENDOR_REQUEST_IN
Dim bResult As Boolean
Dim ReData(8) As Byte
Dim nBytes As Long
Dim HidDevice As Long
Dim DevicePathName As String
DevicePathName = "\\.\Cyusb-0"
If (OpenDevice(HidDevice, DevicePathName) = True) Then
myRequest.bRequest = &H6
myRequest.wValue = &H1
myRequest.wIndex = &H0
myRequest.wLength = &H8
myRequest.bData = &H0
myRequest.direction = &H1
bResult = DeviceIoControl _
(HidDevice, _
IOCTL_Cyusb_VENDOR_REQUEST, _
myRequest, _
10, _
ReData(0), _
8, _
nBytes, _
0)
If (bResult = True) Then
CurTemper = ReData(2) / 2
Shape6.Height = (MaxTemper - CurTemper) * TemperScale
If (Option4.Value = True) Then
Form1.Caption = Str(CurTemper) + " ℃"
Else
Form1.Caption = Str(CurTemper * 9 / 5 + 32) + " ℉"
End If
If (ReData(3) <> PushBut) Then
PushBut = ReData(3)
If (Option4.Value = True) Then
Option5.Value = True
Form1.Caption = Str(CurTemper * 9 / 5 + 32) + " ℉"
Else
Option4.Value = True
Form1.Caption = Str(CurTemper) + " ℃"
End If
End If
If (CurTemper < TLowtemper) Then
Image1.Picture = Image3.Picture
Else
Image1.Picture = LoadPicture("")
End If
If (CurTemper > THightemper) Then
Image2.Picture = Image4.Picture
Else
Image2.Picture = LoadPicture("")
End If
CloseHandle (HidDevice)
Else
Form1.Shape6.Height = (MaxTemper - 0) * TemperScale
Form1.Image1.Picture = LoadPicture("")
Form1.Image2.Picture = LoadPicture("")
MsgBox " 與USB設備通信失敗!" + _
Chr(13) & Chr(10) + _
"USB數據傳輸錯誤,請重新啟動硬件!", _
16, "CurTemper錯誤"
CloseHandle (HidDevice)
Unload Form1
End
End If
End If
End Sub
Private Sub Timer2_Timer()
Dim HidDevice As Long
Dim DevicePathName As String
DevicePathName = "\\.\Cyusb-0"
HidDevice = CreateFile _
(DevicePathName, _
GENERIC_WRITE, _
FILE_SHARE_WRITE, _
0, _
OPEN_EXISTING, _
0, _
0)
If (HidDevice <> INVALID_HANDLE_VALUE) Then
CloseHandle (HidDevice)
Initialize
Command18.Enabled = False
Command19.Enabled = True
Command17.Enabled = False
Form1.Caption = "正在通信..."
Form1.Timer1.Enabled = True
Form1.Timer2.Enabled = False
End If
End Sub
?? 快捷鍵說明
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -