VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "mscomm32.ocx"
Begin VB.Form frmMain 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Demo Application"
   ClientHeight    =   5535
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   11385
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5535
   ScaleWidth      =   11385
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame3 
      Caption         =   "Functions"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1575
      Left            =   120
      TabIndex        =   18
      Top             =   3240
      Width           =   5055
      Begin VB.TextBox txtFreq 
         Alignment       =   2  'Center
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1680
         TabIndex        =   23
         Top             =   960
         Width           =   1575
      End
      Begin VB.CommandButton btnSetFreq 
         Caption         =   "Set Freq"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   120
         TabIndex        =   22
         Top             =   960
         Width           =   1455
      End
      Begin VB.CommandButton btnZeroSensor 
         Caption         =   "Zero Sensor"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3360
         TabIndex        =   21
         Top             =   360
         Width           =   1575
      End
      Begin VB.CommandButton btnGetFreq 
         Caption         =   "Get Freq"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1680
         TabIndex        =   20
         Top             =   360
         Width           =   1575
      End
      Begin VB.CommandButton btnGetPower 
         Caption         =   "Get Power"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   120
         TabIndex        =   19
         Top             =   360
         Width           =   1455
      End
      Begin VB.Label Label7 
         Caption         =   "GHz"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3480
         TabIndex        =   24
         Top             =   1080
         Width           =   495
      End
   End
   Begin VB.CommandButton btnClose 
      Caption         =   "Close"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   120
      TabIndex        =   11
      Top             =   4920
      Width           =   5055
   End
   Begin VB.Frame Frame2 
      Caption         =   "Setup Com Port"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   975
      Left            =   120
      TabIndex        =   6
      Top             =   120
      Width           =   5055
      Begin VB.CommandButton btnResetComPort 
         Caption         =   "Reset"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3600
         TabIndex        =   10
         Top             =   360
         Width           =   1335
      End
      Begin VB.TextBox txtCOMPORTNo 
         Alignment       =   2  'Center
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   360
         Left            =   1320
         TabIndex        =   8
         Top             =   360
         Width           =   735
      End
      Begin VB.CommandButton btnInitializeComPort 
         Caption         =   "Initialize"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   2160
         TabIndex        =   7
         Top             =   360
         Width           =   1335
      End
      Begin VB.Label lblComPortNo 
         Caption         =   "ComPortNo:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   120
         TabIndex        =   9
         Top             =   360
         Width           =   1215
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Data I/O"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1695
      Left            =   120
      TabIndex        =   0
      Top             =   1320
      Width           =   5055
      Begin VB.TextBox txtReceived 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1320
         TabIndex        =   5
         Top             =   1080
         Width           =   2775
      End
      Begin VB.CommandButton btnSend 
         Caption         =   "Send"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   2760
         TabIndex        =   3
         Top             =   480
         Width           =   1335
      End
      Begin VB.TextBox txtCommand 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   1320
         TabIndex        =   2
         Top             =   480
         Width           =   1335
      End
      Begin VB.Label lblReceive 
         Caption         =   "Received:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         TabIndex        =   4
         Top             =   1080
         Width           =   975
      End
      Begin VB.Label lblSend 
         Caption         =   "Command:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         TabIndex        =   1
         Top             =   480
         Width           =   975
      End
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   10680
      Top             =   4800
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Label Label9 
      Caption         =   "(6) Click Close button to exit application. This will send STOP                command to the sensor and close the com port."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   5280
      TabIndex        =   26
      Top             =   3360
      Width           =   5775
   End
   Begin VB.Label Label8 
      Caption         =   "(5) Use function group to exercise sensor commands."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5280
      TabIndex        =   25
      Top             =   2880
      Width           =   5775
   End
   Begin VB.Label Label6 
      Caption         =   $"MainForm.frx":0000
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   5280
      TabIndex        =   17
      Top             =   4080
      Width           =   5775
   End
   Begin VB.Label Label5 
      Caption         =   "(4) Reset button will close the com port connection."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5280
      TabIndex        =   16
      Top             =   2400
      Width           =   5775
   End
   Begin VB.Label Label4 
      Caption         =   "(3) Received text box will display data received from the sensor."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5280
      TabIndex        =   15
      Top             =   1920
      Width           =   5775
   End
   Begin VB.Label Label3 
      Caption         =   "(2) Type command and click on Send button."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5280
      TabIndex        =   14
      Top             =   1440
      Width           =   5655
   End
   Begin VB.Label Label2 
      Caption         =   $"MainForm.frx":008B
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   5280
      TabIndex        =   13
      Top             =   720
      Width           =   6135
   End
   Begin VB.Label Label1 
      Caption         =   "Instructions:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   5280
      TabIndex        =   12
      Top             =   240
      Width           =   3615
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public gstrInputBuffer As String

'Event handler for InitializeComPort button
Private Sub btnInitializeComPort_Click()
    Call SetCommPort(Val(Trim(txtCOMPORTNo.Text)))
End Sub
'Subroutine to set the com port
Public Sub SetCommPort(portNo As Integer)
    On Error GoTo errHndler
        'Setup MSComm control
        MSComm1.Settings = "115200,n,8,1"
        MSComm1.CommPort = Trim(txtCOMPORTNo.Text)
        MSComm1.PortOpen = True
        MSComm1.RThreshold = 1
        MSComm1.SThreshold = 1
        '
        'Wait for half a second before sending START command
        Delay (0.5)
        'Arm sensor to start making measurements
        txtCommand.Text = "START"
        Call btnSend_Click
        '
        Exit Sub
errHndler:
        MsgBox ("ERROR: " & Err.Description)
End Sub

'Event handler for ResetComPort button
Private Sub btnResetComPort_Click()
    'Close com port
    If MSComm1.PortOpen = True Then
       MSComm1.PortOpen = False
    End If
End Sub

'Event handler for Send button
Private Sub btnSend_Click()
  Dim strResult As String
    'Clear buffer & receive text window before sending command
    gstrInputBuffer = ""
    txtReceived.Text = ""
    'Send command and appeand Termination character, 0x0A(10)with it.
    MSComm1.Output = UCase(txtCommand.Text) & Chr(10)
    'Display received result on the Received text box
    txtReceived.Text = strResult
    '
End Sub
'
'Event handler for MSComm1 event
Private Sub MSComm1_OnComm()
    'Get data from Input buffer
    gstrInputBuffer = MSComm1.Input
    'Display received result on the Received text box
    txtReceived.Text = gstrInputBuffer
End Sub

'Event handler for GetFreq button
Private Sub btnGetFreq_Click()
    txtCommand.Text = "FREQ?"
    Call btnSend_Click
End Sub

'Event handler for GetPower button
Private Sub btnGetPower_Click()
    txtCommand.Text = "PWR?"
    Call btnSend_Click
End Sub

'Event handler for SetFreq button
Private Sub btnSetFreq_Click()
    txtCommand.Text = "FREQ " & txtFreq.Text
    Call btnSend_Click
End Sub

'Event handler for ZeroSensor button
Private Sub btnZeroSensor_Click()
    txtCommand.Text = "ZERO"
    Call btnSend_Click
    'Sensor will return OK after about 19 Seconds
End Sub

'Event handler for Close button
Private Sub btnClose_Click()
'
    'Make sure we close the com port before we exit the app
    If MSComm1.PortOpen = True Then
        'Stop sensor from making measurements
        txtCommand.Text = "STOP"
        Call btnSend_Click
        '
        'Wait for half a second after sending START command
        Delay (0.5)
        '
        MSComm1.PortOpen = False
    End If
    'Close the app
    End
End Sub

'Delay routine
Public Sub Delay(ByVal Seconds As Single)
    '
    Dim fStartTimer As Single
    Dim fFinish     As Single
    '
    fStartTimer = Timer
    '
    Do
        DoEvents
        fFinish = Timer
        If Abs(fFinish - fStartTimer) > Seconds Then
            Exit Do
        End If
    Loop
    '
End Sub

