Skip to content

Commit 592ecd7

Browse files
authored
Merge pull request #52 from nutdotnet/45-fix-listvargui
Fix List_Var_Gui error
2 parents a8e8a04 + 3821312 commit 592ecd7

File tree

4 files changed

+48
-35
lines changed

4 files changed

+48
-35
lines changed

WinNUT_V2/WinNUT-Client/List_Var_Gui.vb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ Imports WinNUT_Client_Common
1111

1212
Public Class List_Var_Gui
1313
Private List_Var_Datas As List(Of UPS_List_Datas)
14+
Private UPSDevice As UPS_Device
1415
Private UPS_Name = WinNUT.UPS_Device.Nut_Config.UPSName
1516

17+
Public Sub New(upsDev As UPS_Device)
18+
' This call is required by the designer.
19+
InitializeComponent()
20+
21+
' Add any initialization after the InitializeComponent() call.
22+
UPSDevice = upsDev
23+
End Sub
24+
1625
Private Sub List_Var_Gui_Load(sender As Object, e As EventArgs) Handles MyBase.Load
1726
LogFile.LogTracing("Load List Var Gui", LogLvl.LOG_DEBUG, Me)
1827
Icon = WinNUT.Icon
@@ -22,10 +31,13 @@ Public Class List_Var_Gui
2231
End Sub
2332

2433
Private Sub PopulateTreeView()
25-
Dim action As Action
2634
LogFile.LogTracing("Populate TreeView", LogLvl.LOG_DEBUG, Me)
35+
Dim action As Action
36+
2737
Try
38+
UPSDevice.IsUpdatingData = False
2839
List_Var_Datas = WinNUT.UPS_Device.GetUPS_ListVar()
40+
UPSDevice.IsUpdatingData = True
2941
Catch ex As Exception
3042
' TODO: Internationalize?
3143
MessageBox.Show("Error encountered trying to get variables from the UPS: " & vbNewLine & ex.Message, "Error Encountered")

WinNUT_V2/WinNUT-Client/WinNUT.vb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,9 +1003,8 @@ Public Class WinNUT
10031003

10041004
Private Sub Menu_UPS_Var_Click(sender As Object, e As EventArgs) Handles Menu_UPS_Var.Click
10051005
LogFile.LogTracing("Open List Var Gui", LogLvl.LOG_DEBUG, Me)
1006-
List_Var_Gui.Activate()
1007-
List_Var_Gui.Visible = True
1008-
HasFocus = False
1006+
Dim lvgForm = New List_Var_Gui(UPS_Device)
1007+
lvgForm.Show()
10091008
End Sub
10101009

10111010
Public Sub Update_InstantLog(sender As Object) Handles LogFile.NewData

WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ Public Class Nut_Socket
190190
''' <returns>The full <see cref="Transaction"/> of this function call.</returns>
191191
''' <exception cref="InvalidOperationException">Thrown when calling this function while disconnected.</exception>"
192192
''' <exception cref="NutException">Thrown when the NUT server returns an error or unexpected response.</exception>
193-
Function Query_Data(Query_Msg As String) As Transaction ' (Data As String, Response As NUTResponse)
193+
Function Query_Data(Query_Msg As String) As Transaction
194194
Dim Response As NUTResponse
195195
Dim DataResult As String
196196
Dim finalTransaction As Transaction
197-
' Try
197+
198198
If streamInUse Then
199199
LogFile.LogTracing("Attempted to query " & Query_Msg & " while using the stream.", LogLvl.LOG_ERROR, Me)
200200
Return Nothing
@@ -203,11 +203,12 @@ Public Class Nut_Socket
203203
streamInUse = True
204204

205205
If ConnectionStatus Then
206-
' LogFile.LogTracing("Sending query " & Query_Msg, LogLvl.LOG_DEBUG, Me)
206+
' LogFile.LogTracing("Query: " & Query_Msg, LogLvl.LOG_DEBUG, Me)
207207
WriterStream.WriteLine(Query_Msg & vbCr)
208208
WriterStream.Flush()
209209

210210
DataResult = Trim(ReaderStream.ReadLine())
211+
' LogFile.LogTracing(vbTab & "Response: " & DataResult, LogLvl.LOG_DEBUG, Me)
211212
streamInUse = False
212213
' LogFile.LogTracing("Done processing response for query " & Query_Msg, LogLvl.LOG_DEBUG, Me)
213214

@@ -240,13 +241,15 @@ Public Class Nut_Socket
240241
streamInUse = True
241242
Dim readLine As String
242243

243-
Do
244+
While True
244245
readLine = ReaderStream.ReadLine()
245-
If readLine.StartsWith("END") Then
246-
Exit Do
246+
247+
If Not readLine.StartsWith("END") Then
248+
List_Datas.Add(readLine)
249+
Else
250+
Exit While
247251
End If
248-
List_Datas.Add(readLine)
249-
Loop Until (IsNothing(readLine) Or (ReaderStream.Peek < 0))
252+
End While
250253

251254
streamInUse = False
252255
' LogFile.LogTracing("Done processing LIST response for query " & Query_Msg, LogLvl.LOG_DEBUG, Me)
@@ -262,21 +265,17 @@ Public Class Nut_Socket
262265
'Query
263266
'LIST VAR <upsname>
264267
'Response List of var
265-
'VAR <upsname> <varname> "<value>"
268+
'VAR <upsname><varname> "<value>"
266269
Key = Replace(SplitString(2), """", "")
267270
Value = Replace(SplitString(3), """", "")
268271
Dim UPSName = SplitString(1)
269272
Dim VarDESC = GetVarDescription(Key)
270-
If Not IsNothing(VarDESC) Then
271-
List_Result.Add(New UPS_List_Datas With {
273+
List_Result.Add(New UPS_List_Datas With {
272274
.VarKey = Key,
273275
.VarValue = Trim(Value),
274-
.VarDesc = Split(Replace(VarDESC, """", ""), " ", 4)(3)}
276+
.VarDesc = If(Not IsNothing(VarDESC), Split(Replace(VarDESC, """", ""), " ", 4)(3), String.Empty)}
275277
)
276-
Else
277-
'TODO: Convert to nut_exception error
278-
Throw New Exception("error")
279-
End If
278+
280279
Case "UPS"
281280
'Query
282281
'LIST UPS
@@ -291,7 +290,7 @@ Public Class Nut_Socket
291290
'Query
292291
'LIST RW <upsname>
293292
'List of RW var
294-
'RW <upsname> <varname> "<value>"
293+
'RW <upsname><varname> "<value>"
295294
Key = Replace(SplitString(2), """", "")
296295
Value = Replace(SplitString(3), """", "")
297296
Dim UPSName = SplitString(1)
@@ -300,7 +299,7 @@ Public Class Nut_Socket
300299
List_Result.Add(New UPS_List_Datas With {
301300
.VarKey = Key,
302301
.VarValue = Trim(Value),
303-
.VarDesc = Split(Replace(VarDESC, """", ""), " ", 4)(3)}
302+
.VarDesc = If(Not IsNothing(VarDESC), Split(Replace(VarDESC, """", ""), " ", 4)(3), String.Empty)}
304303
)
305304
Else
306305
'TODO: Convert to nut_exception error
@@ -310,12 +309,12 @@ Public Class Nut_Socket
310309
'Query
311310
'LIST CMD <upsname>
312311
'List of CMD
313-
'CMD <upsname> <cmdname>
312+
'CMD <upsname><cmdname>
314313
Case "ENUM"
315314
'Query
316315
'LIST ENUM <upsname>
317316
'List of Enum ??
318-
'ENUM <upsname> <varname> "<value>"
317+
'ENUM <upsname><varname> "<value>"
319318
Key = Replace(SplitString(2), """", "")
320319
Value = Replace(SplitString(3), """", "")
321320
Dim UPSName = SplitString(1)
@@ -332,14 +331,14 @@ Public Class Nut_Socket
332331
End If
333332
Case "RANGE"
334333
'Query
335-
'LIST RANGE <upsname> <varname>
334+
'LIST RANGE <upsname><varname>
336335
'List of Range
337-
'RANGE <upsname> <varname> "<min>" "<max>"
336+
'RANGE <upsname><varname> "<min>" "<max>"
338337
Case "CLIENT"
339338
'Query
340339
'LIST CLIENT <upsname>
341340
'List of Range
342-
'CLIENT <device name> <client IP address>
341+
'CLIENT <device name><client IP address>
343342
End Select
344343
Next
345344

WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ Public Class UPS_Device
4040
End Set
4141
End Property
4242

43+
Public Property IsUpdatingData As Boolean
44+
Get
45+
Return Update_Data.Enabled
46+
End Get
47+
Set(value As Boolean)
48+
LogFile.LogTracing("UPS device updating status is now [" & value & "]", LogLvl.LOG_NOTICE, Me)
49+
Update_Data.Enabled = value
50+
End Set
51+
End Property
52+
4353
Private upsData As UPSData
4454
Public Property UPS_Datas As UPSData
4555
Get
@@ -303,15 +313,8 @@ Public Class UPS_Device
303313
Try
304314
Dim UPS_rt_Status As String
305315
Dim InputA As Double
306-
' LogFile.LogTracing("Enter Retrieve_UPS_Data", LogLvl.LOG_DEBUG, Me)
307-
If IsConnected Then
308-
'With UPS_Datas
309-
' Select Case "Unknown"
310-
' Case .Mfr, .Model, .Serial, .Firmware
311-
' UPS_Datas = GetUPSProductInfo()
312-
' End Select
313-
'End With
314316

317+
If IsConnected Then
315318
With UPS_Datas.UPS_Value
316319
.Batt_Charge = Double.Parse(GetUPSVar("battery.charge", 255), ciClone)
317320
.Batt_Voltage = Double.Parse(GetUPSVar("battery.voltage", 12), ciClone)

0 commit comments

Comments
 (0)