mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Fixed not updating timespan auto propertys and thread blocking Wait() call for await
This commit is contained in:
@@ -76,9 +76,11 @@ namespace MewtocolNet {
|
|||||||
while (ContinousReaderRunning) {
|
while (ContinousReaderRunning) {
|
||||||
|
|
||||||
//do priority tasks first
|
//do priority tasks first
|
||||||
if (PriorityTasks.Count > 0) {
|
if (PriorityTasks != null && PriorityTasks.Count > 0) {
|
||||||
|
|
||||||
await PriorityTasks.FirstOrDefault(x => !x.IsCompleted);
|
try {
|
||||||
|
await PriorityTasks?.FirstOrDefault(x => !x.IsCompleted);
|
||||||
|
} catch (NullReferenceException) { }
|
||||||
|
|
||||||
} else if (getPLCinfoCycleCount > 25) {
|
} else if (getPLCinfoCycleCount > 25) {
|
||||||
|
|
||||||
|
|||||||
@@ -386,6 +386,10 @@ namespace MewtocolNet {
|
|||||||
foundToUpdate.SetValue(collection, ((NRegister<int>)reg).Value);
|
foundToUpdate.SetValue(collection, ((NRegister<int>)reg).Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (foundToUpdate.PropertyType == typeof(TimeSpan)) {
|
||||||
|
foundToUpdate.SetValue(collection, ((NRegister<TimeSpan>)reg).Value);
|
||||||
|
}
|
||||||
|
|
||||||
//setting back strings
|
//setting back strings
|
||||||
|
|
||||||
if (foundToUpdate.PropertyType == typeof(string)) {
|
if (foundToUpdate.PropertyType == typeof(string)) {
|
||||||
@@ -545,7 +549,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
var awaittask = SendSingleBlock(_msg);
|
var awaittask = SendSingleBlock(_msg);
|
||||||
PriorityTasks.Add(awaittask);
|
PriorityTasks.Add(awaittask);
|
||||||
awaittask.Wait();
|
await awaittask;
|
||||||
|
|
||||||
PriorityTasks.Remove(awaittask);
|
PriorityTasks.Remove(awaittask);
|
||||||
response = awaittask.Result;
|
response = awaittask.Result;
|
||||||
@@ -616,13 +620,13 @@ namespace MewtocolNet {
|
|||||||
string characters = enc.GetString(message);
|
string characters = enc.GetString(message);
|
||||||
}
|
}
|
||||||
} catch (IOException) {
|
} catch (IOException) {
|
||||||
|
Logger.Log($"Critical IO exception on send", LogLevel.Critical, this);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//await result
|
//await result
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
byte[] responseBuffer = new byte[256];
|
byte[] responseBuffer = new byte[256];
|
||||||
do {
|
do {
|
||||||
int bytes = stream.Read(responseBuffer, 0, responseBuffer.Length);
|
int bytes = stream.Read(responseBuffer, 0, responseBuffer.Length);
|
||||||
@@ -630,6 +634,7 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
while (stream.DataAvailable);
|
while (stream.DataAvailable);
|
||||||
} catch (IOException) {
|
} catch (IOException) {
|
||||||
|
Logger.Log($"Critical IO exception on receive", LogLevel.Critical, this);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,19 +643,21 @@ namespace MewtocolNet {
|
|||||||
if (Math.Abs(CycleTimeMs - curCycle) > 2) {
|
if (Math.Abs(CycleTimeMs - curCycle) > 2) {
|
||||||
CycleTimeMs = curCycle;
|
CycleTimeMs = curCycle;
|
||||||
}
|
}
|
||||||
Logger.Log($"IN MSG ({(int)sw.Elapsed.TotalMilliseconds}ms): {_blockString}", LogLevel.Critical, this);
|
|
||||||
SendExceptionsInRow = 0;
|
Logger.Log($"IN MSG ({(int)sw.Elapsed.TotalMilliseconds}ms): {response}", LogLevel.Critical, this);
|
||||||
return response.ToString();
|
return response.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SocketException) {
|
} catch (SocketException) {
|
||||||
|
|
||||||
if (IsConnected) {
|
if (IsConnected) {
|
||||||
|
|
||||||
|
Logger.Log("The PLC connection was closed", LogLevel.Error, this);
|
||||||
CycleTimeMs = 0;
|
CycleTimeMs = 0;
|
||||||
IsConnected = false;
|
IsConnected = false;
|
||||||
Disconnected?.Invoke();
|
Disconnected?.Invoke();
|
||||||
KillPoller();
|
KillPoller();
|
||||||
Logger.Log("The PLC connection was closed", LogLevel.Error, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user