VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form frmLowLevel 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Low-Level Interface Access"
   ClientHeight    =   4920
   ClientLeft      =   4860
   ClientTop       =   2850
   ClientWidth     =   5190
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmLowLevel.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4920
   ScaleWidth      =   5190
   Begin VB.CommandButton cmdAll 
      Caption         =   "All O&ff"
      Enabled         =   0   'False
      Height          =   315
      Index           =   1
      Left            =   4275
      TabIndex        =   35
      Top             =   2490
      Width           =   840
   End
   Begin VB.CommandButton cmdAll 
      Caption         =   "All O&n"
      Enabled         =   0   'False
      Height          =   315
      Index           =   0
      Left            =   4275
      TabIndex        =   34
      Top             =   2070
      Width           =   840
   End
   Begin VB.CommandButton cmdReset 
      Caption         =   "&Reset"
      Enabled         =   0   'False
      Height          =   330
      Left            =   2130
      TabIndex        =   33
      Top             =   810
      Width           =   1155
   End
   Begin MSCommLib.MSComm MSComPort 
      Left            =   3645
      Top             =   615
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "&Cancel"
      Height          =   330
      Left            =   1710
      TabIndex        =   3
      Top             =   4485
      Width           =   1155
   End
   Begin VB.CommandButton cmdConnect 
      Caption         =   "Co&nnect"
      Default         =   -1  'True
      Height          =   330
      Left            =   360
      TabIndex        =   2
      Top             =   4485
      Width           =   1155
   End
   Begin VB.CheckBox chkTestVolts 
      Caption         =   "+5v Test Power"
      Enabled         =   0   'False
      Height          =   285
      Left            =   195
      TabIndex        =   1
      Top             =   825
      Width           =   1485
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   23
      Left            =   375
      TabIndex        =   32
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   22
      Left            =   675
      TabIndex        =   31
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   21
      Left            =   975
      TabIndex        =   30
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   20
      Left            =   1275
      TabIndex        =   29
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   19
      Left            =   1575
      TabIndex        =   28
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   18
      Left            =   1875
      TabIndex        =   27
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   17
      Left            =   2175
      TabIndex        =   26
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   16
      Left            =   2475
      TabIndex        =   25
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   15
      Left            =   2775
      TabIndex        =   24
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   14
      Left            =   3075
      TabIndex        =   23
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   13
      Left            =   3375
      TabIndex        =   22
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   12
      Left            =   3675
      TabIndex        =   21
      Top             =   1305
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   11
      Left            =   3675
      TabIndex        =   20
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   10
      Left            =   3375
      TabIndex        =   19
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   9
      Left            =   3075
      TabIndex        =   18
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   8
      Left            =   2775
      TabIndex        =   17
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   7
      Left            =   2475
      TabIndex        =   16
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   6
      Left            =   2175
      TabIndex        =   15
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   5
      Left            =   1875
      TabIndex        =   14
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   4
      Left            =   1575
      TabIndex        =   13
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   3
      Left            =   1275
      TabIndex        =   12
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   2
      Left            =   975
      TabIndex        =   11
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   1
      Left            =   675
      TabIndex        =   10
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label lblPin 
      Appearance      =   0  'Flat
      BackColor       =   &H80000004&
      BorderStyle     =   1  'Fixed Single
      ForeColor       =   &H80000008&
      Height          =   675
      Index           =   0
      Left            =   375
      TabIndex        =   9
      Top             =   3465
      Width           =   285
   End
   Begin VB.Label Label6 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "24"
      Height          =   195
      Left            =   435
      TabIndex        =   8
      Top             =   2055
      Width           =   180
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "13"
      Height          =   195
      Left            =   3705
      TabIndex        =   7
      Top             =   2070
      Width           =   180
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "12"
      Height          =   195
      Left            =   3720
      TabIndex        =   6
      Top             =   3195
      Width           =   180
   End
   Begin VB.Label Label3 
      BackStyle       =   0  'Transparent
      Caption         =   "1"
      Height          =   210
      Left            =   465
      TabIndex        =   5
      Top             =   3195
      Width           =   165
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "All pins are configures as outputs. Clicking on a pin toggles it's logic status."
      Height          =   465
      Left            =   735
      TabIndex        =   4
      Top             =   2490
      Width           =   2970
   End
   Begin VB.Shape Shape2 
      BorderWidth     =   3
      FillStyle       =   0  'Solid
      Height          =   855
      Left            =   180
      Top             =   2295
      Width           =   285
   End
   Begin VB.Shape Shape1 
      BorderWidth     =   3
      FillColor       =   &H00C0C0C0&
      FillStyle       =   0  'Solid
      Height          =   1485
      Left            =   150
      Top             =   1980
      Width           =   3975
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   $"frmLowLevel.frx":000C
      Height          =   885
      Left            =   75
      TabIndex        =   0
      Top             =   60
      Width           =   4485
   End
End
Attribute VB_Name = "frmLowLevel"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private ComPort                                 As MSComm

Private Const Module_Name                       As String = "frmLowLevel"
Private Sub Image1_Click()

End Sub


Private Sub Command1_Click()

End Sub


Private Sub LowLevelReset()

    Dim F                           As Integer
    
    
    Call Device_Reset(ComPort)
    
    ' All ports output
    Call Device_SendConfigBits(ComPort, "000000000000000000000000")

    For F = 0 To lblPin.Count - 1
        lblPin(F).BackColor = &H8000000F
        lblPin(F).Tag = "0" ' Low
    Next F
    
    chkTestVolts.Value = vbUnchecked
End Sub

Private Sub UpdateDisplay(ByRef Pattern As String)

    Dim F                       As Integer
    
    
    For F = 0 To lblPin.Count - 1
        With lblPin(F)
            Select Case Mid$(Pattern, F + 1, 1)
            Case "0"
                .BackColor = &H8000000F
                .Tag = "0"
                
            Case Else
                .BackColor = &HFF00&
                .Tag = "1"
            End Select
        End With
    Next F
    
End Sub

Private Sub chkTestVolts_Click()

    If chkTestVolts.Value = vbChecked Then
        Device_TestPowerOn ComPort
    Else
        Call LowLevelReset
    End If

End Sub

Private Sub cmdAll_Click(Index As Integer)

    Dim sStatus                         As String
    
    
    Select Case Index
    Case 0 ' All On
        sStatus = String$(24, "1")
    
    Case 1 ' All Off
        sStatus = String$(24, "0")
        
    End Select
    
    Call UpdateDisplay(sStatus)
    
    Call Device_SendDataBits(ComPort, sStatus)
    
End Sub

Private Sub cmdCancel_Click()

    On Error Resume Next ' Were terminating this form so we don't care about errors
    
    Device_Reset ComPort
    Device_ClosePort ComPort
    
    Set ComPort = Nothing
    Unload Me
    
End Sub

Private Sub cmdConnect_Click()
    
    Const PROC_NAME         As String = "cmdConnect_Click"
    On Error GoTo ErrorHandler
        
    gtypModel.NumPins = 24
    
    Set ComPort = MSComPort
    
    '
    ' Open comms port

    Call Device_OpenPort(ComPort) ' This often causes Datacomms Error on the PIC !
    
    '
    ' Make sure there nothing in the RX buffer
    Device_FlushBuffer MSComPort
    
    Call LowLevelReset
    
    cmdConnect.Enabled = False
    chkTestVolts.Enabled = True
    cmdReset.Enabled = True
    cmdAll(0).Enabled = True
    cmdAll(1).Enabled = True
    
    Exit Sub
    
ErrorHandler:
    Device_ClosePort ComPort
    ErrorRoutine Module_Name, PROC_NAME, Err
    Resume 0
End Sub


Private Sub cmdReset_Click()

    Call LowLevelReset
    
End Sub


Private Sub lblPin_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Dim F                               As Integer
    Dim sStatus                         As String
    

    If chkTestVolts.Enabled = True Then
    
        Select Case Button
        Case vbRightButton
            lblPin(Index).BackColor = QBColor(12) ' Red
        
        Case vbLeftButton
            With lblPin(Index)
                Select Case .Tag
                Case "1"
                    ' High, so set Low
                    .BackColor = &H8000000F
                    .Tag = "0"
                    
                Case Else
                    ' Low, so set High
                    .BackColor = &HFF00&
                    .Tag = "1"
                End Select
                
                sStatus = ""
                For F = 0 To 23
                    If lblPin(F).Tag = "1" Then
                        sStatus = sStatus & "1"
                    Else
                        sStatus = sStatus & "0"
                    End If
                Next F
                
                '
                ' Now, re-send status
                Device_SendDataBits ComPort, sStatus
            End With
            
        End Select
    End If
    
End Sub


