'************************************************************************************************************************
' File: Initialization.vb
' Programmer: Ting Chan
' Date: September 30, 2004
'
' Description:
' This form contains the function to load real time data from the PMACS Server
' into the Client data structures described in the module DataStructures.vb
' This form contains all the different modules to initialize the display of 
' various controls on each forms according to the data structures 
' described in the module DataStructures.vb
' The modules are called whenever updated data is received from the PMACS Server.
' 
' Routines in this file:
' SensorInitialize()
' ConvertTime()
' ShoreInitialize()
' ScienceInitialize()
' BusInitialize()
' LoadInitialize()
' GFInitialize()
' ConverterInitialize()
' IntLoad48Initialize()        
' IntLoad12Initialize()
' IntLoad5Initialize()
' LoadDataWorkerThread()
' LoadDataVersionWithCriticalCodeProtected()
' DefaultData()
'
' Revision History:
' 09-30-2004 New header block comments added by Ting Chan, UWEE.
' 10-25-2004 Add new function call to get data for MV converters from  SOAP method getMV() by Ting Chan, UWEE.
' 10-25-2004 Update MVConverterInitialize() by Ting Chan, UWEE.
' 10-28-2004 Add new condition in LoadData to record change in loads by Ting Chan, UWEE
' 12-15-2004 Add GFInitialize() by Ting Chan, UWEE
' 12-17-2004 Modified IntLoad48Initialize(), IntLoad12Initialize(), IntLoad5Initialize(), and LoadData() due to
'            changes in numbering system by Ting Chan, UWEE
' 03-06-2005 Change display method to display fix significant digits for all voltages and currents by Ting Chan, UWEE
' 03-09-2005 Modified IntLoad48Initialize, IntLoad12Initialize, and IntLoad5Initialize to update the diplay in PMACSintload form
'            by Ting Chan, UWEE
' 03-15-2005 Add LoadDataWorkerThread() for multi-threading for loading data by Ting Chan, UWEE
' 03-17-2005 Add DisconnectExtLoad() to disconnect all external loads by Ting Chan, UWEE
' 03-17-2005 Add DisconnectIntLoad() to disconnect all internal loads by Ting Chan, UWEE
' 04-07-2005 Modified LoadData() to include getSPS() to get shore power supply data by Ting Chan, UWEE
' 04-11-2005 Add ShoreInitialize() by Ting Chan, UWEE
' 04-11-2005 Modified BusInitialize() to include bus power by Ting Chan, UWEE
' 04-12-2005 Add ConvertTime() to convert time to UTC time stamp with microseconds by Ting Chan, UWEE
' 04-28-2005 Added sub LoadDataVersionWithCriticalCodeProtected() which is a modified 
'            version of the old LoadData() routine with no references to any control 
'            and with critical code section protected to avoid thread conflict.
' 05-05-2005 Added sub ScienceInitialize() for updating GUI display for science node data by Ting Chan, UWEE
' 06-08-2005 added sub IntLoadPowerInitialize() for display of housing power by Ting Chan, UWEE
' 06-24-2005 added sub ShowMessage() for displaying alert messages by Ting Chan, UWEE
' 07-12-2005 Moved ShowMessage() to WriteAndAlert.vb by Ting Chan, UWEE
'************************************************************************************************************************
Option Strict Off
Option Explicit On 

'see  http://www.dillfrog.com/sponge/web_development/asp_dotnet/on-the-fly_compilation.asp
'For example, the VB.NET Timer function (returning a Double value; not to be confused 
' with System.Timers.Timer object) doesn't work properly until you add 
Imports Microsoft.VisualBasic 'jbe: Needed for old VB style timer function (not the timer event handler) 
Imports System.Math 'jbe: Needed for old VB style absolute value function. 
Imports System.Globalization

Module Initialization

#Region "Initialize Engineering Sensors"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'initialize the Engineering Sensor display
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function SensorInitialize(ByRef Sensors As Sensor) As Object
        Select Case (Sensors.SensorName)
            Case ("temp/mv/1")
                PMACSengsensor.DefInstance.MVT(0).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/mv/2")
                PMACSengsensor.DefInstance.MVT(1).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/mv/3")
                PMACSengsensor.DefInstance.MVT(2).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/mv/4")
                PMACSengsensor.DefInstance.MVT(3).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/mv/5")
                PMACSengsensor.DefInstance.MVT(4).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/mv/6")
                PMACSengsensor.DefInstance.MVT(5).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/mv/7")
                PMACSengsensor.DefInstance.MVT_6.Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/mv/8")
                PMACSengsensor.DefInstance.MVT_7.Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/ilc")
                PMACSengsensor.DefInstance.LVWetT(1).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/bm")
                PMACSengsensor.DefInstance.LVWetT(2).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/xlc/a")
                PMACSengsensor.DefInstance.LVWetT(0).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/edfa/west")
                PMACSengsensor.DefInstance.LVDryT(3).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/bottom")
                PMACSengsensor.DefInstance.LVDryT(6).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/edfa/east")
                PMACSengsensor.DefInstance.LVDryT(2).Text = Format(Sensors.SensorValue, "0.00")
            Case ("humidity")
                PMACSengsensor.DefInstance.LVDryRH.Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/top")
                PMACSengsensor.DefInstance.LVDryT(5).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/laser/east")
                PMACSengsensor.DefInstance.LVDryT(0).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/xlc/b")
                PMACSengsensor.DefInstance.LVWet_XLC_B_Temp.Text = Format(Sensors.SensorValue, "0.00")
            Case ("pressure/fluid")
                PMACSengsensor.DefInstance.LVWetFP.Text = Format(Sensors.SensorValue, "0.00")
            Case ("pressure/lv")    'meaningless channel
                'convert voltage to pressure
                'PMACSengsensor.DefInstance.LVWetHP.Text = Format((Sensors.SensorValue / 4.5) * 100, "0.00")
                'PMACSengsensor.DefInstance.LVWetHP.Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/laser/west")
                PMACSengsensor.DefInstance.LVDryT(1).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/comms/a")
                PMACSengsensor.DefInstance.LVWetT(4).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/idc")
                PMACSengsensor.DefInstance.LVWetT(3).Text = Format(Sensors.SensorValue, "0.00")
            Case ("pressure/mv")
                PMACSengsensor.DefInstance.MVHP.Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/comms/b")
                PMACSengsensor.DefInstance.LVWetT(5).Text = Format(Sensors.SensorValue, "0.00")
            Case ("temp/tbd1")
                PMACSengsensor.DefInstance.LVDryT_Spare.Text = Format(Sensors.SensorValue, "0.00")
        End Select
    End Function
#End Region

#Region "Initialize GF setting"
    '*******************************************************************
    'Initialize the ground fault setting display on external load screen
    '*******************************************************************
    Public Sub GFInitialize(ByRef SciNode As ScienceNode)
        'show GF settings on the ground fault monitoring window
        PMACSgroundfault.DefInstance.GFHigh400V.Text = CStr(SciNode.GF400HighSetpoint) + " uA"
        PMACSgroundfault.DefInstance.GFLow400V.Text = CStr(SciNode.GF400LowSetpoint) + " uA"
        PMACSgroundfault.DefInstance.GFHigh48V.Text = CStr(SciNode.GF48HighSetpoint) + " uA"
        PMACSgroundfault.DefInstance.GFLow48V.Text = CStr(SciNode.GF48LowSetpoint) + " uA"
        PMACSgroundfault.DefInstance.GF400HighSetpoint.Text = CStr(SciNode.GF400HighSetpoint)
        PMACSgroundfault.DefInstance.GF400LowSetPoint.Text = CStr(SciNode.GF400LowSetpoint)
        PMACSgroundfault.DefInstance.GF48HighSetpoint.Text = CStr(SciNode.GF48HighSetpoint)
        PMACSgroundfault.DefInstance.GF48LowSetPoint.Text = CStr(SciNode.GF48LowSetpoint)
    End Sub
#End Region

#Region "Initialize Shore Station"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'initialize the Shore Power Supply display for volatge, current, and power
    'Fault Location algorithm is also being ran in this module if needed
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function ShoreInitialize(ByRef Shore As ShoreStation) As Object
        Dim FaultLocationOutput As Double
        'Display the voltage, current, and power at the shore
        'on the Main Window
        PMACSmain.DefInstance.SSVdisplay.Text = CStr(Format(Shore.ShoreVoltage, "#0.0")) + " V"
        PMACSmain.DefInstance.SSIdisplay.Text = CStr(Format(Shore.ShoreCurrent, "#0.00")) + " A"
        PMACSmain.DefInstance.SNIdisplay.Text = CStr(Format(Shore.ShoreCurrent, "#0.00")) + " A (Est.)"
        PMACSmain.DefInstance.SSPdisplay.Text = CStr(Format(Shore.ShorePower, "#0.00")) + " W"
        'PMACSmain.DefInstance.SNVdisplay.Text = VB6.Format(x_est(2, 0), "fixed") & "V"
        'PMACSmain.DefInstance.SNIdisplay.Text = VB6.Format(x_est(3, 0), "0.0000") & "A"

        'Display the voltage and current of the shore station on the PMACS external load window
        PMACSextload.DefInstance.ShoreVoltMV.Text = CStr(Format(Shore.ShoreVoltage, "#0.0")) + " V"
        PMACSextload.DefInstance.ShoreCurrMV.Text = CStr(Format(Shore.ShoreCurrent, "#0.00")) + " A"

        'Display the voltage, current, and power at the shore
        'on the PMACS Shore Window
        'Check status of shore power supply
        If Shore.ShoreState = 1 Then    'if status is 1 (ON)
            'Set the font color to green
            PMACSshore.DefInstance.ShoreStatus.ForeColor = System.Drawing.Color.Lime
            'Display a meesage indicating the power ssupply is ON
            PMACSshore.DefInstance.ShoreStatus.Text = "Shore Power Supply is ON"
        Else    'if the status is not 1 (OFF)
            'Set the font color to red
            PMACSshore.DefInstance.ShoreStatus.ForeColor = System.Drawing.Color.Red
            'Display a meesage indicating the power ssupply is OFF
            PMACSshore.DefInstance.ShoreStatus.Text = "Shore Power Supply is OFF"
        End If
        'PMACSshore.DefInstance.Check1.Checked = True

        'Disply the volatge and current on the PMACS Shore Window
        PMACSshore.DefInstance.ShoreV.Text = CStr(Format(Shore.ShoreVoltage, "#0.0")) + " V"
        PMACSshore.DefInstance.ShoreI.Text = CStr(Format(Shore.ShoreCurrent, "#0.00")) + " A"
        PMACSshore.DefInstance.ShoreTimeConstant.Text = CStr(Shore.ShoreTc) + " Volts/Second"
        PMACSshore.DefInstance.ShoreTC.Text = CStr(Shore.ShoreTc)
        PMACSshore.DefInstance.ShoreVEst.Text = VB6.Format(x_est(0, 0), "fixed") & " V"
        PMACSshore.DefInstance.ShoreIEst.Text = VB6.Format(x_est(1, 0), "0.00") & " A"
        PMACSfaultlocation.DefInstance.ShoreV.Text = CStr(Format(Shore.ShoreVoltage, "#0.0")) + " V"
        PMACSfaultlocation.DefInstance.ShoreI.Text = CStr(Format(Shore.ShoreCurrent, "#0.00")) + " A"

        'If the flag for running fault location is true
        'then run FaultLocation()
        If RunFaultLocation Then
            FaultLocationOutput = FaultLocation(Shore)
            PMACSfaultlocation.DefInstance.FLOutput.Text = CStr(FaultLocationOutput)
        End If
    End Function
#End Region

#Region "Initialize Science Node"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'initialize the 10KV level Science Node data
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Sub ScienceInitialize(ByRef SciNode As ScienceNode)
        'Display the voltage, current, and power at the Science Node
        'on the Main Window
        PMACSmain.DefInstance.SNVdisplay.Text = CStr(Format(SciNode.SciVoltage, "#0.0")) + " V"
        'PMACSmain.DefInstance.SNIdisplay.Text = CStr(Format(SciNode.SciCurrent, "#0.00")) + " A"
        PMACSmain.DefInstance.SNPdisplay.Text = CStr(Format(SciNode.SciPower, "#0.00")) + " W"

        'Display the voltage and current of the science node on the PMACS external load window
        PMACSextload.DefInstance.SciVoltMV.Text = CStr(Format(SciNode.SciVoltage, "#0.0")) + " V"
        PMACSextload.DefInstance.SciCurrMV.Text = CStr(Format(SciNode.SciCurrent, "#0.00")) + " A"
    End Sub
#End Region

#Region "Initialize bus"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'initialize the low voltage busses display for volatge and current
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function BusInitialize(ByRef Busses As Bus) As Object
        If Busses.BusName = "external/v400" Then
            'If the bus is external 400V bus, display the voltage,
            'current and power on the external load window
            If Busses.BusVoltage < 0 Then
                PMACSextload.DefInstance.V_400.Text = CStr(Format(0, "0.0")) + " V"
            Else
                PMACSextload.DefInstance.V_400.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            End If
            If Busses.BusCurrent < 0 Then
                PMACSextload.DefInstance.I_400.Text = CStr(Format(0, "0.00")) + " A"
                'PMACSextload.DefInstance.Ext400VBusPower.Text = CStr(Format(0, "0.00")) + " W"
            Else
                PMACSextload.DefInstance.I_400.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
                'PMACSextload.DefInstance.Ext400VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
            End If
            'PMACSextload.DefInstance.I_400.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
            'PMACSextload.DefInstance.Ext400VBusPower.Text = CStr(Format(Busses.BusVoltage * Busses.BusCurrent, "#0.0")) + " W"
            PMACSextload.DefInstance.Ext400VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
        ElseIf Busses.BusName = "external/v48" Then
            'If the bus is external 48V bus, display the voltage,
            'current and power on the external load window
            If Busses.BusVoltage < 0 Then
                PMACSextload.DefInstance.V_48.Text = CStr(Format(0, "0.0")) + " V"
            Else
                PMACSextload.DefInstance.V_48.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            End If

            If Busses.BusCurrent < 0 Then
                'PMACSextload.DefInstance.I_48.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
                PMACSextload.DefInstance.I_48.Text = CStr(Format(0, "0.00")) + " A"
                'PMACSextload.DefInstance.Ext48VBusPower.Text = CStr(Format(0, "0.00")) + " W"
            Else
                PMACSextload.DefInstance.I_48.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
                'PMACSextload.DefInstance.Ext48VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
            End If
            'PMACSextload.DefInstance.I_48.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
            PMACSextload.DefInstance.Ext48VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
        ElseIf Busses.BusName = "internal/v48" Then
            'If the bus is internal 48V bus, display the voltage,
            'current and power on the 48V internal load window
            If Busses.BusVoltage < 0 Then
                PMACS48Vintload.DefInstance.V_48Int.Text = CStr(Format(0, "0.0")) + " V"
                PMACSintload.DefInstance.vBus(4).Text = CStr(Format(0, "0.0")) + " V"
                PMACSintload.DefInstance.vBus(1).Text = CStr(Format(0, "0.0")) + " V"
            Else
                PMACS48Vintload.DefInstance.V_48Int.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
                PMACSintload.DefInstance.vBus(4).Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
                PMACSintload.DefInstance.vBus(1).Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            End If
            'PMACS48Vintload.DefInstance.V_48Int.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            If Busses.BusCurrent < 0 Then
                PMACS48Vintload.DefInstance.I_48Int.Text = CStr(Format(0, "0.00")) + " A"
                'PMACS48Vintload.DefInstance.Int48VBusPower.Text = CStr(Format(0, "0.00")) + " W"
            Else
                PMACS48Vintload.DefInstance.I_48Int.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
                'PMACS48Vintload.DefInstance.Int48VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
            End If
            'PMACS48Vintload.DefInstance.I_48Int.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
            PMACS48Vintload.DefInstance.Int48VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
        ElseIf Busses.BusName = "internal/v12" Then
            'If the bus is internal 12V bus, display the voltage,
            'current and power on the 12V internal load window
            If Busses.BusVoltage < 0 Then
                PMACS12Vintload.DefInstance.V_12Int.Text = CStr(Format(0, "0.0")) + " V"
                PMACSintload.DefInstance.vBus(0).Text = CStr(Format(0, "0.0")) + " V"
            Else
                PMACS12Vintload.DefInstance.V_12Int.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
                PMACSintload.DefInstance.vBus(0).Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            End If
            'PMACS12Vintload.DefInstance.V_12Int.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            If Busses.BusCurrent < 0 Then
                PMACS12Vintload.DefInstance.I_12Int.Text = CStr(Format(0, "0.00")) + " A"
                'PMACS12Vintload.DefInstance.Int12VBusPower.Text = CStr(Format(0, "0.00")) + " W"
            Else
                PMACS12Vintload.DefInstance.I_12Int.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
                'PMACS12Vintload.DefInstance.Int12VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
            End If
            'PMACS12Vintload.DefInstance.I_12Int.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
            PMACS12Vintload.DefInstance.Int12VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
        ElseIf Busses.BusName = "internal/v5" Then
            'If the bus is internal 5V bus, display the voltage,
            'current and power on the 5V internal load window
            If Busses.BusVoltage < 0 Then
                PMACS5Vintload.DefInstance.V_5Int.Text = CStr(Format(0, "0.0")) + " V"
                PMACSintload.DefInstance.vBus(3).Text = CStr(Format(0, "0.0")) + " V"
            Else
                PMACS5Vintload.DefInstance.V_5Int.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
                PMACSintload.DefInstance.vBus(3).Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            End If
            'PMACS5Vintload.DefInstance.V_5Int.Text = CStr(Format(Busses.BusVoltage, "#0.0")) + " V"
            If Busses.BusCurrent < 0 Then
                PMACS5Vintload.DefInstance.I_5Int.Text = CStr(Format(0, "0.00")) + " A"
                'PMACS5Vintload.DefInstance.Int5VBusPower.Text = CStr(Format(0, "0.00")) + " W"
            Else
                PMACS5Vintload.DefInstance.I_5Int.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
                'PMACS5Vintload.DefInstance.Int5VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
            End If
            'PMACS5Vintload.DefInstance.I_5Int.Text = CStr(Format(Busses.BusCurrent, "##0.00")) + " A"
            PMACS5Vintload.DefInstance.Int5VBusPower.Text = CStr(Format(Busses.BusPower, "#0.00")) + " W"
        End If
    End Function
#End Region

#Region "Initialize external load"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Initialize the Load Configuration frame for external load at 400V and 48V
    '8 loads total. each loads has 2 voltage levels.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function LoadInitialize(ByRef Loads As Load) As Object
        'Set 400V load switches status as appear in configuration frame 
        'according to data structure element status
        'when switch or deadface is ture, that means switch or deadface is closed
        'when switch or deadface is false, that means switch or deadface is opened

        'When switch is closed, check deadface status
        If Loads.Load400S = True Then
            PMACSextload.DefInstance.LoadSwitchClose_400(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.LoadSwitchOpen_400(Loads.Loadindex - 1).Checked = False
            If Loads.Load400B = True Then
                PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Lime
            ElseIf Loads.Load400B = False Then
                PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Yellow
            End If

        ElseIf Loads.Load400S = False Then
            PMACSextload.DefInstance.LoadSwitchClose_400(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadSwitchOpen_400(Loads.Loadindex - 1).Checked = True
            If Loads.Load400B = True Then
                If Loads.Load400Error = "" Or Loads.Load400Error = "n/a" Then
                    PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                    'ElseIf Loads.Load400Error = "over-current" Then
                    'PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
                Else
                    'PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                    PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
                End If
                'PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.White
            ElseIf Loads.Load400B = False Then
                PMACSextload.DefInstance.Load_400Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Yellow
            End If
        End If

        If Loads.Load400D = True Then
            PMACSextload.DefInstance.LoadDeadfaceClose_400(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.LoadDeadfaceOpen_400(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.Load_400Deadface(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Lime
        ElseIf Loads.Load400D = False Then
            PMACSextload.DefInstance.LoadDeadfaceClose_400(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadDeadfaceOpen_400(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.Load_400Deadface(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Red
        End If

        'Set 400V load switches status as appear in configuration frame 
        'according to data structure element status
        'when switch or deadface is ture, that means switch or deadface is closed
        'when switch or deadface is false, that means switch or deadface is opened
        If Loads.Load48S = True Then
            PMACSextload.DefInstance.LoadSwitchClose_48(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.LoadSwitchOpen_48(Loads.Loadindex - 1).Checked = False
            If Loads.Load48B = True Then
                PMACSextload.DefInstance.Load_48Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Lime
            ElseIf Loads.Load48B = False Then
                PMACSextload.DefInstance.Load_48Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Yellow
            End If

        ElseIf Loads.Load48S = False Then
            PMACSextload.DefInstance.LoadSwitchClose_48(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadSwitchOpen_48(Loads.Loadindex - 1).Checked = True
            If Loads.Load48B = True Then
                If Loads.Load48Error = "" Or Loads.Load48Error = "n/a" Then
                    PMACSextload.DefInstance.Load_48Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                    'ElseIf Loads.Load48Error = "over-current" Then
                    'PMACSextload.DefInstance.Load_48Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
                Else
                    'PMACSextload.DefInstance.Load_48Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                    PMACSextload.DefInstance.Load_48Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
                End If
            ElseIf Loads.Load48B = False Then
                PMACSextload.DefInstance.Load_48Switch(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Yellow
            End If
        End If

        If Loads.Load48D = True Then
            PMACSextload.DefInstance.LoadDeadfaceClose_48(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.LoadDeadfaceOpen_48(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.Load_48Deadface(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Lime
        ElseIf Loads.Load48D = False Then
            PMACSextload.DefInstance.LoadDeadfaceClose_48(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadDeadfaceOpen_48(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.Load_48Deadface(Loads.Loadindex - 1).BackColor = System.Drawing.Color.Red
        End If

        'Check load priorty and initialize the configuration frame
        If Loads.LoadPrior = 1 Then
            PMACSextload.DefInstance.LoadHigh(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.LoadMedium(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadLow(Loads.Loadindex - 1).Checked = False
        ElseIf Loads.LoadPrior = 2 Then
            PMACSextload.DefInstance.LoadHigh(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadMedium(Loads.Loadindex - 1).Checked = True
            PMACSextload.DefInstance.LoadLow(Loads.Loadindex - 1).Checked = False
        ElseIf Loads.LoadPrior = 3 Then
            PMACSextload.DefInstance.LoadHigh(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadMedium(Loads.Loadindex - 1).Checked = False
            PMACSextload.DefInstance.LoadLow(Loads.Loadindex - 1).Checked = True
        End If

        'Check the 400V and 48V load current limit and update the configuration frame
        PMACSextload.DefInstance.LabelLoad(Loads.Loadindex - 1).Text = Loads.Load400Name + vbCrLf + Loads.Load48Name
        PMACSextload.DefInstance.LoadID400(Loads.Loadindex - 1).Text = Loads.Load400Name
        PMACSextload.DefInstance.LoadID48(Loads.Loadindex - 1).Text = Loads.Load48Name
        PMACSextload.DefInstance.LoadILimit400(Loads.Loadindex - 1).Text = CStr(Loads.Load400CurrentLimit)
        PMACSextload.DefInstance.LoadILimit48(Loads.Loadindex - 1).Text = CStr(Loads.Load48CurrentLimit)

        'check to see if 400V load current is negative
        'if the value is negative, display zero instead
        If Loads.Load400Current < 0 Then
            PMACSextload.DefInstance.Load_400I(Loads.Loadindex - 1).Text = CStr(Format(0, "0.00")) + " A"
        Else
            PMACSextload.DefInstance.Load_400I(Loads.Loadindex - 1).Text = CStr(Format(Loads.Load400Current, "##0.00")) + " A"
        End If

        'check to see if 48V load current is negative
        'if the value is negative, display zero instead
        If Loads.Load48Current < 0 Then
            PMACSextload.DefInstance.Load_48I(Loads.Loadindex - 1).Text = CStr(Format(0, "0.00")) + " A"
        Else
            PMACSextload.DefInstance.Load_48I(Loads.Loadindex - 1).Text = CStr(Format(Loads.Load48Current, "##0.00")) + " A"
        End If
        'PMACSextload.DefInstance.Load_400I(Loads.Loadindex - 1).Text = CStr(Loads.Load400Current) + " A"
        'PMACSextload.DefInstance.Load_48I(Loads.Loadindex - 1).Text = CStr(Loads.Load48Current) + " A"
    End Function
#End Region

#Region "Initialize MV converter"
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'initialze the converter switch frame display with converter status
    'for 10KV-400V converters A and B
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function MVConverterInitialize(ByRef MVConverters() As MVConverter) As Object
        Dim i As Integer
        'check converter status, 
        'if status = 1, converter is on
        'if status = 0, converter is off
        If MVConverters(0).ConverterStatus = 1 And MVConverters(1).ConverterStatus = 0 Then 'converter A is ON
            'PMACSextload.DefInstance.ConverterA.Checked = True
            'PMACSextload.DefInstance.ConverterB.Checked = False
            PMACSextload.DefInstance.ConA.ForeColor = System.Drawing.Color.Lime
            PMACSextload.DefInstance.ConB.ForeColor = System.Drawing.Color.Red
            PMACSextload.DefInstance.Line6.BorderWidth = 3
            PMACSextload.DefInstance.Line6.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line7.BorderWidth = 3
            PMACSextload.DefInstance.Line7.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line8.BorderWidth = 3
            PMACSextload.DefInstance.Line8.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line11.BorderWidth = 3
            PMACSextload.DefInstance.Line11.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line12.BorderWidth = 3
            PMACSextload.DefInstance.Line12.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line96.Visible = True
            PMACSextload.DefInstance.Line99.Visible = False
            PMACSextload.DefInstance.Line9.BorderWidth = 3
            PMACSextload.DefInstance.Line9.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line10.BorderWidth = 3
            PMACSextload.DefInstance.Line10.BorderDashStyle = Drawing2D.DashStyle.Dash
            'PMACSextload.DefInstance.SciVoltMV.Text = CStr(Format(MVConverters(0).ConverterVoltage, "#0.0")) + " V"
            'PMACSextload.DefInstance.SciCurrMV.Text = CStr(Format(MVConverters(0).ConverterCurrent, "##0.00")) + " A"

            PMACSmvconverter.DefInstance.ConverterAStatus.Text = "Converter A is ON"
            PMACSmvconverter.DefInstance.ConverterBStatus.Text = "Converter B is OFF"
            PMACSmvconverter.DefInstance.MVConverterAStatus.Text = "ON"
            PMACSmvconverter.DefInstance.MVConverterBStatus.Text = "OFF"
            If MVConverters(0).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Red
            End If
            If MVConverters(1).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Red
            End If
            PMACSmvconverter.DefInstance.ConverterAStatus.ForeColor = System.Drawing.Color.Lime
            PMACSmvconverter.DefInstance.ConverterBStatus.ForeColor = System.Drawing.Color.Red
            PMACSmvconverter.DefInstance.MVConverterAInputVDisplay.Text = CStr(Format(MVConverters(0).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterAInputIDisplay.Text = CStr(Format(MVConverters(0).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterAOutputVDisplay.Text = CStr(Format(MVConverters(0).ConverterOutputVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterAOutputIDisplay.Text = CStr(Format(MVConverters(0).ConverterOutputCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterBInputVDisplay.Text = CStr(Format(MVConverters(1).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterBInputIDisplay.Text = CStr(Format(MVConverters(1).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterBOutputVDisplay.Text = "N/A"
            PMACSmvconverter.DefInstance.MVConverterBOutputIDisplay.Text = "N/A"
            If MVConverters(0).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2A.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Open"
            End If
            If MVConverters(1).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Open"
            End If

            For i = 0 To 5
                PMACSmvconverter.DefInstance.MVConverterAStageVoltage(i).Text = CStr(Format(MVConverters(0).ConverterStages(i) / 1000, "#0.0")) + " V"
                PMACSmvconverter.DefInstance.MVConverterBStageVoltage(i).Text = "N/A"
            Next i
        ElseIf MVConverters(0).ConverterStatus = 0 And MVConverters(1).ConverterStatus = 1 Then 'converter B is ON
            'PMACSextload.DefInstance.ConverterA.Checked = False
            'PMACSextload.DefInstance.ConverterB.Checked = True
            PMACSextload.DefInstance.ConA.ForeColor = System.Drawing.Color.Red
            PMACSextload.DefInstance.ConB.ForeColor = System.Drawing.Color.Lime
            PMACSextload.DefInstance.Line9.BorderWidth = 3
            PMACSextload.DefInstance.Line9.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line10.BorderWidth = 3
            PMACSextload.DefInstance.Line10.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line11.BorderWidth = 3
            PMACSextload.DefInstance.Line11.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line12.BorderWidth = 3
            PMACSextload.DefInstance.Line12.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line8.BorderWidth = 3
            PMACSextload.DefInstance.Line8.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line96.Visible = False
            PMACSextload.DefInstance.Line99.Visible = True
            PMACSextload.DefInstance.Line6.BorderWidth = 3
            PMACSextload.DefInstance.Line6.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line7.BorderWidth = 3
            PMACSextload.DefInstance.Line7.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.SciVoltMV.Text = CStr(Format(MVConverters(1).ConverterVoltage, "#0.0")) + " V"
            PMACSextload.DefInstance.SciCurrMV.Text = CStr(Format(MVConverters(1).ConverterCurrent, "##0.00")) + " A"

            PMACSmvconverter.DefInstance.ConverterBStatus.Text = "Converter B is ON"
            PMACSmvconverter.DefInstance.ConverterAStatus.Text = "Converter A is OFF"
            PMACSmvconverter.DefInstance.MVConverterAStatus.Text = "OFF"
            PMACSmvconverter.DefInstance.MVConverterBStatus.Text = "ON"
            If MVConverters(0).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Red
            End If
            If MVConverters(1).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Red
            End If
            PMACSmvconverter.DefInstance.ConverterBStatus.ForeColor = System.Drawing.Color.Lime
            PMACSmvconverter.DefInstance.ConverterAStatus.ForeColor = System.Drawing.Color.Red
            PMACSmvconverter.DefInstance.MVConverterBInputVDisplay.Text = CStr(Format(MVConverters(1).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterBInputIDisplay.Text = CStr(Format(MVConverters(1).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterBOutputVDisplay.Text = CStr(Format(MVConverters(1).ConverterOutputVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterBOutputIDisplay.Text = CStr(Format(MVConverters(1).ConverterOutputCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterAInputVDisplay.Text = CStr(Format(MVConverters(0).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterAInputIDisplay.Text = CStr(Format(MVConverters(0).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterAOutputVDisplay.Text = "N/A"
            PMACSmvconverter.DefInstance.MVConverterAOutputIDisplay.Text = "N/A"
            If MVConverters(0).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2A.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2A.Text = "Open"
            End If
            If MVConverters(1).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Open"
            End If

            For i = 0 To 5
                PMACSmvconverter.DefInstance.MVConverterBStageVoltage(i).Text = CStr(Format(MVConverters(1).ConverterStages(i) / 1000, "#0.0")) + " V"
                PMACSmvconverter.DefInstance.MVConverterAStageVoltage(i).Text = "N/A"
            Next i
        ElseIf MVConverters(0).ConverterStatus = 1 And MVConverters(1).ConverterStatus = 1 Then 'both converters are ON, note: should never happen
            PMACSextload.DefInstance.ConA.ForeColor = System.Drawing.Color.Lime
            PMACSextload.DefInstance.ConB.ForeColor = System.Drawing.Color.Lime
            PMACSextload.DefInstance.Line6.BorderWidth = 3
            PMACSextload.DefInstance.Line6.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line7.BorderWidth = 3
            PMACSextload.DefInstance.Line7.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line8.BorderWidth = 3
            PMACSextload.DefInstance.Line8.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line9.BorderWidth = 3
            PMACSextload.DefInstance.Line9.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line10.BorderWidth = 3
            PMACSextload.DefInstance.Line10.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line11.BorderWidth = 3
            PMACSextload.DefInstance.Line11.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line12.BorderWidth = 3
            PMACSextload.DefInstance.Line12.BorderDashStyle = Drawing2D.DashStyle.Solid
            PMACSextload.DefInstance.Line96.Visible = True
            PMACSextload.DefInstance.Line99.Visible = True
            PMACSmvconverter.DefInstance.ConverterBStatus.ForeColor = System.Drawing.Color.Lime
            PMACSmvconverter.DefInstance.ConverterAStatus.ForeColor = System.Drawing.Color.Lime
            PMACSmvconverter.DefInstance.ConverterAStatus.Text = "Converter A is ON"
            PMACSmvconverter.DefInstance.ConverterBStatus.Text = "Converter B is ON"
            PMACSmvconverter.DefInstance.MVConverterAStatus.Text = "ON"
            PMACSmvconverter.DefInstance.MVConverterBStatus.Text = "ON"
            If MVConverters(0).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Red
            End If
            If MVConverters(1).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Red
            End If
            PMACSmvconverter.DefInstance.MVConverterAInputVDisplay.Text = CStr(Format(MVConverters(0).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterAInputIDisplay.Text = CStr(Format(MVConverters(0).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterAOutputVDisplay.Text = CStr(Format(MVConverters(0).ConverterOutputVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterAOutputIDisplay.Text = CStr(Format(MVConverters(0).ConverterOutputCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterBInputVDisplay.Text = CStr(Format(MVConverters(1).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterBInputIDisplay.Text = CStr(Format(MVConverters(1).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterBOutputVDisplay.Text = CStr(Format(MVConverters(1).ConverterOutputVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterBOutputIDisplay.Text = CStr(Format(MVConverters(1).ConverterOutputCurrent, "##0.00")) + " A"
            If MVConverters(0).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2A.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2A.Text = "Open"
            End If
            If MVConverters(1).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Open"
            End If

            For i = 0 To 5
                PMACSmvconverter.DefInstance.MVConverterAStageVoltage(i).Text = CStr(Format(MVConverters(0).ConverterStages(i) / 1000, "#0.0")) + " V"
                PMACSmvconverter.DefInstance.MVConverterBStageVoltage(i).Text = CStr(Format(MVConverters(1).ConverterStages(i) / 1000, "#0.0")) + " V"
            Next i
        Else    'both converters are OFF
            PMACSextload.DefInstance.ConA.ForeColor = System.Drawing.Color.Red
            PMACSextload.DefInstance.ConB.ForeColor = System.Drawing.Color.Red
            'PMACSextload.DefInstance.ConverterA.Checked = False
            'PMACSextload.DefInstance.ConverterB.Checked = False
            PMACSextload.DefInstance.Line11.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line12.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line99.Visible = False
            PMACSextload.DefInstance.Line9.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line10.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line8.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line96.Visible = False
            PMACSextload.DefInstance.Line6.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSextload.DefInstance.Line7.BorderDashStyle = Drawing2D.DashStyle.Dash
            PMACSmvconverter.DefInstance.ConverterBStatus.ForeColor = System.Drawing.Color.Red
            PMACSmvconverter.DefInstance.ConverterAStatus.ForeColor = System.Drawing.Color.Red
            PMACSmvconverter.DefInstance.ConverterAStatus.Text = "Converter A is OFF"
            PMACSmvconverter.DefInstance.ConverterBStatus.Text = "Converter B is OFF"
            PMACSmvconverter.DefInstance.MVConverterAStatus.Text = "OFF"
            PMACSmvconverter.DefInstance.MVConverterBStatus.Text = "OFF"
            If MVConverters(0).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterAInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterAInputPath.ForeColor = System.Drawing.Color.Red
            End If
            If MVConverters(1).ConverterOK = 1 Then
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "No Fault"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Yellow
            Else
                PMACSmvconverter.DefInstance.MVConverterBInputPath.Text = "Faulted"
                PMACSmvconverter.DefInstance.MVConverterBInputPath.ForeColor = System.Drawing.Color.Red
            End If
            PMACSmvconverter.DefInstance.MVConverterAInputVDisplay.Text = CStr(Format(MVConverters(0).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterAInputIDisplay.Text = CStr(Format(MVConverters(0).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterAOutputVDisplay.Text = CStr(Format(MVConverters(0).ConverterOutputVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterAOutputIDisplay.Text = CStr(Format(MVConverters(0).ConverterOutputCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterBInputVDisplay.Text = CStr(Format(MVConverters(1).ConverterVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterBInputIDisplay.Text = CStr(Format(MVConverters(1).ConverterCurrent, "##0.00")) + " A"
            PMACSmvconverter.DefInstance.MVConverterBOutputVDisplay.Text = CStr(Format(MVConverters(1).ConverterOutputVoltage, "#0.0")) + " V"
            PMACSmvconverter.DefInstance.MVConverterBOutputIDisplay.Text = CStr(Format(MVConverters(1).ConverterOutputCurrent, "##0.00")) + " A"
            If MVConverters(0).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2A.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2A.Text = "Open"
            End If
            If MVConverters(1).ConverterS2Open = 1 Then
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Close"
            Else
                PMACSmvconverter.DefInstance.MVConverterS2B.Text = "Open"
            End If

            For i = 0 To 5
                PMACSmvconverter.DefInstance.MVConverterAStageVoltage(i).Text = CStr(Format(MVConverters(0).ConverterStages(i) / 1000, "#0.0")) + " V"
                PMACSmvconverter.DefInstance.MVConverterBStageVoltage(i).Text = CStr(Format(MVConverters(1).ConverterStages(i) / 1000, "#0.0")) + " V"
            Next i
        End If
    End Function
#End Region

#Region "Initialize 48V internal load"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Initialize the Load Configuration frame for 48V internal load
    '5V internal load are from index 10-16
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function IntLoad48Initialize(ByRef IntLoads As IntLoad48) As Object
        'check switch status
        'if status = true, switch is closed
        'if status = false, switch is opened

        If IntLoads.Load48S = True Then
            'update displays on PMACS48Vintload screen
            PMACS48Vintload.DefInstance.IntLoad48SwitchClose(IntLoads.Loadindex - 10).Checked = True
            PMACS48Vintload.DefInstance.IntLoad48SwitchOpen(IntLoads.Loadindex - 10).Checked = False
            PMACS48Vintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Lime
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.IntLoad48SwitchClose(IntLoads.Loadindex - 10).Checked = True
            PMACSintload.DefInstance.IntLoad48SwitchOpen(IntLoads.Loadindex - 10).Checked = False
            PMACSintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Lime

        Else
            'update displays on PMACS48Vintload screen
            If IntLoads.LoadError = "" Or IntLoads.LoadError = "n/a" Then
                PMACS48Vintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Red
                PMACSintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Red
                'ElseIf IntLoads.LoadError = "over-current" Then
                'PMACS48Vintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Gray
                'PMACSintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Gray
            Else
                'PMACS48Vintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Red
                'PMACSintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Red
                PMACS48Vintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Gray
                PMACSintload.DefInstance.Switch48(IntLoads.Loadindex - 10).BackColor = System.Drawing.Color.Gray
            End If
            PMACS48Vintload.DefInstance.IntLoad48SwitchClose(IntLoads.Loadindex - 10).Checked = False
            PMACS48Vintload.DefInstance.IntLoad48SwitchOpen(IntLoads.Loadindex - 10).Checked = True
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.IntLoad48SwitchClose(IntLoads.Loadindex - 10).Checked = False
            PMACSintload.DefInstance.IntLoad48SwitchOpen(IntLoads.Loadindex - 10).Checked = True

        End If

        'update load current, load current limit, and voltage display
        'with values stored in the data structure
        'update displays on PMACS48Vintload screen
        PMACS48Vintload.DefInstance.LabelIntLoad48(IntLoads.Loadindex - 10).Text = IntLoads.LoadName
        PMACS48Vintload.DefInstance.LoadID48Int(IntLoads.Loadindex - 10).Text = IntLoads.LoadName
        'update displays on PMACSintload screen
        PMACSintload.DefInstance.LabelIntLoad48(IntLoads.Loadindex - 10).Text = IntLoads.LoadName
        PMACSintload.DefInstance.LoadID48Int(IntLoads.Loadindex - 10).Text = IntLoads.LoadName

        'check to see if 48V load current is negative
        'if the value is negative, display zero instead
        If IntLoads.LoadCurrent < 0 Then
            'update displays on PMACS48Vintload screen 
            PMACS48Vintload.DefInstance.Load_48IntI(IntLoads.Loadindex - 10).Text = CStr(Format(0, "0.00")) + " A"
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.Load_48IntI(IntLoads.Loadindex - 10).Text = CStr(Format(0, "0.00")) + " A"
        Else
            'update displays on PMACS48Vintload screen 
            PMACS48Vintload.DefInstance.Load_48IntI(IntLoads.Loadindex - 10).Text = CStr(Format(IntLoads.LoadCurrent, "##0.00")) + " A"
            'update displays on PMACSintload screen 
            PMACSintload.DefInstance.Load_48IntI(IntLoads.Loadindex - 10).Text = CStr(Format(IntLoads.LoadCurrent, "##0.00")) + " A"
        End If
        'update displays on PMACS48Vintload screen
        PMACS48Vintload.DefInstance.Int48ILimit(IntLoads.Loadindex - 10).Text = CStr(IntLoads.LoadCurrentLimit)
        'update displays on PMACSintload screen
        PMACSintload.DefInstance.Int48ILimit(IntLoads.Loadindex - 10).Text = CStr(IntLoads.LoadCurrentLimit)
    End Function
#End Region

#Region "Initialize 12V internal load"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Initialize the Load Configuration frame for 12V internal load
    '5V internal load are from index 3-9
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function IntLoad12Initialize(ByRef IntLoads As IntLoad12) As Object
        'check switch status
        'if status = true, switch is closed
        'if status = false, switch is opened
        If IntLoads.Load12S = True Then
            'update displays on PMACS12Vintload screen
            PMACS12Vintload.DefInstance.IntLoad12SwitchClose(IntLoads.Loadindex - 3).Checked = True
            PMACS12Vintload.DefInstance.IntLoad12SwitchOpen(IntLoads.Loadindex - 3).Checked = False
            PMACS12Vintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Lime
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.IntLoad12SwitchClose(IntLoads.Loadindex - 3).Checked = True
            PMACSintload.DefInstance.IntLoad12SwitchOpen(IntLoads.Loadindex - 3).Checked = False
            PMACSintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Lime
        Else
            If IntLoads.LoadError = "" Or IntLoads.LoadError = "n/a" Then
                PMACS12Vintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Red
                PMACSintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Red
                'ElseIf IntLoads.LoadError = "over-current" Then
                'PMACS12Vintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Gray
                'PMACSintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Gray
            Else
                'PMACS12Vintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Red
                'PMACSintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Red
                PMACS12Vintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Gray
                PMACSintload.DefInstance.Switch12(IntLoads.Loadindex - 3).BackColor = System.Drawing.Color.Gray
            End If
            'update displays on PMACS12Vintload screen
            PMACS12Vintload.DefInstance.IntLoad12SwitchClose(IntLoads.Loadindex - 3).Checked = False
            PMACS12Vintload.DefInstance.IntLoad12SwitchOpen(IntLoads.Loadindex - 3).Checked = True

            'update displays on PMACSintload screen
            PMACSintload.DefInstance.IntLoad12SwitchClose(IntLoads.Loadindex - 3).Checked = False
            PMACSintload.DefInstance.IntLoad12SwitchOpen(IntLoads.Loadindex - 3).Checked = True

        End If

        'update load current, load current limit, and voltage display
        'with values stored in the data structure
        'update displays on PMACS12Vintload screen
        PMACS12Vintload.DefInstance.LabelIntLoad12(IntLoads.Loadindex - 3).Text = IntLoads.LoadName
        PMACS12Vintload.DefInstance.LoadID12Int(IntLoads.Loadindex - 3).Text = IntLoads.LoadName
        'update displays on PMACSintload screen
        PMACSintload.DefInstance.LabelIntLoad12(IntLoads.Loadindex - 3).Text = IntLoads.LoadName
        PMACSintload.DefInstance.LoadID12Int(IntLoads.Loadindex - 3).Text = IntLoads.LoadName


        'check to see if 12V load current is negative
        'if the value is negative, display zero instead
        If IntLoads.LoadCurrent < 0 Then
            'update displays on PMACS12Vintload screen
            PMACS12Vintload.DefInstance.Load_12IntI(IntLoads.Loadindex - 3).Text = CStr(Format(0, "0.00")) + " A"
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.Load_12IntI(IntLoads.Loadindex - 3).Text = CStr(Format(0, "0.00")) + " A"
        Else
            'update displays on PMACS12Vintload screen
            PMACS12Vintload.DefInstance.Load_12IntI(IntLoads.Loadindex - 3).Text = CStr(Format(IntLoads.LoadCurrent, "##0.00")) + " A"
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.Load_12IntI(IntLoads.Loadindex - 3).Text = CStr(Format(IntLoads.LoadCurrent, "##0.00")) + " A"
        End If

        'update displays on PMACS12Vintload screen
        PMACS12Vintload.DefInstance.Int12ILimit(IntLoads.Loadindex - 3).Text = CStr(IntLoads.LoadCurrentLimit)
        'update displays on PMACSintload screen
        PMACSintload.DefInstance.Int12ILimit(IntLoads.Loadindex - 3).Text = CStr(IntLoads.LoadCurrentLimit)
    End Function
#End Region

#Region "Initialize 5V internal load"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Initialize the Load Configuration frame for 5V internal load
    '5V internal load are from index 1-2
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function IntLoad5Initialize(ByRef IntLoads As IntLoad5) As Object
        'check switch status
        'if status = true, switch is closed
        'if status = false, switch is opened
        If IntLoads.Load5S = True Then
            'update displays on PMACS5Vintload screen
            PMACS5Vintload.DefInstance.IntLoad5SwitchClose(IntLoads.Loadindex - 1).Checked = True
            PMACS5Vintload.DefInstance.IntLoad5SwitchOpen(IntLoads.Loadindex - 1).Checked = False
            PMACS5Vintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Lime
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.IntLoad5SwitchClose(IntLoads.Loadindex - 1).Checked = True
            PMACSintload.DefInstance.IntLoad5SwitchOpen(IntLoads.Loadindex - 1).Checked = False
            PMACSintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Lime
        Else
            If IntLoads.LoadError = "" Or IntLoads.LoadError = "n/a" Then
                PMACS5Vintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                PMACSintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                'ElseIf IntLoads.LoadError = "over-current" Then
                'PMACS5Vintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
                'PMACSintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
            Else
                'PMACS5Vintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                'PMACSintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Red
                PMACS5Vintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
                PMACSintload.DefInstance.Switch5(IntLoads.Loadindex - 1).BackColor = System.Drawing.Color.Gray
            End If
            'update displays on PMACS5Vintload screen
            PMACS5Vintload.DefInstance.IntLoad5SwitchClose(IntLoads.Loadindex - 1).Checked = False
            PMACS5Vintload.DefInstance.IntLoad5SwitchOpen(IntLoads.Loadindex - 1).Checked = True

            'update displays on PMACSintload screen
            PMACSintload.DefInstance.IntLoad5SwitchClose(IntLoads.Loadindex - 1).Checked = False
            PMACSintload.DefInstance.IntLoad5SwitchOpen(IntLoads.Loadindex - 1).Checked = True

        End If

        'update load current, load current limit, and voltage display
        'with values stored in the data structure
        'update displays on PMACS5Vintload screen
        PMACS5Vintload.DefInstance.LabelIntLoad5(IntLoads.Loadindex - 1).Text = IntLoads.LoadName
        PMACS5Vintload.DefInstance.LoadID5Int(IntLoads.Loadindex - 1).Text = IntLoads.LoadName
        'update displays on PMACSintload screen
        PMACSintload.DefInstance.LabelIntLoad5(IntLoads.Loadindex - 1).Text = IntLoads.LoadName
        PMACSintload.DefInstance.LoadID5Int(IntLoads.Loadindex - 1).Text = IntLoads.LoadName

        'check to see if 5V load current is negative
        'if the value is negative, display zero instead
        If IntLoads.LoadCurrent < 0 Then
            'update displays on PMACS5Vintload screen
            PMACS5Vintload.DefInstance.Load_5IntI(IntLoads.Loadindex - 1).Text = CStr(Format(0, "0.00")) + " A"
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.Load_5IntI(IntLoads.Loadindex - 1).Text = CStr(Format(0, "0.00")) + " A"
        Else
            'update displays on PMACS5Vintload screen
            PMACS5Vintload.DefInstance.Load_5IntI(IntLoads.Loadindex - 1).Text = CStr(Format(IntLoads.LoadCurrent, "##0.00")) + " A"
            'update displays on PMACSintload screen
            PMACSintload.DefInstance.Load_5IntI(IntLoads.Loadindex - 1).Text = CStr(Format(IntLoads.LoadCurrent, "##0.00")) + " A"
        End If
        'update displays on PMACS5Vintload screen
        PMACS5Vintload.DefInstance.Int5ILimit(IntLoads.Loadindex - 1).Text = CStr(IntLoads.LoadCurrentLimit)
        'update displays on PMACSintload screen
        PMACS5Vintload.DefInstance.Int5ILimit(IntLoads.Loadindex - 1).Text = CStr(IntLoads.LoadCurrentLimit)
    End Function
#End Region

#Region "Initialize Internal Load Housing Power"
    'display housing power on PMACSintload window
    Public Sub IntLoadPowerInitialize()
        PMACSintload.DefInstance.WetHousePower.Text = CStr(Format(PowerWet, "#0.00")) + " W"
        PMACSintload.DefInstance.DryHousePower.Text = CStr(Format(PowerDry, "#0.00")) + " W"
    End Sub
#End Region

#Region "Convert to UTC Time Stamp"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'convert date and time from seconds and microseconds into 
    'UTC time stamp on a 24 hour clock
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Public Function ConvertTime(ByRef Seconds As Integer, ByRef Microseconds As Integer) As String
        Dim myDateTime As String    'store date and time in AM/PM from input seconds
        Dim myMicrosec As Integer    'store input microseconds
        Dim myStringMicrosec As String  'the string to hold microsec
        Dim myDate As String 'store date
        Dim myTime As String 'store time
        Dim mySec As String 'store second, for single digit, it has not 0
        Dim mySecond As String 'store second, for single digit, it has a 0 in front
        Dim myUTCTime As String 'store UTC time
        Dim myFullUTCTime As String 'UTC time with microsecond

        Dim myDatedate As Date      'hold the date in Date format
        Dim myFormatDate As String 'convert date into MMMM dd, yyyy format

        'myDatedate = myDate
        'MsgBox(myDatedate)

        'Convert second from 1970/1/1 to current Date and Time and store in a string
        myDateTime = DateAdd(DateInterval.Second, Seconds, DateSerial(1970, 1, 1))

        'convert microsecond into a string
        If Microseconds / 100000 > 1 Then
            myMicrosec = Microseconds / 1000
        ElseIf Microseconds / 10000 > 1 Then
            myMicrosec = Microseconds / 100
        Else
            myMicrosec = Microseconds / 10
        End If

        myStringMicrosec = CStr(Format(myMicrosec, "###"))

        'MsgBox(Format(Now, "mmmm-yy"))
        myDate = DateValue(myDateTime)  'store the current date
        myDatedate = myDate
        'MsgBox(Format(myDatedate, "MMMM dd, yyyy"))
        'myFormatDate = Format(myDatedate, "MMMM dd, yyyy")
        myFormatDate = Format(myDatedate, "yyyy.MM.dd")
        'MsgBox(myDatedatedate)
        'MsgBox(myDatedate)
        myTime = TimeValue(myDateTime)  'store the current time
        mySec = Second(myTime)          'store the current second
        mySecond = Format(CDbl(mySec), "0#")
        myUTCTime = FormatDateTime(myTime, 4)   'convert time into a 24 clock WITHOUT second

        'store the UTC Date and Time with second and micorsecond
        'in the following format:
        'MM/DD/YYYY HH:MM:SS.microsecond
        myFullUTCTime = myFormatDate + "   " + myUTCTime + ":" + mySecond + "." + myStringMicrosec

        Return myFullUTCTime
    End Function
#End Region

#Region "Load data thread"
    '****************************************************************************
    ' LoadDataWorkerThread()    Programmer: Ting Chan   Date: 01-13-2005
    '
    ' This routine runs as an independent child thread separately from the thread of the
    ' main PMACS client parent thread.  This routine will loop forever
    ' and call the LoadData() which calls the SOAP methods getLoads(), getBuses(),
    ' getSensors(), and getMV()
    '
    ' I am not sure if best strategy is to let this worker thread loop forever or
    ' to exit the thread and start a new worker thread for each request.
    ' But for now I will choose to implement the strategy of letting the worker thread
    ' loop forever.  Note that the worker thread seems to terminate automatically
    ' when the main parent thread aborts so we don't have to do anything special
    ' to get rid of it.
    '
    ' See also:
    ' LoadDataVersionWithCriticalCodeProtected()
    '
    ' Revision History:
    ' 04-06-2005 Modified by Elliott to no longer access control and indicators on the parent thread
    '            directly.  The new child threads will use intermediate public (global)
    '            data variables to indicate the operation desired, to see if operation 
    '            completed, to transfer the input parameters to the SOAP method and to 
    '            transfer the return values from the SOAP method.  The new child threads 
    '            will also use the VB.net Threading.Interlocked.Increment and 
    '            Decrement mechanism to assure that the intermediate variables are not simultaneously 
    '            altered by more than one thread at a time (i.e will assure 'atomic' operation when accessing
    '            the intermediate variables).  Note that we will now need to have timer event routines 
    '            that handle the interaction with the new child thread routines and continuously run.
    ' 
    '****************************************************************************

    Public Sub LoadDataWorkerThread() 'tc new.   'jbe: child thread

        Dim X As Object 'jbe: Dummy work variable.
        Dim Y As Integer
        Dim i As Long
        Dim myDebugStr As String 'debug only
        Dim myPrompt As String 'error string
        Dim response As Integer
        Dim localWantToInvokeSoapLoadDataMethod As Boolean 'jbe: New 04-06-2005 local copy of global wantToInvokeSoapLoadDataMethod.
        Dim tstart As Double 'jbe: Start time for implementing a time-out if program gets stuck.
        Dim elapsed As Double 'jbe: Elapsed time for implementing a time-out if program gets stuck.

        myDebugStr = "" 'debug only

loopAgain:

        'jbe: Make thread sleep for 50 msec in order to give other
        '     threads extra time to execute.  May not be necessary
        '     since the system will automatically pre-empt the
        '     thread and let another thread execute but this insures
        '     we do not spend too much CPU time looping anyway.
        '''PMACSmain.DefInstance.threadLoadData.Sleep(50) '??????????jbe: New 04-06-2005 

        tstart = Microsoft.VisualBasic.Timer        'jbe: Get time in seconds since midnight to nearest 50 msec.

        'jbe: Loop until no other thread is doing a critical code section.
        While lockCriticalCodeCount > 0

            'jbe: Some other thread has locked a critical section of code.
            '     We only want to allow one thread to be doing critical sections of code
            '     at one time.  
            'jbe: Note that none of the thread safe critical sections of code in the PMACS
            '     GUI do any IO or time consuming CPU activity.  Therefore, it is OK to
            '     just loop and wait for another thread to finish its critical code section
            '     since it will not hang up the program for more than a few milliseconds.

            elapsed = System.Math.Abs(tstart - Microsoft.VisualBasic.Timer)

            If elapsed > 30 Then
                'jbe: Have looped for more than 30 seconds.
                '     Should never occur.
                '     Program somehow got stuck in the loop.  So show error message.
                myPrompt = "Error in Sub LoadDataWorkerThread() that is in a child thread." + vbCrLf + vbCrLf
                myPrompt = myPrompt + "Should never occur." + vbCrLf
                myPrompt = myPrompt + "Critical thread safe code has been locked for more than 30 seconds." + vbCrLf
                response = MsgBox(myPrompt, 0, "Error Just BEFORE Critical Code Section For Thread Synchronization")
                globalLastReqestSoapCount = 9999

                'jbe: We may want to abort the program here.  But for now just exit routine and
                '     hope the program recovers and that this error never occurs.
                '     I am not sure but we may need to resset global handshake flags here???? 
                Exit Sub
            End If

        End While 'loop the other thread has completed executing its critical section of code.

        '************************************************************************************** 
        '**************** Critical section of code starts here. *******************************
        '**************************************************************************************

        'jbe: Below is the "Interlocked" keyword.  The variable 'locks' is incremented
        '     using the special 'Increment' method of the 'Interlocked' class so that
        '     the change to the variable is done as an 'atomic' operation so that another
        '     thread cannot sneak in and change the value while the current thread is
        '     simultaneously trying to change it.
        '
        '     In other parts of the code, the program will have if statements to only
        '     allow critical sections of code to execute if variable 'locks' is non-zero 
        '     so that only one thread at a time can make changes to certain variables and controls.
        '     This may help avoid lockups and failures to repaint, etcetera.
        System.Threading.Interlocked.Increment(lockCriticalCodeCount)

        localWantToInvokeSoapLoadDataMethod = wantToInvokeSoapLoadDataMethod

        If localWantToInvokeSoapLoadDataMethod Then
            'jbe: Set ChildThreadHasGotNewValues false so parent thread will know the new
            '     set of values has not yet been received in the child thread.
            ChildThreadHasGotNewValues = False 'jbe: Maybe move into critical code section???
        End If

        '************************************************************************************** 
        '**************** Critical section of code ENDS here. *********************************
        '**************************************************************************************

        'jbe: Decrement global lockCriticalCodeCount so other threads 
        '     will be allowed to execute their own critical code sections.
        System.Threading.Interlocked.Decrement(lockCriticalCodeCount)


        If localWantToInvokeSoapLoadDataMethod Then
            'jbe: It is now OK to invoke SOAP method to get a set of Load Data values.

            Try
                'YES--- ???Maybe need new version of LoadData() just for the thread??????

                'jbeReplacedWithNewThreadSafeVersion X = LoadData(Y)  'jbe: 1 in file Initialization.vb, Sub LoadDataWorkerThread()  IN-CHILD-THREAD
                'jbe: Invoke the version of LoadData() with no references to any Visual control and
                '     with critical code section protected to avoid thread conflict.
                '     When the SOAP data is returned the data will be stored in a global structure.
                '     The type of data being obtained is based on globalRequestSoapRotateCount.

                X = LoadDataVersionWithCriticalCodeProtected(Y)  'jbe: 1 in file Initialization.vb, Sub LoadDataWorkerThread()  IN-CHILD-THREAD

                'jbe: Note that the SOAP data that is obained above is extracted and loaded in 
                '     another routine that resides on the parent thread,  xxxxxx????.

            Catch ex As Exception
                'tc: Some error occurred (probably in the Soap request code).
                '     Display a popup message.
                Beep()
                myPrompt = "Error in getting Load Data over network." + vbCrLf + vbCrLf
                myPrompt = myPrompt + "Possible reasons include the following:" + vbCrLf
                myPrompt = myPrompt + "1. Server could be offline." + vbCrLf
                myPrompt = myPrompt + "2. Network cable could be disconnected." + vbCrLf + vbCrLf
                myPrompt = myPrompt + "Exact text of exception error information is as follows:" + vbCrLf
                myPrompt = myPrompt + ex.ToString()
                'response = MsgBox(myPrompt, 0, "Error Getting Data")
            End Try
        End If

        GoTo loopAgain 'tc: Loop forever

    End Sub 'end LoadDataWorkerThread() (a child thread).

#End Region

#Region "Load Data Thread Version"
    '************************************************************************************************************************
    ' LoadDataVersionWithCriticalCodeProtected()     Programmer: John Elliott     Date: 4-6-2005
    '
    ' Modified version of the old LoadData() routine with no references to any control and
    ' with critical code section protected to avoid thread conflict.
    ' This routine is called from the child thread routine LoadDataWorkerThread().
    ' This routine must not be called from the parent thread!!!!
    '
    ' See also routines:
    ' LoadDataWorkerThread()  - The function that is the child worker thread for all data except the ground fault
    '                           data.
    ' LoadData()              - Similar function to this one but without the thread safe protection of the
    '                           critical code sections.
    ' TimerLoadData_Tick()   -  Event handler routine for general SOAP data items (Loads, busses, etc).    
    '
    ' Input parameters:
    ' globalLastReqestSoapCount  - Global integer to save the last value of globalRequestSoapRotateCount
    '                              for which data was successfully returned to the child thread.
    '                              Usually this will just be one less than globalRequestSoapRotateCount 
    '                              with wrap around, but we will explicitly use a separate variable to 
    '                              make the code more obvious.
    '
    '
    ' Output parameters:
    ' globalRequestSoapRotateCount   - Global count which rotates from 1 to 5.  Used to keep track of what load set to get
    '                                  next from the SOAP method. 1 means want to get external loads.
    '                                  2 means want to get internal load, etc.
    ' globalExtLoadListType - Global structure to temporarily hold the return load values from the SOAP getLoads()
    '                         method when called with argument "/1/external".  These values will later
    '                         be transferred to local variable by routine TimerLoadData_Tick().
    ' globalIntLoadListType - Global structure to temporarily hold the return load values from the SOAP getLoads()
    '                         method when called with argument "/1/internal".  These values will later
    '                         be transferred to local variables by routine TimerLoadData_Tick().
    '                         Used to temporarily hold the data in the child before transferring it to the 
    '                         parent thread.
    ' globalBusListType     - Global structure of type busListType for storing the bus data.   
    '                         Used to temporarily hold the data in the child before transferring 
    '                         it to the parent thread.
    ' globalSensorListType  - Global structure of type globalSensorListType for storing the Sensor data.   
    '                         Used to temporarily hold the data in the child before transferring it to 
    '                         the parent thread.
    ' globalMVType          - Global structure of type mvType for storing the Medium Voltage converter data.   
    '                         Used to temporarily hold the data in the child before transferring it to 
    '                         the parent thread.
    ' ChildThreadHasGotNewValues     - Global flag to indicate that the child thread that gets general SOAP data has
    '                                  received new values after waiting for the call to one of the SOAP methods. 
    '    
    ' Revision History:
    '
    '************************************************************************************************************************

    Public Function LoadDataVersionWithCriticalCodeProtected(ByRef Y As Integer) As Object 'jbe new 04-06-2005

        Dim r As Integer
        Dim c As String
        Dim X As Integer
        Dim i As Integer
        Dim tstart As Double 'jbe: Start time for implementing a time-out if program gets stuck.
        Dim elapsed As Double 'jbe: Elapsed time for implementing a time-out if program gets stuck.
        Dim response As Integer
        Dim myPrompt As String
        Dim myString As String      'the string as input parameter to identify the specific component 

        Dim ws As New edu.washington.apl.pmacs.load_service  'work variable.
        Dim mySensorListType As edu.washington.apl.pmacs.sensorListType 'create a new object instance for sensorListType
        Dim myBusListType As edu.washington.apl.pmacs.busListType       'create a new object instance for busListType
        Dim myExtLoadListType As edu.washington.apl.pmacs.loadListType  'create a new object instance for loadListType, for external load 
        Dim myIntLoadListType As edu.washington.apl.pmacs.loadListType  'create a new object instance for loadListType, for internal load
        Dim myMVType As edu.washington.apl.pmacs.mvType                 'create a new object instance for mvType
        Dim mySpsType As edu.washington.apl.pmacs.spsType               'create a new object instance for spsType

        '****************************************************************************
        'tc: check to see if NPC is online or offline
        '****************************************************************************
        Try
            NPCState = ws.getNPCState
            globalNPCStatus = True
        Catch ex As Exception
            'tc: Some error occurred (probably in the Soap request code).
            '     Display a popup message.
            globalNPCStatus = False
            NPCState = 0
            Beep()
            'myPrompt = MyMsgBoxForm.DefInstance.Label1.Text + vbCrLf + vbCrLf
            myPrompt = myPrompt + "Error in getting Node Power Controller status over network in Function LoadDataVersionWithCriticalCodeProtected()....." + vbCrLf + vbCrLf
            myPrompt = myPrompt + "Possible reasons include the following:" + vbCrLf
            myPrompt = myPrompt + "1. Server could be offline." + vbCrLf
            myPrompt = myPrompt + "2. Network cable could be disconnected." + vbCrLf + vbCrLf
            myPrompt = myPrompt + "Exact text of exception error information is as follows:" + vbCrLf
            myPrompt = myPrompt + ex.ToString() + vbCrLf

            globalLastReqestSoapCount = 9999
        End Try

        If wantPauseLoadDataThread Then
            NPCState = 0
        End If

        Try
            If NPCState = 1 Then    'try getting science node data only when NPC is online
                Try
                    Try
                        myString = "/1/external"

                        '**********************************************************
                        'Load external load data
                        '**********************************************************
                        'Results are stored in structure myExtLoadListType. 
                        myExtLoadListType = ws.getLoads(myString)
                        GotExtLoadData = True
                    Catch ex As Exception
                        GotExtLoadData = False
                        'tc: Some error occurred (probably in the Soap request code).
                        '     Display a popup message.
                        Beep()
                        globalLastReqestSoapCount = 9999
                    End Try

                    Try
                        '**********************************************************
                        'Load internal load data
                        '**********************************************************
                        myString = "/1/internal"     'string to specific the load type, in this case, the internal load at 48V, 12V, and 5V
                        'SOAP method to return load parameters for all loads of specific type  
                        myIntLoadListType = ws.getLoads(myString)
                        GotIntLoadData = True
                    Catch ex As Exception
                        GotIntLoadData = False
                        'tc: Some error occurred (probably in the Soap request code).
                        '     Display a popup message.
                        Beep()
                        globalLastReqestSoapCount = 9999
                    End Try

                    Try
                        '**********************************************************
                        'Get bus data
                        '**********************************************************
                        myString = "/1/bus"
                        'call the server for low voltage bus data   
                        myBusListType = ws.getBuses(myString)
                        GotBusData = True
                    Catch ex As Exception
                        GotBusData = False
                        'tc: Some error occurred (probably in the Soap request code).
                        '     Display a popup message.
                        Beep()
                        globalLastReqestSoapCount = 9999
                    End Try

                    Try
                        '**********************************************************
                        'Load engineering sensors data
                        '**********************************************************
                        myString = "/1/sensor"
                        'call server for engineering sensor data
                        mySensorListType = ws.getSensors(myString)
                        GotSensorData = True
                    Catch ex As Exception
                        GotSensorData = False
                        Beep()
                        globalLastReqestSoapCount = 9999
                    End Try

                    Try
                        '**********************************************************
                        'Load MV converter data
                        '**********************************************************
                        myString = "/1/mv"
                        'call server for MV converter data
                        myMVType = ws.getMV(myString)
                        GotMVData = True
                    Catch ex As Exception
                        GotMVData = False
                        Beep()
                        globalLastReqestSoapCount = 9999
                    End Try

                    If GotExtLoadData Or GotIntLoadData Or GotBusData Or GotSensorData Or GotMVData Then
                        ChildThreadHasGotNewScienceValues = True
                    Else
                        ChildThreadHasGotNewScienceValues = False
                    End If
                Catch ex As Exception
                    ChildThreadHasGotNewScienceValues = False
                    'tc: Some error occurred (probably in the Soap request code).
                    '     Display a popup message.
                    Beep()
                    globalLastReqestSoapCount = 9999
                End Try
            Else
                GotExtLoadData = False
                GotIntLoadData = False
                GotBusData = False
                GotSensorData = False
                GotMVData = False
                ChildThreadHasGotNewScienceValues = False
            End If

            Try
                '**********************************************************
                'Load shore power supply data
                '**********************************************************
                myString = "/psc"
                mySpsType = ws.getSPS(myString)
                ChildThreadHasGotNewShoreValues = True
                GotShoreData = True
            Catch ex As Exception
                ChildThreadHasGotNewShoreValues = False
                GotShoreData = False
                'tc: Some error occurred (probably in the Soap request code).
                '     Display a popup message.
                Beep()
                globalLastReqestSoapCount = 9999
            End Try

            'jbe: Set global integer globalLastReqestSoapCount to indicate what type of data was most recently received.
            '     This will later be copied into a local variable under a protected code section.
            globalLastReqestSoapCount = globalRequestSoapRotateCount

            If ChildThreadHasGotNewShoreValues = True Or ChildThreadHasGotNewScienceValues = True Then
                'jbe: Set the global flag ChildThreadHasGotNewValues true so that the
                '     parent thread will know that new SOAP data is available in the
                '     global structures.
                ChildThreadHasGotNewValues = True
            Else
                ChildThreadHasGotNewValues = False
                wantToInvokeSoapLoadDataMethod = True
            End If

        Catch ex As Exception

        End Try


        '************************************************************************************** 
        '**************** Critical section of code starts here. *******************************
        '**************************************************************************************

        tstart = Microsoft.VisualBasic.Timer        'jbe: Get time in seconds since midnight to nearest 50 msec.

        'jbe: Loop until no other thread is doing a critical code section.
        While lockCriticalCodeCount > 0
            'jbe: Some other thread has locked a critical section of code.
            '     We only want to allow one thread to be doing critical sections of code
            '     at one time.  
            'jbe: Note that none of the thread safe critical sections of code in the PMACS
            '     GUI do any IO or time consuming CPU activity.  Therefore, it is OK to
            '     just loop and wait for another thread to finish its critical code section
            '     since it will not hang up the program for more than a few milli

            elapsed = System.Math.Abs(tstart - Microsoft.VisualBasic.Timer)

            If elapsed > 30 Then
                'jbe: Have looped for more than 30 seconds.
                '     Should never occur.
                '     Program somehow got stuck in the loop.  So show error message.
                myPrompt = "Error in Sub LoadDataVersionWithCriticalCodeProtected()." + vbCrLf + vbCrLf
                myPrompt = myPrompt + "Should never occur.  TIMEOUT." + vbCrLf
                myPrompt = myPrompt + "Critical thread safe code has been locked for more than 30 seconds." + vbCrLf
                response = MsgBox(myPrompt, 0, "Error Just BEFORE Critical Code Section For Thread Synchronization")
                globalLastReqestSoapCount = 9999
                Exit Function
            End If

        End While 'loop until the other thread has completed executing its critical section of code.

        'jbe: Below is the "Interlocked" keyword.  The global variable 'locks' is incremented
        '     using the special 'Increment' method of the 'Interlocked' class so that
        '     the change to the variable is done as an 'atomic' operation so that another
        '     thread cannot sneak in and change the value while the current thread is
        '     simultaneously trying to change it.
        '
        '     In other parts of the code, the program will have if statements to only
        '     allow critical sections of code to execute if variable 'locks' is non-zero 
        '     so that only one thread at a time can make changes to certain variables and controls.
        '     This may help avoid lockups and failures to repaint, etcetera.
        System.Threading.Interlocked.Increment(lockCriticalCodeCount)

        '************************************************************************************** 
        '**************** Critical section of code starts here. *******************************
        '**************************************************************************************

        If lockCriticalCodeCount <> 1 Then
            'jbe: Error. Should never occur.
            '     Must be a flaw in my logic.
            myPrompt = "Error in Sub LoadDataVersionWithCriticalCodeProtected()." + vbCrLf + vbCrLf
            myPrompt = myPrompt + "Should never occur." + vbCrLf
            myPrompt = myPrompt + "Value of lockCriticalCodeCount =" + vbCrLf
            myPrompt = myPrompt + Str$(lockCriticalCodeCount)
            myPrompt = myPrompt + "Should only be 1 here." + vbCrLf + vbCrLf
            myPrompt = myPrompt + "This must be a flaw in thread critical code section logic." + vbCrLf
            myPrompt = myPrompt + "The code fix to avoid thread conflict does NOT work!!!" + vbCrLf
            response = MsgBox(myPrompt, 0, "Error In Critical Code Section For Thread Synchronization")

            'jbe: Set globalLastReqestSoapCount to a special value to indicate an error occurred
            '     to the parent thread will not try to update the GUI displays with bad data.
            globalLastReqestSoapCount = 9999

            'jbe: We may want to abort the program here.  But for now just let it run and
            '     hope this error never occurs.
        End If

        'jbe: Copy the new SOAP data from the local structure to a global structure. 
        '     This must be done in an 'atomic' manner (within critical code section here)
        '     to avoid thread conflicts.

        globalExtLoadListType = myExtLoadListType
        globalIntLoadListType = myIntLoadListType
        globalBusListType = myBusListType
        globalSensorListType = mySensorListType
        globalMVType = myMVType
        globalSpsType = mySpsType

        'tc: Comment out on 06-01-2005 by Ting Chan
        '    The flag is set in previous section already
        'jbe: Set the global flag ChildThreadHasGotNewValues true so that the
        '     parent thread will know that new SOAP data is available in the
        '     global structures.
        'ChildThreadHasGotNewValues = True

        '************************************************************************************** 
        '**************** Critical section of code ENDS here. *********************************
        '**************************************************************************************

        'jbe: Decrement global lockCriticalCodeCount so other threads 
        '     will be allowed to execute their own critical code sections.
        System.Threading.Interlocked.Decrement(lockCriticalCodeCount)

    End Function 'end LoadDataVersionWithCriticalCodeProtected()

#End Region

#Region "Restore to Default"
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'When the user click on the Default button, PMACS will restore
    'all settings to its deafault state.
    'All current limit = 1A
    'All switches status = open
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Public Function DefaultData(ByRef Y As Integer) As Object
        Dim i As Integer
        Dim X As Integer
        Dim IndexString As String
        'Dim Inttsecs As Integer
        'Dim Inttusecs As Integer
        Dim Exttsecs As Integer
        Dim Exttusecs As Integer
        Dim myString As String 'work variable.
        Dim result As String
        Dim ws As New edu.washington.apl.pmacs.load_service  'work variable.
        Dim myExtLoadUpdateType As New edu.washington.apl.pmacs.loadUpdateType
        Dim myIntLoadUpdateType As New edu.washington.apl.pmacs.loadUpdateType
        'Dim myIntLoadUpdateType As New edu.washington.apl.pmacs.loadUpdateType
        'Dim myExtLoadListType As edu.washington.apl.pmacs.loadListType  'comment out on 4/27/05 due to change in setload()
        'Dim myIntLoadListType As edu.washington.apl.pmacs.loadListType
        Dim myDateTime As String
        Dim myMicrosec As String

        'Reset all external load settings
        'for both 400V and 48V
        'current = 0
        'current limit = 1A
        'status = 0(off) except internal Load 1, 15 and 16 which are default ON

        If Y = 1 Then
            For i = 0 To 7
                IndexString = CStr(i + 1)
                myString = "/1/external/" + IndexString + "/v48"
                If Loads(i).LoadState48 = -1 Then
                    myExtLoadUpdateType.state = -1
                Else
                    myExtLoadUpdateType.state = 0
                End If
                myExtLoadUpdateType.current_limit = 1000
                result = ws.setLoad(myString, myExtLoadUpdateType)
            Next
            For i = 0 To 7
                myString = "/1/external/" + CStr(i + 1) + "/v400"
                If Loads(i).LoadState400 = -1 Then
                    myExtLoadUpdateType.state = -1
                Else
                    myExtLoadUpdateType.state = 0
                End If
                myExtLoadUpdateType.current_limit = 1000
                result = ws.setLoad(myString, myExtLoadUpdateType)
            Next
            'myExtLoadUpdateType.state = 0
            'myExtLoadUpdateType.current_limit = 1000

            'myExtLoadListType = ws.setLoad(myString, myExtLoadUpdateType) 'comment out on 4/27/05 due to change in setload()
            'result = ws.setLoad(myString, myExtLoadUpdateType)
        ElseIf Y = 2 Then   'All Internal Load
            For i = 0 To 1
                IndexString = CStr(i + 1)
                myString = "/1/internal/" + IndexString
                If i = 0 Then
                    myIntLoadUpdateType.state = 1
                Else
                    myIntLoadUpdateType.state = 0
                End If
                myIntLoadUpdateType.current_limit = IntLoads5(i).DefaultCurrentLimit * 1000
                result = ws.setLoad(myString, myIntLoadUpdateType)
            Next

            For i = 0 To 6
                IndexString = CStr(i + 3)
                myString = "/1/internal/" + IndexString
                myIntLoadUpdateType.state = 0
                myIntLoadUpdateType.current_limit = IntLoads12(i).DefaultCurrentLimit * 1000
                result = ws.setLoad(myString, myIntLoadUpdateType)
            Next

            For i = 0 To 6
                IndexString = CStr(i + 10)
                myString = "/1/internal/" + IndexString
                If i = 5 Or i = 6 Then
                    myIntLoadUpdateType.state = 1
                Else
                    myIntLoadUpdateType.state = 0
                End If

                myIntLoadUpdateType.current_limit = IntLoads48(i).DefaultCurrentLimit * 1000
                result = ws.setLoad(myString, myIntLoadUpdateType)
            Next
        ElseIf Y = 3 Then   '5V internal Load
            For i = 0 To 1
                IndexString = CStr(i + 1)
                myString = "/1/internal/" + IndexString
                If i = 0 Then
                    myIntLoadUpdateType.state = 1
                Else
                    myIntLoadUpdateType.state = 0
                End If
                myIntLoadUpdateType.current_limit = IntLoads5(i).DefaultCurrentLimit * 1000
                result = ws.setLoad(myString, myIntLoadUpdateType)
            Next
        ElseIf Y = 4 Then   '12V Internal Load
            For i = 0 To 6
                IndexString = CStr(i + 3)
                myString = "/1/internal/" + IndexString
                myIntLoadUpdateType.state = 0
                myIntLoadUpdateType.current_limit = IntLoads12(i).DefaultCurrentLimit * 1000
                result = ws.setLoad(myString, myIntLoadUpdateType)
            Next
        ElseIf Y = 5 Then   '48V Internal Load
            For i = 0 To 6
                IndexString = CStr(i + 10)
                myString = "/1/internal/" + IndexString
                If i = 5 Or i = 6 Then
                    myIntLoadUpdateType.state = 1
                Else
                    myIntLoadUpdateType.state = 0
                End If

                myIntLoadUpdateType.current_limit = IntLoads48(i).DefaultCurrentLimit * 1000
                result = ws.setLoad(myString, myIntLoadUpdateType)
            Next
        End If
    End Function
#End Region

End Module