Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions WinNUT_V2/WinNUT-Client/My Project/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,11 @@
<Setting Name="IsFirstRun" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="CAL_PowerFactor" Type="System.Double" Scope="User">
<Value Profile="(Default)">0.95</Value>
</Setting>
<Setting Name="CAL_ApparentPowerNom" Type="System.Int32" Scope="User">
<Value Profile="(Default)">2400</Value>
</Setting>
</Settings>
</SettingsFile>
18 changes: 18 additions & 0 deletions WinNUT_V2/WinNUT-Client/Pref_Gui.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions WinNUT_V2/WinNUT-Client/Pref_Gui.vb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Public Class Pref_Gui
Try
LogFile.LogTracing("Save Parameters.", LogLvl.LOG_DEBUG, Me)
My.Settings.NUT_ServerAddress = Tb_Server_IP.Text
My.Settings.CAL_PowerFactor = CDbl(Tb_Cal_PowerFactor.Value)
My.Settings.CAL_ApparentPowerNom = CInt(Tb_Cal_ApparentPowerNom.Value)
My.Settings.NUT_ServerPort = CInt(Tb_Port.Text)
My.Settings.NUT_UPSName = Tb_UPS_Name.Text
My.Settings.NUT_PollIntervalMsec = CInt(pollingIntervalValue.Value * 1000D)
Expand Down Expand Up @@ -303,6 +305,14 @@ Public Class Pref_Gui
Private Sub Pref_Gui_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Icon = WinNUT.Icon
LogFile.LogTracing("Load Pref Gui", LogLvl.LOG_DEBUG, Me)
Try
Tb_Cal_PowerFactor.Value = CDbl(My.Settings.CAL_PowerFactor)
Catch
End Try
Try
Tb_Cal_ApparentPowerNom.Value = CInt(My.Settings.CAL_ApparentPowerNom)
Catch
End Try
End Sub

''' <summary>
Expand Down
2 changes: 2 additions & 0 deletions WinNUT_V2/WinNUT-Client/WinNUT-client.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />

<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Deployment" />
Expand Down
7 changes: 7 additions & 0 deletions WinNUT_V2/WinNUT-Client/WinNUT.vb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ Public Class WinNUT
My.Settings.NUT_UPSName,
My.Settings.NUT_AutoReconnect)

' Apply user-tunable watt-calculation knobs from My.Settings before
' instantiating the device. These are shared via UPS_Device.RuntimeConfig
' because UPS_Device lives in the Common assembly where My.Settings is
' not available.
UPS_Device.RuntimeConfig.PowerFactor = My.Settings.CAL_PowerFactor
UPS_Device.RuntimeConfig.ApparentPowerNomVA = My.Settings.CAL_ApparentPowerNom

UPS_Device = New UPS_Device(Nut_Config, LogFile, My.Settings.NUT_PollIntervalMsec, My.Settings.CAL_FreqInNom)
AddHandler UPS_Device.EncounteredNUTException, AddressOf HandleNUTException
UPS_Device.Connect_UPS(retryOnConnFailure)
Expand Down
29 changes: 26 additions & 3 deletions WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@ Imports System.Windows.Forms
Public Class UPS_Device
#Region "Statics/Defaults"
Private ReadOnly INVARIANT_CULTURE = CultureInfo.InvariantCulture
Private Const POWER_FACTOR = 0.8
Private Const POWER_FACTOR_DEFAULT = 0.95
Private Const APPARENT_POWER_DEFAULT = 2400

' Shared configuration holder. The Client project sets this once
' before instantiating UPS_Device, so the Common assembly does not
' need to reference My.Settings (which is scoped to the Client
' project only).
Public NotInheritable Class RuntimeConfig
Public Shared PowerFactor As Double = POWER_FACTOR_DEFAULT
Public Shared ApparentPowerNomVA As Integer = APPARENT_POWER_DEFAULT
End Class

Private ReadOnly Property POWER_FACTOR As Double
Get
Dim pf = RuntimeConfig.PowerFactor
If pf <= 0.0 OrElse pf > 1.0 Then Return POWER_FACTOR_DEFAULT
Return pf
End Get
End Property

' How many milliseconds to wait before the Reconnect routine tries again.
Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 5000
Expand Down Expand Up @@ -353,8 +371,13 @@ Public Class UPS_Device
parsedValue = Single.Parse(GetUPSVar("output.realpower"), INVARIANT_CULTURE)

Case PowerMethod.RPNomLoadPct
parsedValue = Double.Parse(GetUPSVar("ups.realpower.nominal"), INVARIANT_CULTURE)
parsedValue *= UPS_Datas.UPS_Value.Load / 100.0
Dim rpNom As Double
Try
rpNom = Double.Parse(GetUPSVar("ups.realpower.nominal"), INVARIANT_CULTURE)
Catch
rpNom = Config.ApparentPowerNomVA
End Try
parsedValue = rpNom * UPS_Datas.UPS_Value.Load / 100.0

Case PowerMethod.InputNomVALoadPct
Dim nomCurrent = Double.Parse(GetUPSVar("input.current.nominal"), INVARIANT_CULTURE)
Expand Down
2 changes: 2 additions & 0 deletions WinNUT_V2/WinNUT-Client_Common/WinNUT-Client_Common.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />

<Reference Include="System.Net.Http" />
<Reference Include="System.Security" />
<Reference Include="System.Windows.Forms" />
Expand Down