Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Text
Imports System.Windows.Forms
Imports System.IO
Imports Microsoft.VisualBasic

Public Class RgrTest_Tabbed
    Private Const DFLT_1_NUM_FMT As String = "###0.0###"
    Private Const DFLT_2_NUM_FMT As String = "###0.000"
    Private Const INVALID_RTN_VAL As Integer = 0
    Private Const MSG_PLEASE_WAIT As String = "...please wait..."
    Private Const MSG_OPT_ON As String = "On"
    Private Const MSG_OPT_OFF As String = "Off"
    Private Const MSG_TRUE As String = "True"
    Private Const MSG_FALSE As String = "False"
    Private Const MSG_ERROR As String = "Error"
    Private Const MSG_INIT_ERROR As String = "Error: Initialize sensor"
    Private Const MSG_TAKE_TRACE_ERROR As String = "Error: Take trace"
    Private Const MSG_SUCCESS As String = "Success"
    Private Const MSG_FAILURE As String = "Failure"
    Private Const MSG_YES As String = "Yes"
    Private Const MSG_NO As String = "No"
    Private Const MSG_CANCELLED As String = "Cancelled"
    Private Const MSG_SENSOR_TRYING_TO_INITALIZE As String = "...trying to initialize..."
    Private Const MSG_SENSOR_IS_NOT_CONNECTED As String = "Sensor is not connected"
    Private Const MSG_SENSOR_FAILED_TO_INITIALIZE As String = "Sensor failed to initilize"

    Public Structure OPTION_DATE
        Dim YEAR As Integer
        Dim MONTH As Integer
        Dim DAY As Integer
    End Structure

    Private sensDesc() As SDByte
    Private currAddr As Integer
    Private currIdx As Integer
    Private currSN As String = New String(Chr(0), 8)
    Private currMN As MODEL_NUMBER
    Private currConnType As CONN_TYPES
    Private currTriggerOpt As FEATURE_STATE
    Private currRecorderOutOpt As FEATURE_STATE
    Private currCalAndWtyOpt As FEATURE_STATE
    Private currFilterOpt As FEATURE_STATE
    Private currWtyExpDate As OPTION_DATE
    Private currCalExpDate As OPTION_DATE
    Private currCalDueDate As OPTION_DATE
    Private sbCopyString As StringBuilder
    Private tr(-1) As Double

    '=============================================
    'Top of Form - Sensor count, list sensors, etc
    '---------------------------------------------
    Private Sub btnLB_SensorCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SensorCount.Click
        lblLB_SensorCount.Text = LB_SensorCnt().ToString()
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub txtSerNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSerNo.TextChanged
        currSN = txtSerNo.Text.Trim
    End Sub

    Private Sub udIndex_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles udIndex.ValueChanged
        currIdx = CInt(udIndex.Value)
    End Sub

    Private Sub udAddress_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles udAddress.ValueChanged
        currAddr = CInt(udAddress.Value)
    End Sub

    Private Sub btnLB_SensorList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SensorList.Click
        Dim i As Integer
        Dim cnt As Integer = LB_SensorCnt()

        lstLB_SensorList.Items.Clear()

        If cnt > 0 Then
            ReDim sensDesc(cnt - 1)
            If LB_SensorList(sensDesc(0), cnt) >= 1 Then
                For i = sensDesc.GetLowerBound(0) To sensDesc.GetUpperBound(0)
                    lstLB_SensorList.Items.Add(String.Format("{0,3:d}     {1,3:d}     ", sensDesc(i).DeviceIndex, _
                            sensDesc(i).DeviceAddress) & sensDesc(i).SN())
                Next
            End If
        End If
    End Sub

    Private Sub lstLB_SensorList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstLB_SensorList.Click
        Dim rslt As Integer
        Dim lstIdx As Integer

        If chkAutoFill.Checked Then
            If Not IsNothing(sensDesc) Then
                If sensDesc.Length = lstLB_SensorList.Items.Count Then
                    lstIdx = lstLB_SensorList.SelectedIndex
                    If lstIdx >= 0 Then

                        currIdx = sensDesc(lstIdx).DeviceIndex
                        udIndex.Value = CDec(currIdx)

                        currAddr = sensDesc(lstIdx).DeviceAddress
                        udAddress.Value = CDec(currAddr)

                        currSN = sensDesc(lstIdx).SN()
                        txtSerNo.Text = currSN

                        rslt = LB_GetModelNumber_Addr(currAddr, currMN)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve model number")
                            Return
                        End If
                        lblCurrMN.Text = currMN.ToString

                        'get the option info and report it
                        rslt = LB_GetFilterOpt(currSN, currFilterOpt)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve filter option value")
                            Return
                        End If
                        lstOptions.Items.Add("Filter Option: " & IIf(currFilterOpt = FEATURE_STATE.ST_ON, MSG_OPT_ON, MSG_OPT_OFF))

                        rslt = LB_GetTriggerOpt(currSN, currTriggerOpt)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve trigger option value")
                            Return
                        End If
                        lstOptions.Items.Add("Trigger Option: " & IIf(currTriggerOpt = FEATURE_STATE.ST_ON, MSG_OPT_ON, MSG_OPT_OFF))

                        rslt = LB_GetRecorderOutOption(currSN, currRecorderOutOpt)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve recorder out option value")
                            Return
                        End If
                        lstOptions.Items.Add("Recorder Option: " & IIf(currRecorderOutOpt = FEATURE_STATE.ST_ON, MSG_OPT_ON, MSG_OPT_OFF))

                        rslt = LB_GetCalAndWtyOption(currSN, currCalAndWtyOpt)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve calibration and warranty option value")
                            Return
                        End If
                        lstOptions.Items.Add("Cal & Warranty Option: " & IIf(currCalAndWtyOpt = FEATURE_STATE.ST_ON, MSG_OPT_ON, MSG_OPT_OFF))

                        rslt = LB_GetCalOptExpDate(currSN, currCalExpDate.YEAR, currCalExpDate.MONTH, currCalExpDate.DAY)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve cal option expiration date")
                            Return
                        End If
                        lstOptions.Items.Add("Cal Option Exp Date: " & currCalExpDate.MONTH.ToString & "/" & currCalExpDate.DAY.ToString & "/" & currCalExpDate.YEAR.ToString)

                        rslt = LB_GetWtyOptExpDate(currSN, currWtyExpDate.YEAR, currWtyExpDate.MONTH, currWtyExpDate.DAY)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve cal option expiration date")
                            Return
                        End If
                        lstOptions.Items.Add("Warranty Option Exp Date: " & currWtyExpDate.MONTH.ToString & "/" & currWtyExpDate.DAY.ToString & "/" & currWtyExpDate.YEAR.ToString)

                        rslt = LB_GetCalDueDate(currSN, currCalDueDate.YEAR, currCalDueDate.MONTH, currCalDueDate.DAY)
                        If rslt <= INVALID_RTN_VAL Then
                            MessageBox.Show("Unable to retrieve cal option expiration date")
                            Return
                        End If
                        lstOptions.Items.Add("Cal Due Date: " & currCalDueDate.MONTH.ToString & "/" & currCalDueDate.DAY.ToString & "/" & currCalDueDate.YEAR.ToString)

                    End If
                End If
            End If
        End If
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        currSN = ""
        txtSerNo.Text = ""
        currAddr = -1
        udAddress.Value = -1
        currIdx = -1
        udIndex.Value = -1
        lstOptions.Items.Clear()
    End Sub

    '=====================================
    'FIRST TAB - Index & Address Functions
    '-------------------------------------
    Private Sub btnLB_GetAddress_Idx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetAddress_Idx.Click
        Dim rslt As Integer

        rslt = LB_GetAddress_Idx(currIdx)
        If rslt > 0 Then
            lblLB_GetAddress_Idx.Text = rslt.ToString
        Else
            lblLB_GetAddress_Idx.Text = MSG_ERROR
        End If
    End Sub

    Private Sub btnLB_GetAddress_SN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetAddress_SN.Click
        Dim rslt As Integer

        rslt = LB_GetAddress_SN(currSN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetAddress_SN.Text = rslt.ToString
        Else
            lblLB_GetAddress_SN.Text = MSG_ERROR
        End If
    End Sub

    Private Sub btnLB_SetAddress_Idx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetAddress_Idx.Click
        Dim rslt As Integer

        rslt = LB_SetAddress_Idx(currIdx, CInt(udLB_SetAddress_Idx_Address.Value))
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetAddress_Idx.Text = MSG_SUCCESS
        Else
            lblLB_SetAddress_Idx.Text = MSG_ERROR
        End If
    End Sub

    Private Sub btnLB_SetAddress_SN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetAddress_SN.Click
        Dim rslt As Integer

        rslt = LB_SetAddress_SN(currSN, CInt(udLB_SetAddress_Idx_Address.Value))
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetAddress_SN.Text = MSG_SUCCESS
        Else
            lblLB_SetAddress_SN.Text = MSG_ERROR
        End If
    End Sub

    Private Sub btnLB_ChangeAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_ChangeAddress.Click
        Dim rslt As Integer

        rslt = LB_ChangeAddress(currAddr, CInt(udLB_ChangeAddress_NewAddress.Value))
        If rslt > INVALID_RTN_VAL Then
            lblLB_ChangeAddress.Text = MSG_SUCCESS
        Else
            lblLB_ChangeAddress.Text = MSG_ERROR
        End If
    End Sub

    Private Sub btnLB_GetIndex_Addr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetIndex_Addr.Click
        Dim rslt As Integer

        rslt = LB_GetIndex_Addr(currAddr)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetIndex_Addr.Text = rslt.ToString
        Else
            lblLB_GetIndex_Addr.Text = MSG_ERROR
        End If
    End Sub

    Private Sub btnLB_GetIndex_SN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetIndex_SN.Click
        Dim rslt As Integer

        rslt = LB_GetIndex_SN(currSN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetIndex_SN.Text = rslt.ToString
        Else
            lblLB_GetIndex_SN.Text = MSG_ERROR
        End If
    End Sub

    Private Sub btnLB_AddressConflictExists_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_AddressConflictExists.Click
        Dim rslt As Integer

        rslt = LB_AddressConflictExists()
        If rslt > 0 Then
            lblLB_AddressConflictExists.Text = MSG_TRUE
        Else
            lblLB_AddressConflictExists.Text = MSG_FALSE
        End If
    End Sub

    Private Sub btnLB_WillAddressConflict_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_WillAddressConflict.Click
        Dim rslt As Integer

        rslt = LB_WillAddressConflict(CInt(udLB_WillAddressConflict.Value))
        If rslt > 0 Then
            lblLB_WillAddressConflict.Text = MSG_TRUE
        Else
            lblLB_WillAddressConflict.Text = MSG_FALSE
        End If
    End Sub

    Private Sub btnLB_GetSerNo_Idx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetSerNo_Idx.Click
        Dim rslt As Integer
        Dim tmpSN As String = New String(Chr(0), 255)    'make a buffer full of null characters...buffer needs to be at least 16 characters (just to be sure)

        rslt = LB_GetSerNo_Idx(currIdx, tmpSN)
        If rslt > 0 Then
            lblLB_GetSerNo_Idx.Text = MSG_SUCCESS & ": " & tmpSN.Substring(0, 6)        'serial number is first six characters
        Else
            lblLB_GetSerNo_Idx.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetSerNo_Addr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetSerNo_Addr.Click
        Dim rslt As Integer
        Dim tmpSN As String = New String(Chr(0), 255)    'make a buffer full of null characters...buffer needs to be at least 16 characters (just to be sure)

        rslt = LB_GetSerNo_Addr(currAddr, tmpSN)
        If rslt > 0 Then
            lblLB_GetSerNo_Addr.Text = MSG_SUCCESS & ": " & tmpSN.Substring(0, 6)     'serial number is first six characters
        Else
            lblLB_GetSerNo_Addr.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_DriverVersion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_DriverVersion.Click
        Dim rslt As Integer

        rslt = LB_DriverVersion()
        If rslt > INVALID_RTN_VAL Then
            lblLB_DriverVersion.Text = rslt.ToString
        Else
            lblLB_DriverVersion.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_BlinkLED_Idx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_BlinkLED_Idx.Click
        Dim rslt As Integer

        rslt = LB_BlinkLED_Idx(currIdx)
        If rslt > INVALID_RTN_VAL Then
            lblLB_BlinkLED_Idx.Text = MSG_SUCCESS
        Else
            lblLB_BlinkLED_Idx.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_BlinkLED_Addr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_BlinkLED_Addr.Click
        Dim rslt As Integer

        rslt = LB_BlinkLED_Addr(currAddr)
        If rslt > INVALID_RTN_VAL Then
            lblLB_BlinkLED_Addr.Text = MSG_SUCCESS
        Else
            lblLB_BlinkLED_Addr.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_BlinkLED_SN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_BlinkLED_SN.Click
        Dim rslt As Integer

        rslt = LB_BlinkLED_SN(currSN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_BlinkLED_SN.Text = MSG_SUCCESS
        Else
            lblLB_BlinkLED_SN.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetFirmwareVersion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetFirmwareVersion.Click
        Dim rslt As Integer
        Dim ver(20) As Byte

        rslt = LB_GetFirmwareVersion(currAddr, ver(0), ver.Length)
        If rslt > INVALID_RTN_VAL Then
            lblVersion.Text = Encoding.ASCII.GetString(ver)
        Else
            lblVersion.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetCalDueDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetCalDueDate.Click
        Dim rslt As Integer
        Dim yr As Integer = 0, mo As Integer = 0, da As Integer = 0

        rslt = LB_GetCalDueDate(currSN, yr, mo, da)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetCalDueDate.Text = mo.ToString & "/" & da.ToString & "/" & yr.ToString
        Else
            lblLB_GetCalDueDate.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetCalDueDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetCalDueDate.Click
        Dim rslt As Integer
        Dim yr As Integer = dtLB_SetCalDueDate.Value.Year Mod 100, mo As Integer = dtLB_SetCalDueDate.Value.Month, da As Integer = dtLB_SetCalDueDate.Value.Day

        rslt = LB_SetCalDueDate(currSN, yr, mo, da)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetCalDueDate.Text = MSG_SUCCESS
        Else
            lblLB_SetCalDueDate.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetModelNumber_SN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetModelNumber_SN.Click
        Dim rslt As Integer
        Dim tmpMN As MODEL_NUMBER

        rslt = LB_GetModelNumber_SN(currSN, tmpMN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetModelNumber_SN.Text = tmpMN.ToString
        Else
            lblLB_GetModelNumber_SN.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetModelNumber_Idx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetModelNumber_Idx.Click
        Dim rslt As Integer
        Dim tmpMN As MODEL_NUMBER

        rslt = LB_GetModelNumber_Idx(currIdx, tmpMN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetModelNumber_Idx.Text = tmpMN.ToString
        Else
            lblLB_GetModelNumber_Idx.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetModelNumber_Addr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetModelNumber_Addr.Click
        Dim rslt As Integer
        Dim tmpMN As MODEL_NUMBER

        rslt = LB_GetModelNumber_Addr(currAddr, tmpMN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetModelNumber_Addr.Text = tmpMN.ToString
        Else
            lblLB_GetModelNumber_Addr.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_IsSensorConnected_SN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_IsSensorConnected_SN.Click
        Dim rslt As Integer
        Dim tmpSN As String = txtLB_IsSensorConnected_SN.Text & New String(Chr(0), 100)

        rslt = LB_IsSensorConnected_SN(tmpSN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_IsSensorConnected_SN.Text = MSG_YES
        Else
            lblLB_IsSensorConnected_SN.Text = MSG_NO
        End If
    End Sub

    Private Sub btnLB_IsSensorConnected_Addr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_IsSensorConnected_Addr.Click
        Dim rslt As Integer
        Dim tmpaddr As Integer = CInt(udLB_IsSensorConnected_Addr.Value)

        rslt = LB_IsSensorConnected_Addr(tmpaddr)
        If rslt > INVALID_RTN_VAL Then
            lblLB_IsSensorConnected_Addr.Text = MSG_YES
        Else
            lblLB_IsSensorConnected_Addr.Text = MSG_NO
        End If
    End Sub

    '==================================
    'SECOND TAB - Init, CW && Pulse Mod
    '----------------------------------
    Private Sub btnLB_InitializeSensor_Idx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_InitializeSensor_Idx.Click
        Dim rslt As Integer

        lblLB_InitializeSensor_Idx.Text = MSG_PLEASE_WAIT
        lblLB_InitializeSensor_Idx.Refresh()
        rslt = LB_InitializeSensor_Idx(currIdx)
        If rslt > INVALID_RTN_VAL Then
            lblLB_InitializeSensor_Idx.Text = MSG_SUCCESS
        Else
            lblLB_InitializeSensor_Idx.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_InitializeSensor_Addr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_InitializeSensor_Addr.Click
        Dim rslt As Integer

        lblLB_InitializeSensor_Addr.Text = MSG_PLEASE_WAIT
        lblLB_InitializeSensor_Addr.Refresh()
        rslt = LB_InitializeSensor_Addr(currAddr)
        If rslt > INVALID_RTN_VAL Then
            lblLB_InitializeSensor_Addr.Text = MSG_SUCCESS
        Else
            lblLB_InitializeSensor_Addr.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_InitializeSensor_SN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_InitializeSensor_SN.Click
        Dim rslt As Integer

        lblLB_InitializeSensor_SN.Text = MSG_PLEASE_WAIT
        lblLB_InitializeSensor_SN.Refresh()
        rslt = LB_InitializeSensor_SN(currSN)
        If rslt > INVALID_RTN_VAL Then
            lblLB_InitializeSensor_SN.Text = MSG_SUCCESS
        Else
            lblLB_InitializeSensor_SN.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetFrequency_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetFrequency.Click
        Dim rslt As Integer
        Dim tmpFreq As Double = 0.0

        If IsNumeric(txtLB_SetFrequency.Text) Then
            tmpFreq = CDbl(txtLB_SetFrequency.Text)
            rslt = LB_SetFrequency(currAddr, tmpFreq)
            If rslt > INVALID_RTN_VAL Then
                lblLB_SetFrequency.Text = MSG_SUCCESS
            Else
                lblLB_SetFrequency.Text = MSG_FAILURE
            End If
        Else
            lblLB_SetFrequency.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetFrequency_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetFrequency.Click
        Dim rslt As Integer
        Dim tmpFreq As Double

        rslt = LB_GetFrequency(currAddr, tmpFreq)
        If rslt > INVALID_RTN_VAL Then
            txtLB_GetFrequency.Text = tmpFreq.ToString
            lblLB_GetFrequency.Text = MSG_SUCCESS
        Else
            txtLB_GetFrequency.Text = "-"
            lblLB_GetFrequency.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetMeasurementPowerUnits_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetMeasurementPowerUnits.Click
        Dim rslt As Integer
        Dim tmpUnits As PWR_UNITS

        If cboLB_SetMeasurementPowerUnits.SelectedIndex >= PWR_UNITS.DBM Then
            tmpUnits = cboLB_SetMeasurementPowerUnits.SelectedIndex
        Else
            lblLB_SetMeasurementPowerUnits.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetMeasurementPowerUnits(currAddr, tmpUnits)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetMeasurementPowerUnits.Text = MSG_SUCCESS
        Else
            lblLB_SetMeasurementPowerUnits.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetMeasurementPowerUnits_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetMeasurementPowerUnits.Click
        Dim rslt As Integer
        Dim tmpUnits As PWR_UNITS

        rslt = LB_GetMeasurementPowerUnits(currAddr, tmpUnits)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetMeasurementPowerUnits.Text = tmpUnits.ToString
        Else
            lblLB_GetMeasurementPowerUnits.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetAverages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetAverages.Click
        Dim rslt As Integer
        Dim tmpAvgs As Double = 0.0

        If IsNumeric(txtLB_SetAverages.Text) Then
            tmpAvgs = CDbl(txtLB_SetAverages.Text)
            rslt = LB_SetAverages(currAddr, tmpAvgs)
            If rslt > INVALID_RTN_VAL Then
                lblLB_SetAverages.Text = MSG_SUCCESS
            Else
                lblLB_SetAverages.Text = MSG_FAILURE
            End If
        Else
            lblLB_SetAverages.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetAverages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetAverages.Click
        Dim rslt As Integer
        Dim tmpAvgs As Double

        rslt = LB_GetAverages(currAddr, tmpAvgs)
        If rslt > INVALID_RTN_VAL Then
            txtLB_GetAverages.Text = tmpAvgs.ToString
            lblLB_GetAverages.Text = MSG_SUCCESS
        Else
            txtLB_GetAverages.Text = "-"
            lblLB_GetAverages.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_MeasureCW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_MeasureCW.Click
        Make_CWMeas()
    End Sub

    Private Sub btnLB_MeasurePulse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_MeasurePulse.Click
        Make_PulseMeas()
    End Sub

    Private Sub cbLB_MeasureCW_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbLB_MeasureCW.CheckedChanged
        tmrCW.Enabled = cbLB_MeasureCW.Checked
    End Sub

    Private Sub cbLB_MeasurePulse_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbLB_MeasurePulse.CheckedChanged
        tmrPulse.Enabled = cbLB_MeasurePulse.Checked
    End Sub

    Private Sub tmrCW_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCW.Tick
        Make_CWMeas()
    End Sub

    Private Sub tmrPulse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPulse.Tick
        Make_PulseMeas()
    End Sub

    Private Sub Make_CWMeas()
        Dim rslt As Integer
        Dim tmpCW As Double
        Dim passFail As PASS_FAIL_RESULT

        If ckCWPF.Checked Then
            rslt = LB_MeasureCW_PF(currAddr, tmpCW, passFail)
            If rslt > INVALID_RTN_VAL Then
                lblLB_MeasureCW.Text = tmpCW.ToString(DFLT_1_NUM_FMT) & ": " & passFail.ToString
            Else
                lblLB_MeasureCW.Text = MSG_FAILURE
            End If
        Else
            rslt = LB_MeasureCW(currAddr, tmpCW)
            If rslt > INVALID_RTN_VAL Then
                lblLB_MeasureCW.Text = tmpCW.ToString(DFLT_1_NUM_FMT)
            Else
                lblLB_MeasureCW.Text = MSG_FAILURE
            End If
        End If
    End Sub

    Private Sub Make_PulseMeas()
        Dim rslt As Integer
        Dim tmpPls As Double, tmpPk As Double, tmpDC As Double, tmpAvg As Double, tmpCrF As Double
        Dim passFail As PASS_FAIL_RESULT

        If ckPulsePF.Checked Then
            rslt = LB_MeasurePulse_PF(currAddr, tmpPls, tmpPk, tmpAvg, tmpDC, passFail)
            tmpCrF = tmpPk - tmpAvg
            If rslt > INVALID_RTN_VAL Then
                lblLB_MeasurePulse.Text = _
                    "Pls: " & tmpPls.ToString(DFLT_2_NUM_FMT) & _
                    "  Pk: " & tmpPk.ToString(DFLT_2_NUM_FMT) & _
                    "  Avg: " & tmpAvg.ToString(DFLT_2_NUM_FMT) & _
                    "  DC: " & (tmpDC * 100.0).ToString(DFLT_2_NUM_FMT) & _
                    "  CrF: " & tmpCrF.ToString(DFLT_2_NUM_FMT) & _
                    "  P/F: " & passFail.ToString()
            Else
                lblLB_MeasurePulse.Text = MSG_FAILURE
            End If
        Else
            rslt = LB_MeasurePulse(currAddr, tmpPls, tmpPk, tmpAvg, tmpDC)
            tmpCrF = tmpPk - tmpAvg
            If rslt > INVALID_RTN_VAL Then
                lblLB_MeasurePulse.Text = _
                    "Pls: " & tmpPls.ToString(DFLT_2_NUM_FMT) & _
                    "  Pk: " & tmpPk.ToString(DFLT_2_NUM_FMT) & _
                    "  Avg: " & tmpAvg.ToString(DFLT_2_NUM_FMT) & _
                    "  DC: " & (tmpDC * 100.0).ToString(DFLT_2_NUM_FMT) & _
                    "  CrF: " & tmpCrF.ToString(DFLT_2_NUM_FMT)
            Else
                lblLB_MeasurePulse.Text = MSG_FAILURE
            End If
        End If
    End Sub

    '===================================
    'THIRD TAB - Meas Criteria & Offsets
    '-----------------------------------
    Private Sub btnLB_SetAntiAliasing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetAntiAliasing.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboLB_SetAntiAliasing.SelectedIndex >= 0 Then
            enumState = cboLB_SetAntiAliasing.SelectedIndex
        Else
            lblLB_SetAntiAliasing.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetAntiAliasingEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetAntiAliasing.Text = MSG_SUCCESS
        Else
            lblLB_SetAntiAliasing.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetAntiAliasing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetAntiAliasing.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetAntiAliasingEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetAntiAliasing.Text = enumState.ToString
        Else
            lblLB_GetAntiAliasing.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetAutoPulseEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetAutoPulseEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboSetAutoPulseEnabled.SelectedIndex >= 0 Then
            enumState = cboSetAutoPulseEnabled.SelectedIndex
        Else
            lblSetAutoPulseEnabled.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetAutoPulseEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblSetAutoPulseEnabled.Text = enumState.ToString
        Else
            lblSetAutoPulseEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetAutoPulseEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetAutoPulseEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetAutoPulseEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblGetAutoPulseEnabled.Text = enumState.ToString
        Else
            lblGetAutoPulseEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetPulseCriteria_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetPulseCriteria.Click
        Dim rslt As Integer
        Dim plsCrit As Double

        plsCrit = CDbl(udLB_SetPulseCriteria.Value)
        rslt = LB_SetPulseCriteria(currAddr, plsCrit)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetPulseCriteria.Text = MSG_SUCCESS
        Else
            lblLB_SetPulseCriteria.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetPulseCriteria_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetPulseCriteria.Click
        Dim rslt As Integer
        Dim plsCrit As Double

        rslt = LB_GetPulseCriteria(currAddr, plsCrit)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetPulseCriteria.Text = MSG_SUCCESS & ": " & plsCrit.ToString(DFLT_1_NUM_FMT)
        Else
            lblLB_SetPulseCriteria.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetDutyCycleEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetDutyCycleEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboSetDutyCycleEnabled.SelectedIndex >= 0 Then
            enumState = cboSetDutyCycleEnabled.SelectedIndex
        Else
            lblSetDutyCycleEnabled.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetDutyCycleEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblSetDutyCycleEnabled.Text = enumState.ToString
        Else
            lblSetDutyCycleEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetDutyCycleEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDutyCycleEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetDutyCycleEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblGetDutyCycleEnabled.Text = enumState.ToString
        Else
            lblGetDutyCycleEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetDutyCyclePerCent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetDutyCyclePerCent.Click
        Dim rslt As Integer
        Dim dutyCycle As Double

        dutyCycle = CDbl(udSetDutyCyclePerCent.Value)
        rslt = LB_SetDutyCyclePerCent(currAddr, dutyCycle)
        If rslt > INVALID_RTN_VAL Then
            lblSetDutyCyclePerCent.Text = MSG_SUCCESS
        Else
            lblSetDutyCyclePerCent.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetDutyCyclePerCent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDutyCyclePerCent.Click
        Dim rslt As Integer
        Dim dutyCycle As Double

        rslt = LB_GetDutyCyclePerCent(currAddr, dutyCycle)
        If rslt > INVALID_RTN_VAL Then
            lblGetDutyCyclePerCent.Text = MSG_SUCCESS & ": " & dutyCycle.ToString(DFLT_1_NUM_FMT)
        Else
            lblGetDutyCyclePerCent.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetOffsetEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetOffsetEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboLB_SetOffsetEnabled.SelectedIndex >= 0 Then
            enumState = cboLB_SetOffsetEnabled.SelectedIndex
        Else
            lblLB_SetOffsetEnabled.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetOffsetEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetOffsetEnabled.Text = enumState.ToString
        Else
            lblLB_SetOffsetEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetOffsetEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetOffsetEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetOffsetEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetOffsetEnabled.Text = enumState.ToString
        Else
            lblLB_GetOffsetEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetOffset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetOffset.Click
        Dim rslt As Integer
        Dim offset As Double

        offset = CDbl(udLB_SetOffset.Value)
        rslt = LB_SetOffset(currAddr, offset)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetOffset.Text = MSG_SUCCESS
        Else
            lblLB_SetOffset.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetOffset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetOffset.Click
        Dim rslt As Integer
        Dim offset As Double

        rslt = LB_GetOffset(currAddr, offset)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetOffset.Text = MSG_SUCCESS & ": " & offset.ToString(DFLT_1_NUM_FMT)
        Else
            lblLB_GetOffset.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetCWReference_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetCWReference.Click
        Dim rslt As Integer
        Dim CWRef As Double

        CWRef = CDbl(udLB_SetCWReference.Value)
        'next statement uses dBm as units just for demonstration purposes...use the units of your choice
        rslt = LB_SetCWReference(currAddr, CWRef, PWR_UNITS.DBM)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetCWReference.Text = MSG_SUCCESS
        Else
            lblLB_SetCWReference.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetCWReference_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetCWReference.Click
        Dim rslt As Integer
        Dim CWRef As Double
        Dim CWRefUnits As PWR_UNITS

        rslt = LB_GetCWReference(currAddr, CWRef, CWRefUnits)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetCWReference.Text = MSG_SUCCESS & ": " & CWRef.ToString(DFLT_1_NUM_FMT)
        Else
            lblLB_GetCWReference.Text = MSG_FAILURE
        End If
    End Sub

    'rather than have a lot of text boxes I'm just demonstrating this call with some default references
    Private Sub btnLB_SetPulseReference_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetPulseReference.Click
        Dim rslt As Integer
        Dim frm As RgrTst_SetPulseRef = New RgrTst_SetPulseRef

        Dim plsGetRef As Double = 0.0
        Dim pkGetRef As Double = 0.0
        Dim avgGetRef As Double = 0.0
        Dim dcGetRef As Double = 0.0
        Dim plsGetRefUnits As PWR_UNITS = PWR_UNITS.DBM

        Dim plsRef As Double = -10.0
        Dim pkRef As Double = -10.0
        Dim avgRef As Double = -10.0
        Dim dcRef As Double = -10.0
        Dim plsRefUnits As PWR_UNITS = PWR_UNITS.DBM

        'get the current references and present them in the dialog 
        rslt = LB_GetPulseReference(currAddr, plsGetRef, pkGetRef, avgGetRef, dcGetRef, plsGetRefUnits)
        frm.PlsRef = plsGetRef
        frm.PkRef = pkGetRef
        frm.AvgRef = avgGetRef
        frm.DCRef = dcGetRef

        frm.ShowDialog()

        If frm.DialogResult = Windows.Forms.DialogResult.OK Then
            'get the new references from the dialog 
            plsRef = frm.PlsRef
            pkRef = frm.PkRef
            avgRef = frm.AvgRef
            dcRef = frm.DCRef
            'set them as the new references
            rslt = LB_SetPulseReference(currAddr, plsRef, pkRef, avgRef, dcRef, plsRefUnits)
            If rslt > INVALID_RTN_VAL Then
                lblLB_SetPulseReference.Text = MSG_SUCCESS
            Else
                lblLB_SetPulseReference.Text = MSG_FAILURE
            End If
        Else
            lblLB_SetPulseReference.Text = MSG_CANCELLED
        End If
    End Sub

    Private Sub btnLB_SetResponseEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetResponseEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboLB_SetResponseEnabled.SelectedIndex >= 0 Then
            enumState = cboLB_SetResponseEnabled.SelectedIndex
        Else
            lblLB_SetResponseEnabled.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetResponseEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetResponseEnabled.Text = enumState.ToString
        Else
            lblLB_SetResponseEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetResponseEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetResponseEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetResponseEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetResponseEnabled.Text = enumState.ToString
        Else
            lblLB_GetResponseEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_SetResponse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetResponse.Click
        Dim rslt As Integer
        Dim rspPts(MAX_NUM_RESP_PTS - 1) As ResponsePoints
        Dim numPts As Integer = MAX_NUM_RESP_PTS

        'get the current response
        rslt = LB_GetResponse(currAddr, rspPts(0), numPts)
        ReDim Preserve rspPts(numPts - 1)
        'create the dialog box
        Dim frm As RgrTst_SetGetResponse = New RgrTst_SetGetResponse
        'set the response points we just retrieved
        frm.Response = rspPts
        frm.ShowDialog()
        If frm.DialogResult = Windows.Forms.DialogResult.OK Then
            rspPts = frm.Response
            numPts = rspPts.Length
            rslt = LB_SetResponse(currAddr, rspPts(0), numPts)
            If rslt > INVALID_RTN_VAL Then
                lblLB_SetResponse.Text = MSG_SUCCESS
            Else
                lblLB_SetResponse.Text = MSG_FAILURE
            End If
        Else
            lblLB_SetResponse.Text = MSG_CANCELLED
        End If
    End Sub

    '===================
    'FOURTH TAB - Limits
    '-------------------
    Private Sub btnLB_SetLimitEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_SetLimitEnabled.Click
        Dim rslt As Integer
        Dim enumState As LIMIT_STYLE

        If cboLB_SetLimitEnabled_State.SelectedIndex >= 0 Then
            enumState = cboLB_SetLimitEnabled_State.SelectedIndex
        Else
            lblLB_SetLimitEnabled_Rslt.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetLimitEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetLimitEnabled_Rslt.Text = enumState.ToString
        Else
            lblLB_SetLimitEnabled_Rslt.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetLimitEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetLimitEnabled.Click
        Dim rslt As Integer
        Dim enumState As LIMIT_STYLE

        rslt = LB_GetLimitEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblLB_GetLimitEnabled_State.Text = enumState.ToString
            lblLB_GetLimitEnabled_Rslt.Text = MSG_SUCCESS
        Else
            lblLB_GetLimitEnabled_Rslt.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnLB_GetSingleSidedLimit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLB_GetSingleSidedLimit.Click
        Dim rslt As Integer
        Dim ssLimit As Double
        Dim ssLimitUnits As PWR_UNITS
        Dim ssLimitRule As SS_RULE

        rslt = LB_GetSingleSidedLimit(currAddr, ssLimit, ssLimitUnits, ssLimitRule)
        If rslt > INVALID_RTN_VAL Then
            lblGetSingleSidedLimit.Text = "Limit = " & ssLimit.ToString(DFLT_1_NUM_FMT) & " " & ssLimitUnits.ToString & " Rule = " & ssLimitRule.ToString
        Else
            lblGetSingleSidedLimit.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetSingleSidedLimit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetSingleSidedLimit.Click
        Dim rslt As Integer
        Dim ssLimit As Double
        Dim ssLimitUnits As PWR_UNITS = PWR_UNITS.DBM
        Dim ssLimitRule As SS_RULE

        ssLimit = CDbl(udSetSingleSidedLimit.Value)
        ssLimitRule = cboSetSingleSidedLimit_Rule.SelectedIndex
        rslt = LB_SetSingleSidedLimit(currAddr, ssLimit, ssLimitUnits, ssLimitRule)
        If rslt > INVALID_RTN_VAL Then
            lblSetSingleSidedLimit.Text = MSG_SUCCESS
        Else
            lblSetSingleSidedLimit.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetDoubleSidedLimit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetDoubleSidedLimit.Click
        Dim rslt As Integer
        Dim dsUpperLimit As Double
        Dim dsLowerLimit As Double
        Dim dsLimitUnits As PWR_UNITS = PWR_UNITS.DBM
        Dim dsLimitRule As DS_RULE

        dsUpperLimit = CDbl(udLB_SetDoubleSidedLimit_Upper.Value)
        dsLowerLimit = CDbl(udLB_SetDoubleSidedLimit_Lower.Value)
        If dsLowerLimit >= dsUpperLimit Then
            MessageBox.Show("Upper limit must be greater than lower limit", "Double Sided Limit", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return
        End If
        dsLimitRule = cboLB_SetDoubleSidedLimit_Rule.SelectedIndex
        rslt = LB_SetDoubleSidedLimit(currAddr, dsLowerLimit, dsUpperLimit, dsLimitUnits, dsLimitRule)
        If rslt > INVALID_RTN_VAL Then
            lblLB_SetDoubleSidedLimit.Text = MSG_SUCCESS
        Else
            lblLB_SetDoubleSidedLimit.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetDoubleSidedLimit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDoubleSidedLimit.Click
        Dim rslt As Integer
        Dim dsUpperLimit As Double
        Dim dsLowerLimit As Double
        Dim dsLimitUnits As PWR_UNITS
        Dim dsLimitRule As DS_RULE

        rslt = LB_GetDoubleSidedLimit(currAddr, dsLowerLimit, dsUpperLimit, dsLimitUnits, dsLimitRule)
        If rslt > INVALID_RTN_VAL Then
            lblGetDoubleSidedLimit.Text = "LL = " & dsLowerLimit.ToString(DFLT_1_NUM_FMT) & _
                                            "   UL = " & dsUpperLimit.ToString(DFLT_1_NUM_FMT) & vbCrLf & _
                                            "   Units = " & dsLimitUnits.ToString() & _
                                            "   Rule = " & dsLimitRule.ToString()
            lblGetDoubleSidedLimit_Rslt.Text = MSG_SUCCESS
        Else
            lblGetDoubleSidedLimit_Rslt.Text = MSG_FAILURE
        End If
    End Sub

    '======================
    'FIFTH TAB - Triggering
    '----------------------
    Private Sub btnSetTTLTriggerInEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetTTLTriggerInEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboSetTTLTriggerInEnabled.SelectedIndex >= 0 Then
            enumState = cboSetTTLTriggerInEnabled.SelectedIndex
        Else
            lblSetTTLTriggerInEnabled.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetTTLTriggerInEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblSetTTLTriggerInEnabled.Text = MSG_SUCCESS
        Else
            lblSetTTLTriggerInEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetTTLTriggerInEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetTTLTriggerInEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetTTLTriggerInEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblGetTTLTriggerInEnabled.Text = enumState.ToString
        Else
            lblGetTTLTriggerInEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetTTLTriggerInTimeOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetTTLTriggerInTimeOut.Click
        Dim rslt As Integer
        Dim tmo As Integer

        tmo = CInt(udSetTTLTriggerInTimeOut.Value)
        rslt = LB_SetTTLTriggerInTimeOut(currAddr, tmo)
        If rslt > INVALID_RTN_VAL Then
            lblSetTTLTriggerInTimeOut.Text = MSG_SUCCESS
        Else
            lblSetTTLTriggerInTimeOut.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetTTLTriggerInTimeOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetTTLTriggerInTimeOut.Click
        Dim rslt As Integer
        Dim tmo As Integer

        rslt = LB_GetTTLTriggerInTimeOut(currAddr, tmo)
        If rslt > INVALID_RTN_VAL Then
            lblGetTTLTriggerInTimeOut.Text = MSG_SUCCESS & ": " & tmo.ToString()
        Else
            lblGetTTLTriggerInTimeOut.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetTTLTriggerInInverted_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetTTLTriggerInInverted.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboSetTTLTriggerInInverted.SelectedIndex >= 0 Then
            enumState = cboSetTTLTriggerInInverted.SelectedIndex
        Else
            lblSetTTLTriggerInInverted.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetTTLTriggerInInverted(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblSetTTLTriggerInInverted.Text = MSG_SUCCESS
        Else
            lblSetTTLTriggerInInverted.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetTTLTriggerInInverted_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetTTLTriggerInInverted.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetTTLTriggerInInverted(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblGetTTLTriggerInInverted.Text = enumState.ToString
        Else
            lblGetTTLTriggerInInverted.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetTTLTriggerOutEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetTTLTriggerOutEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboSetTTLTriggerOutEnabled.SelectedIndex >= 0 Then
            enumState = cboSetTTLTriggerOutEnabled.SelectedIndex
        Else
            lblSetTTLTriggerOutEnabled.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetTTLTriggerOutEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblSetTTLTriggerOutEnabled.Text = enumState.ToString
        Else
            lblSetTTLTriggerOutEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetTTLTriggerOutEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetTTLTriggerOutEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetTTLTriggerOutEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblGetTTLTriggerOutEnabled.Text = enumState.ToString
        Else
            lblGetTTLTriggerOutEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetTTLTriggerOutInverted_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetTTLTriggerOutInverted.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboSetTTLTriggerOutInverted.SelectedIndex >= 0 Then
            enumState = cboSetTTLTriggerOutInverted.SelectedIndex
        Else
            lblSetTTLTriggerOutInverted.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetTTLTriggerOutInverted(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblSetTTLTriggerOutInverted.Text = enumState.ToString
        Else
            lblSetTTLTriggerOutInverted.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetTTLTriggerOutInverted_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetTTLTriggerOutInverted.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetTTLTriggerOutInverted(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblGetTTLTriggerOutInverted.Text = enumState.ToString
        Else
            lblGetTTLTriggerOutInverted.Text = MSG_FAILURE
        End If
    End Sub

    '========================
    'SIXTH TAB - Recorder Out
    '------------------------
    Private Sub btnSetRecorderOutSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetRecorderOutSetup.Click
        Dim rslt As Integer
        Dim dblZeroVoltLevel As Double = CDbl(udSetRecorderOutSetup_Zero.Value)
        Dim dblOneVoltLevel As Double = CDbl(udSetRecorderOutSetup_One.Value)
        Dim roUnits As PWR_UNITS = PWR_UNITS.DBM

        rslt = LB_SetRecorderOutSetup(currAddr, dblZeroVoltLevel, dblOneVoltLevel, roUnits)
        If rslt > INVALID_RTN_VAL Then
            lblSetRecorderOutSetup.Text = MSG_SUCCESS
        Else
            lblSetRecorderOutSetup.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetRecorderOutSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRecorderOutSetup.Click
        Dim rslt As Integer
        Dim dblZeroVoltLevel As Double = 0.0
        Dim dblOneVoltLevel As Double = 0.0
        Dim roUnits As PWR_UNITS = PWR_UNITS.DBM

        rslt = LB_GetRecorderOutSetup(currAddr, dblZeroVoltLevel, dblOneVoltLevel, roUnits)
        If rslt > INVALID_RTN_VAL Then
            lblGetRecorderOutSetup.Text = "0V = " & dblZeroVoltLevel.ToString(DFLT_1_NUM_FMT) & "  1V = " & dblOneVoltLevel.ToString(DFLT_1_NUM_FMT) & " Units = " & roUnits.ToString()
        Else
            lblGetRecorderOutSetup.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnSetRecorderOutEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetRecorderOutEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        If cboSetRecorderOutEnabled.SelectedIndex >= 0 Then
            enumState = cboSetRecorderOutEnabled.SelectedIndex
        Else
            lblSetRecorderOutEnabled.Text = MSG_ERROR
            Return
        End If
        rslt = LB_SetRecorderOutEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblSetRecorderOutEnabled.Text = enumState.ToString
        Else
            lblSetRecorderOutEnabled.Text = MSG_FAILURE
        End If
    End Sub

    Private Sub btnGetRecorderOutEnabled_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRecorderOutEnabled.Click
        Dim rslt As Integer
        Dim enumState As FEATURE_STATE

        rslt = LB_GetRecorderOutEnabled(currAddr, enumState)
        If rslt > INVALID_RTN_VAL Then
            lblGetRecorderOutEnabled.Text = enumState.ToString
        Else
            lblGetRecorderOutEnabled.Text = MSG_FAILURE
        End If
    End Sub

End Class
