@@ -190,11 +190,11 @@ Public Class Nut_Socket
190
190
''' <returns>The full <see cref="Transaction"/> of this function call.</returns>
191
191
''' <exception cref="InvalidOperationException">Thrown when calling this function while disconnected.</exception>"
192
192
''' <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
194
194
Dim Response As NUTResponse
195
195
Dim DataResult As String
196
196
Dim finalTransaction As Transaction
197
- ' Try
197
+
198
198
If streamInUse Then
199
199
LogFile.LogTracing( "Attempted to query " & Query_Msg & " while using the stream." , LogLvl.LOG_ERROR, Me )
200
200
Return Nothing
@@ -203,11 +203,12 @@ Public Class Nut_Socket
203
203
streamInUse = True
204
204
205
205
If ConnectionStatus Then
206
- ' LogFile.LogTracing("Sending query " & Query_Msg, LogLvl.LOG_DEBUG, Me)
206
+ ' LogFile.LogTracing("Query: " & Query_Msg, LogLvl.LOG_DEBUG, Me)
207
207
WriterStream.WriteLine(Query_Msg & vbCr)
208
208
WriterStream.Flush()
209
209
210
210
DataResult = Trim(ReaderStream.ReadLine())
211
+ ' LogFile.LogTracing(vbTab & "Response: " & DataResult, LogLvl.LOG_DEBUG, Me)
211
212
streamInUse = False
212
213
' LogFile.LogTracing("Done processing response for query " & Query_Msg, LogLvl.LOG_DEBUG, Me)
213
214
@@ -240,13 +241,15 @@ Public Class Nut_Socket
240
241
streamInUse = True
241
242
Dim readLine As String
242
243
243
- Do
244
+ While True
244
245
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
247
251
End If
248
- List_Datas.Add(readLine)
249
- Loop Until (IsNothing(readLine) Or (ReaderStream.Peek < 0 ))
252
+ End While
250
253
251
254
streamInUse = False
252
255
' LogFile.LogTracing("Done processing LIST response for query " & Query_Msg, LogLvl.LOG_DEBUG, Me)
@@ -262,21 +265,17 @@ Public Class Nut_Socket
262
265
'Query
263
266
'LIST VAR <upsname>
264
267
'Response List of var
265
- 'VAR <upsname> <varname> "<value>"
268
+ 'VAR <upsname><varname> "<value>"
266
269
Key = Replace(SplitString( 2 ), """" , "" )
267
270
Value = Replace(SplitString( 3 ), """" , "" )
268
271
Dim UPSName = SplitString( 1 )
269
272
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 {
272
274
.VarKey = Key ,
273
275
.VarValue = Trim(Value),
274
- .VarDesc = Split(Replace(VarDESC, """" , "" ), " " , 4 )( 3 )}
276
+ .VarDesc = If ( Not IsNothing(VarDESC), Split(Replace(VarDESC, """" , "" ), " " , 4 )( 3 ), String .Empty )}
275
277
)
276
- Else
277
- 'TODO: Convert to nut_exception error
278
- Throw New Exception( "error" )
279
- End If
278
+
280
279
Case "UPS"
281
280
'Query
282
281
'LIST UPS
@@ -291,7 +290,7 @@ Public Class Nut_Socket
291
290
'Query
292
291
'LIST RW <upsname>
293
292
'List of RW var
294
- 'RW <upsname> <varname> "<value>"
293
+ 'RW <upsname><varname> "<value>"
295
294
Key = Replace(SplitString( 2 ), """" , "" )
296
295
Value = Replace(SplitString( 3 ), """" , "" )
297
296
Dim UPSName = SplitString( 1 )
@@ -300,7 +299,7 @@ Public Class Nut_Socket
300
299
List_Result.Add( New UPS_List_Datas With {
301
300
.VarKey = Key ,
302
301
.VarValue = Trim(Value),
303
- .VarDesc = Split(Replace(VarDESC, """" , "" ), " " , 4 )( 3 )}
302
+ .VarDesc = If ( Not IsNothing(VarDESC), Split(Replace(VarDESC, """" , "" ), " " , 4 )( 3 ), String .Empty )}
304
303
)
305
304
Else
306
305
'TODO: Convert to nut_exception error
@@ -310,12 +309,12 @@ Public Class Nut_Socket
310
309
'Query
311
310
'LIST CMD <upsname>
312
311
'List of CMD
313
- 'CMD <upsname> <cmdname>
312
+ 'CMD <upsname><cmdname>
314
313
Case "ENUM"
315
314
'Query
316
315
'LIST ENUM <upsname>
317
316
'List of Enum ??
318
- 'ENUM <upsname> <varname> "<value>"
317
+ 'ENUM <upsname><varname> "<value>"
319
318
Key = Replace(SplitString( 2 ), """" , "" )
320
319
Value = Replace(SplitString( 3 ), """" , "" )
321
320
Dim UPSName = SplitString( 1 )
@@ -332,14 +331,14 @@ Public Class Nut_Socket
332
331
End If
333
332
Case "RANGE"
334
333
'Query
335
- 'LIST RANGE <upsname> <varname>
334
+ 'LIST RANGE <upsname><varname>
336
335
'List of Range
337
- 'RANGE <upsname> <varname> "<min>" "<max>"
336
+ 'RANGE <upsname><varname> "<min>" "<max>"
338
337
Case "CLIENT"
339
338
'Query
340
339
'LIST CLIENT <upsname>
341
340
'List of Range
342
- 'CLIENT <device name> <client IP address>
341
+ 'CLIENT <device name><client IP address>
343
342
End Select
344
343
Next
345
344
0 commit comments