|
|
|
@ -73,12 +73,19 @@ namespace SlnMesnac.RfidUpload.TouchSocket
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
|
|
|
|
|
if (mes.Length == 22 && mes.StartsWith("RFID") && mes.EndsWith("0D"))
|
|
|
|
|
if(mes.Length %22 ==0)
|
|
|
|
|
{
|
|
|
|
|
// 去掉帧头 "RFID" 和帧尾 "0D"
|
|
|
|
|
string trimmedMes = mes.Substring(4, mes.Length - 6); // 去掉前4个字符和后2个字符
|
|
|
|
|
ReceiveCodeDelegateEvent?.Invoke(trimmedMes);
|
|
|
|
|
}
|
|
|
|
|
// 拆分混合数据
|
|
|
|
|
SplitMixedData(mes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (mes.Length == 22 && mes.StartsWith("RFID") && mes.EndsWith("0D"))
|
|
|
|
|
//{
|
|
|
|
|
// // 去掉帧头 "RFID" 和帧尾 "0D"
|
|
|
|
|
// string trimmedMes = mes.Substring(4, mes.Length - 6); // 去掉前4个字符和后2个字符
|
|
|
|
|
// ReceiveCodeDelegateEvent?.Invoke(trimmedMes);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
@ -112,7 +119,42 @@ namespace SlnMesnac.RfidUpload.TouchSocket
|
|
|
|
|
return Task.FromResult(messageModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void SplitMixedData(string mixedData)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
while (index < mixedData.Length)
|
|
|
|
|
{
|
|
|
|
|
// 查找 "RFID" 的起始位置
|
|
|
|
|
int startIndex = mixedData.IndexOf("RFID", index);
|
|
|
|
|
if (startIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查从起始位置开始长度为 22 的子字符串是否以 "0D" 结尾
|
|
|
|
|
if (startIndex + 22 <= mixedData.Length && mixedData.Substring(startIndex, 22).EndsWith("0D"))
|
|
|
|
|
{
|
|
|
|
|
string singleData = mixedData.Substring(startIndex, 22);
|
|
|
|
|
// 去掉帧头 "RFID" 和帧尾 "0D"
|
|
|
|
|
string trimmedMes = singleData.Substring(4, singleData.Length - 6);
|
|
|
|
|
// 触发事件
|
|
|
|
|
ReceiveCodeDelegateEvent?.Invoke(trimmedMes);
|
|
|
|
|
|
|
|
|
|
// 输出拆分后的数据
|
|
|
|
|
Console.WriteLine(trimmedMes);
|
|
|
|
|
|
|
|
|
|
index = startIndex + 22;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
index = startIndex + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|