' 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