www.pudn.com > the PC Host examples .zip > Temperature.frm


VERSION 5.00 
Begin VB.Form DisplayWindow  
   BackColor       =   &H00FF8080& 
   Caption         =   "USB Design By Example: Thermometer Examples" 
   ClientHeight    =   5595 
   ClientLeft      =   60 
   ClientTop       =   345 
   ClientWidth     =   8475 
   FillColor       =   &H00FFFFFF& 
   FillStyle       =   0  'Solid 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   5595 
   ScaleWidth      =   8475 
   StartUpPosition =   3  'Windows Default 
   Begin VB.Timer Timer1  
      Interval        =   200 
      Left            =   7920 
      Top             =   120 
   End 
   Begin VB.TextBox UpperLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   5 
      Left            =   5520 
      MaxLength       =   2 
      TabIndex        =   24 
      Text            =   "25" 
      Top             =   4800 
      Width           =   1215 
   End 
   Begin VB.TextBox UpperLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   4 
      Left            =   5520 
      MaxLength       =   2 
      TabIndex        =   23 
      Text            =   "70" 
      Top             =   4200 
      Width           =   1215 
   End 
   Begin VB.TextBox UpperLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   3 
      Left            =   5520 
      MaxLength       =   2 
      TabIndex        =   22 
      Text            =   "25" 
      Top             =   3600 
      Width           =   1215 
   End 
   Begin VB.TextBox UpperLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   2 
      Left            =   5520 
      MaxLength       =   2 
      TabIndex        =   21 
      Text            =   "25" 
      Top             =   3000 
      Width           =   1215 
   End 
   Begin VB.TextBox UpperLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   1 
      Left            =   5520 
      MaxLength       =   2 
      TabIndex        =   20 
      Text            =   "25" 
      Top             =   2400 
      Width           =   1215 
   End 
   Begin VB.TextBox UpperLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   0 
      Left            =   5520 
      MaxLength       =   2 
      TabIndex        =   19 
      Text            =   "25" 
      Top             =   1800 
      Width           =   1215 
   End 
   Begin VB.TextBox LowerLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   5 
      Left            =   2880 
      MaxLength       =   2 
      TabIndex        =   18 
      Text            =   "15" 
      Top             =   4800 
      Width           =   1215 
   End 
   Begin VB.TextBox LowerLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   4 
      Left            =   2880 
      MaxLength       =   2 
      TabIndex        =   17 
      Text            =   "40" 
      Top             =   4200 
      Width           =   1215 
   End 
   Begin VB.TextBox LowerLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   3 
      Left            =   2880 
      MaxLength       =   2 
      TabIndex        =   16 
      Text            =   "15" 
      Top             =   3600 
      Width           =   1215 
   End 
   Begin VB.TextBox LowerLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   2 
      Left            =   2880 
      MaxLength       =   2 
      TabIndex        =   15 
      Text            =   "20" 
      Top             =   3000 
      Width           =   1215 
   End 
   Begin VB.TextBox LowerLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   1 
      Left            =   2880 
      MaxLength       =   2 
      TabIndex        =   14 
      Text            =   "15" 
      Top             =   2400 
      Width           =   1215 
   End 
   Begin VB.TextBox LowerLimit  
      Alignment       =   2  'Center 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   0 
      Left            =   2880 
      MaxLength       =   2 
      TabIndex        =   13 
      Text            =   "15" 
      Top             =   1800 
      Width           =   1215 
   End 
   Begin VB.TextBox Temperature  
      Alignment       =   2  'Center 
      Enabled         =   0   'False 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   5 
      Left            =   4200 
      TabIndex        =   12 
      Text            =   "19" 
      Top             =   4800 
      Width           =   1215 
   End 
   Begin VB.TextBox Temperature  
      Alignment       =   2  'Center 
      Enabled         =   0   'False 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   4 
      Left            =   4200 
      TabIndex        =   11 
      Text            =   "56" 
      Top             =   4200 
      Width           =   1215 
   End 
   Begin VB.TextBox Temperature  
      Alignment       =   2  'Center 
      Enabled         =   0   'False 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   3 
      Left            =   4200 
      TabIndex        =   10 
      Text            =   "19" 
      Top             =   3600 
      Width           =   1215 
   End 
   Begin VB.TextBox Temperature  
      Alignment       =   2  'Center 
      Enabled         =   0   'False 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   2 
      Left            =   4200 
      TabIndex        =   9 
      Text            =   "26" 
      Top             =   3000 
      Width           =   1215 
   End 
   Begin VB.TextBox Temperature  
      Alignment       =   2  'Center 
      Enabled         =   0   'False 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   1 
      Left            =   4200 
      TabIndex        =   8 
      Text            =   "22" 
      Top             =   2400 
      Width           =   1215 
   End 
   Begin VB.TextBox Temperature  
      Alignment       =   2  'Center 
      Enabled         =   0   'False 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   18 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      Height          =   495 
      Index           =   0 
      Left            =   4200 
      TabIndex        =   7 
      Text            =   "20" 
      Top             =   1800 
      Width           =   1215 
   End 
   Begin VB.Shape Alarm  
      FillColor       =   &H000000FF& 
      FillStyle       =   0  'Solid 
      Height          =   495 
      Index           =   5 
      Left            =   7200 
      Shape           =   3  'Circle 
      Top             =   4800 
      Width           =   495 
   End 
   Begin VB.Shape Alarm  
      FillColor       =   &H000000FF& 
      FillStyle       =   0  'Solid 
      Height          =   495 
      Index           =   4 
      Left            =   7200 
      Shape           =   3  'Circle 
      Top             =   4200 
      Width           =   495 
   End 
   Begin VB.Shape Alarm  
      FillColor       =   &H000000FF& 
      FillStyle       =   0  'Solid 
      Height          =   495 
      Index           =   3 
      Left            =   7200 
      Shape           =   3  'Circle 
      Top             =   3600 
      Width           =   495 
   End 
   Begin VB.Shape Alarm  
      FillColor       =   &H000000FF& 
      FillStyle       =   0  'Solid 
      Height          =   495 
      Index           =   2 
      Left            =   7200 
      Shape           =   3  'Circle 
      Top             =   3000 
      Width           =   495 
   End 
   Begin VB.Shape Alarm  
      FillColor       =   &H000000FF& 
      FillStyle       =   0  'Solid 
      Height          =   495 
      Index           =   1 
      Left            =   7200 
      Shape           =   3  'Circle 
      Top             =   2400 
      Width           =   495 
   End 
   Begin VB.Label Heading  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Upper" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   14.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   375 
      Index           =   1 
      Left            =   5520 
      TabIndex        =   26 
      Top             =   1320 
      Width           =   1215 
   End 
   Begin VB.Label Heading  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Lower" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   14.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   375 
      Index           =   0 
      Left            =   2880 
      TabIndex        =   25 
      Top             =   1320 
      Width           =   1215 
   End 
   Begin VB.Shape Alarm  
      FillColor       =   &H000000FF& 
      FillStyle       =   0  'Solid 
      Height          =   495 
      Index           =   0 
      Left            =   7200 
      Shape           =   3  'Circle 
      Top             =   1800 
      Width           =   495 
   End 
   Begin VB.Label Title  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Adding Temperature Limits" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   24 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   1095 
      Left            =   0 
      TabIndex        =   6 
      Top             =   360 
      Width           =   8535 
   End 
   Begin VB.Label Label  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Sensor 6" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   20.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   615 
      Index           =   5 
      Left            =   600 
      TabIndex        =   5 
      Top             =   4800 
      Width           =   1935 
   End 
   Begin VB.Label Label  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Sensor 5" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   20.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   615 
      Index           =   4 
      Left            =   600 
      TabIndex        =   4 
      Top             =   4200 
      Width           =   1935 
   End 
   Begin VB.Label Label  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Sensor 4" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   20.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   615 
      Index           =   3 
      Left            =   600 
      TabIndex        =   3 
      Top             =   3600 
      Width           =   1935 
   End 
   Begin VB.Label Label  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Sensor 3" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   20.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   615 
      Index           =   2 
      Left            =   600 
      TabIndex        =   2 
      Top             =   3000 
      Width           =   1935 
   End 
   Begin VB.Label Label  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Sensor 2" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   20.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   615 
      Index           =   1 
      Left            =   600 
      TabIndex        =   1 
      Top             =   2400 
      Width           =   1935 
   End 
   Begin VB.Label Label  
      Alignment       =   2  'Center 
      BackStyle       =   0  'Transparent 
      Caption         =   "Sensor 1" 
      BeginProperty Font  
         Name            =   "Arial Rounded MT Bold" 
         Size            =   20.25 
         Charset         =   0 
         Weight          =   700 
         Underline       =   0   'False 
         Italic          =   0   'False 
         Strikethrough   =   0   'False 
      EndProperty 
      ForeColor       =   &H00FFFFFF& 
      Height          =   615 
      Index           =   0 
      Left            =   480 
      TabIndex        =   0 
      Top             =   1800 
      Width           =   2175 
   End 
End 
Attribute VB_Name = "DisplayWindow" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
' This example operates a little differently than described in Chapter 9 (it's simpler) 
' Both examples (Reading Temperatures and Adding Temperature Limits) use the same code, 
' only the display is different. 
' Every 200msec the Lower and Upper Limits are downloaded to the IO Device which replys 
' with the current temperatures and an ALARM byte [Bit 0 = Alarm(0), Bit(1) = Alarm(1), etc] 
' 
' For ease of display the temperature ranges are restricted 00 to 99 (you can change this) 
' 
Private Limits As Boolean ' Choose between Example 1 or 2 
Private Red, Black As Long 
 
Private Sub Form_Load() 
' This module contains both Thermometer examples, set "Limits" = TRUE for example 2 
Limits = True 
Red = RGB(255, 0, 0): Black = RGB(0, 0, 0) ' Initialize my ALARM colors 
If Not Limits Then ' Hide all of the extra display for example 2 
    For i% = 0 To 5: LowerLimit(i%).Visible = False: UpperLimit(i%).Visible = False: Alarm(i%).Visible = False: Next i% 
    Heading(0).Visible = False: Heading(1).Visible = False 
    Title.Caption = "Reading Temperatures" 
    End If 
End Sub 
 
Private Sub Timer1_Timer() 
' Update Limits and check for temperature changes every 200msec 
Dim Temperatures(6) As Byte ' Note Temperature(6) is the ALARM indicator 
Dim Alarms As Byte: Dim Buffer(11) As Byte 
For i% = 0 To 5: Buffer(i%) = Val(LowerLimit(i%).Text): Buffer(6 + i%) = Val(UpperLimit(i%).Text): Next i% 
Call WriteUSBdevice(AddressFor(Buffer(0)), 12)  'Update limits 
Call ReadUSBdevice(AddressFor(Temperatures(0)), 7) ' Read current temperature 
'For i% = 0 To 5: Temperatures(i%) = ((i% + 2) * 10) + i%: Next i%: Temperatures(6) = &H39 
Alarms = Temperatures(6) 
For i% = 0 To 5 ' Update temperature display and show ALARMs if present 
    Temperature(i%).Text = TwoDecimalCharacters$(Temperatures(i%)) 
    If ((Alarms And 1) = 1) And (Alarm(i%).FillColor = Black) Then Alarm(i%).FillColor = Red 
    If ((Alarms And 1) = 0) And (Alarm(i%).FillColor = Red) Then Alarm(i%).FillColor = Black 
    Alarms = (Alarms And &HFE) / 2 ' Clear Bit 0 before divide 
    Next i% 
' NOTE: a real program would do something significant when an ALARM was detected 
End Sub