⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 USB2.0原理与工程开发光盘(第一版和第二版)
💻 FRM
📖 第 1 页 / 共 4 页
字号:
        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, _
              OverLap)
    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, _
              OverLap)
    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, _
              OverLap)
    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, _
              OverLap)
    
    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, _
              SecAttr, _
              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 + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -