Skip to content

Commit 4d58c43

Browse files
committed
Smaller socket updates
- Removed redundant IsConnected property in favor of ConnectionStatus - Renamed Nut and Net version properties and converted them to auto-implemented properties. - Wrapped version query statements in try-catch blocks in case servers that throw an error for these queries (Synology in particular) may not have further problems with other queries. - Added support for Net version 1.3
1 parent ef6ce51 commit 4d58c43

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,15 @@ Public Class Nut_Socket
1010
End Get
1111
End Property
1212

13-
Public ReadOnly Property IsConnected() As Boolean
14-
Get
15-
Return ConnectionStatus
16-
End Get
17-
End Property
18-
1913
Private _isLoggedIn As Boolean = False
2014
Public ReadOnly Property IsLoggedIn() As Boolean
2115
Get
2216
Return _isLoggedIn
2317
End Get
2418
End Property
2519

26-
Private Nut_Ver As String
27-
Public ReadOnly Property Nut_Version() As String
28-
Get
29-
Return Nut_Ver
30-
End Get
31-
End Property
32-
33-
Private Net_Ver As String
34-
Public ReadOnly Property Net_Version() As String
35-
Get
36-
Return Net_Ver
37-
End Get
38-
End Property
20+
Public ReadOnly Property NUTVersion As String
21+
Public ReadOnly Property NetVersion As String
3922
#End Region
4023

4124
Private LogFile As Logger
@@ -80,23 +63,37 @@ Public Class Nut_Socket
8063

8164
LogFile.LogTracing("Connection established and streams ready.", LogLvl.LOG_NOTICE, Me)
8265

66+
LogFile.LogTracing("Gathering basic info about the NUT server...", LogLvl.LOG_DEBUG, Me)
67+
68+
Try
69+
Dim Nut_Query = Query_Data("VER")
70+
71+
If Nut_Query.ResponseType = NUTResponse.OK Then
72+
_NUTVersion = (Nut_Query.RawResponse.Split(" "c))(4)
73+
LogFile.LogTracing("Server version: " & NUTVersion, LogLvl.LOG_NOTICE, Me)
74+
End If
75+
Catch nutEx As NutException
76+
LogFile.LogTracing("Error retrieving server version.", LogLvl.LOG_WARNING, Me)
77+
LogFile.LogException(nutEx, Me)
78+
End Try
79+
80+
Try
81+
Dim Nut_Query = Query_Data("NETVER")
82+
83+
If Nut_Query.ResponseType = NUTResponse.OK Then
84+
_NetVersion = Nut_Query.RawResponse
85+
LogFile.LogTracing("Protocol version: " & NetVersion, LogLvl.LOG_NOTICE, Me)
86+
End If
87+
Catch nutEx As NutException
88+
LogFile.LogTracing("Error retrieving protocol version.", LogLvl.LOG_WARNING, Me)
89+
LogFile.LogException(nutEx, Me)
90+
End Try
91+
92+
LogFile.LogTracing("Completed gathering basic info about NUT server.", LogLvl.LOG_DEBUG, Me)
8393
Catch Excep As Exception
8494
Disconnect(True)
8595
Throw ' Pass exception on up to UPS
8696
End Try
87-
88-
Dim Nut_Query = Query_Data("VER")
89-
90-
If Nut_Query.ResponseType = NUTResponse.OK Then
91-
Nut_Ver = (Nut_Query.RawResponse.Split(" "c))(4)
92-
End If
93-
Nut_Query = Query_Data("NETVER")
94-
95-
If Nut_Query.ResponseType = NUTResponse.OK Then
96-
Net_Ver = Nut_Query.RawResponse
97-
End If
98-
99-
LogFile.LogTracing(String.Format("NUT server reports VER: {0} NETVER: {1}", Nut_Ver, Net_Ver), LogLvl.LOG_NOTICE, Me)
10097
End Sub
10198

10299
Public Sub Login()
@@ -169,7 +166,7 @@ Public Class Nut_Socket
169166
Response = NUTResponse.ENDLIST
170167
Case "ERR"
171168
Response = DirectCast([Enum].Parse(GetType(NUTResponse), SplitString(1)), NUTResponse)
172-
Case "NETWORK", "1.0", "1.1", "1.2"
169+
Case "NETWORK", "1.0", "1.1", "1.2", "1.3"
173170
'In case of "VER" or "NETVER" Query
174171
Response = NUTResponse.OK
175172
Case Else

WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Public Class UPS_Device
2525

2626
Public ReadOnly Property IsConnected As Boolean
2727
Get
28-
Return (Nut_Socket.IsConnected)
28+
Return (Nut_Socket.ConnectionStatus)
2929
End Get
3030
End Property
3131
Public ReadOnly Property IsLoggedIn As Boolean

0 commit comments

Comments
 (0)