Fix
This commit is contained in:
@@ -92,15 +92,16 @@ namespace Modbus.Net
|
|||||||
/// <param name="def">需要添加的信息信息</param>
|
/// <param name="def">需要添加的信息信息</param>
|
||||||
protected virtual bool AddMessageToList(MessageWaitingDef def)
|
protected virtual bool AddMessageToList(MessageWaitingDef def)
|
||||||
{
|
{
|
||||||
|
var ans = false;
|
||||||
lock (WaitingMessages)
|
lock (WaitingMessages)
|
||||||
{
|
{
|
||||||
if (WaitingMessages.FirstOrDefault(p => p.Key == def.Key) == null || def.Key == null)
|
if (WaitingMessages.FirstOrDefault(p => p.Key == def.Key) == null || def.Key == null)
|
||||||
{
|
{
|
||||||
WaitingMessages.Add(def);
|
WaitingMessages.Add(def);
|
||||||
return true;
|
ans = true;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return ans;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -116,10 +117,18 @@ namespace Modbus.Net
|
|||||||
var ans = new List<(byte[], bool)>();
|
var ans = new List<(byte[], bool)>();
|
||||||
byte[] receiveMessageCopy = new byte[receiveMessage.Length];
|
byte[] receiveMessageCopy = new byte[receiveMessage.Length];
|
||||||
Array.Copy(receiveMessage, receiveMessageCopy, receiveMessage.Length);
|
Array.Copy(receiveMessage, receiveMessageCopy, receiveMessage.Length);
|
||||||
var length = LengthCalc?.Invoke(receiveMessageCopy);
|
int? length = -1;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
length = LengthCalc?.Invoke(receiveMessageCopy);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
List<byte[]> duplicatedMessages;
|
List<byte[]> duplicatedMessages;
|
||||||
if (length == null || length == -1) return ans;
|
if (length == null || length == -1) return ans;
|
||||||
if (length == 0) return null;
|
else if (length == 0) return null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
duplicatedMessages = new List<byte[]>();
|
duplicatedMessages = new List<byte[]>();
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ namespace Modbus.Net
|
|||||||
var ans = 0;
|
var ans = 0;
|
||||||
foreach (var position in packageCountPositions)
|
foreach (var position in packageCountPositions)
|
||||||
{
|
{
|
||||||
if (position >= receiveMessage.Length) return -1;
|
if (position > receiveMessage.Length - 1) return -1;
|
||||||
ans = ans * 256 + receiveMessage[position];
|
ans = ans * 256 + receiveMessage[position];
|
||||||
}
|
}
|
||||||
|
if (ans + otherCount > receiveMessage.Length) return -1;
|
||||||
return ans + otherCount;
|
return ans + otherCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,9 +76,9 @@ namespace Modbus.Net
|
|||||||
_taskCycleSema?.Close();
|
_taskCycleSema?.Close();
|
||||||
sendSuccess = true;
|
sendSuccess = true;
|
||||||
}
|
}
|
||||||
else if (WaitingMessages.Count > WaitingMessages.IndexOf(_currentSendingPos) + 1)
|
else if (WaitingMessages.IndexOf(_currentSendingPos) == -1)
|
||||||
{
|
{
|
||||||
_currentSendingPos = WaitingMessages[WaitingMessages.IndexOf(_currentSendingPos) + 1];
|
_currentSendingPos = WaitingMessages.First();
|
||||||
_currentSendingPos.SendMutex.Set();
|
_currentSendingPos.SendMutex.Set();
|
||||||
sendSuccess = true;
|
sendSuccess = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace Modbus.Net
|
|||||||
int tmpCount = 0, tmpCount2 = 0;
|
int tmpCount = 0, tmpCount2 = 0;
|
||||||
foreach (var matchPos in matchPoses)
|
foreach (var matchPos in matchPoses)
|
||||||
{
|
{
|
||||||
if (matchPos.Item1 >= message.Length || matchPos.Item2 >= message.Length) return null;
|
if (matchPos.Item1 > message.Length - 1 || matchPos.Item2 > message.Length - 1) return null;
|
||||||
tmpCount = tmpCount * 256 + message[matchPos.Item1];
|
tmpCount = tmpCount * 256 + message[matchPos.Item1];
|
||||||
tmpCount2 = tmpCount2 * 256 + message[matchPos.Item2];
|
tmpCount2 = tmpCount2 * 256 + message[matchPos.Item2];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ namespace MachineJob.Service
|
|||||||
_logger.LogInformation(dataReturnDef.MachineId + " " + value.Key + " " + value.Value.DeviceValue);
|
_logger.LogInformation(dataReturnDef.MachineId + " " + value.Key + " " + value.Value.DeviceValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var context = new DatabaseWriteContext())
|
using (var context = new DatabaseWriteContext())
|
||||||
@@ -119,7 +120,7 @@ namespace MachineJob.Service
|
|||||||
{
|
{
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user