|
|
|
@ -32,10 +32,15 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
public delegate void RefreshMaterialCodeStr(string materialCodeStr, string ip);
|
|
|
|
|
public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent;
|
|
|
|
|
|
|
|
|
|
//相机拍照识别结果事件
|
|
|
|
|
//相机拍照识别结果
|
|
|
|
|
public delegate void CameraResult(string result);
|
|
|
|
|
public static event CameraResult CameraResultEvent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//光电信号推送
|
|
|
|
|
public delegate void SerialSignalPush(string ip, int flag);
|
|
|
|
|
public static event SerialSignalPush SerialSignalPushEvent;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public TcpServer(ILogger<TcpServer> logger,TcpService tcpService)
|
|
|
|
@ -66,6 +71,27 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
_service.Received = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// 串口模块光电信号
|
|
|
|
|
if (client.IP == config.SerialIP)
|
|
|
|
|
{
|
|
|
|
|
int result = ChangeSerialSignal(e.ByteBlock.Buffer,e.ByteBlock.Len);
|
|
|
|
|
if(result == -1)
|
|
|
|
|
{
|
|
|
|
|
client.Logger.Info($"{client.IP}:{client.Port}》接收到光电信息异常");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string message = result == 1 ? "触发" : "释放";
|
|
|
|
|
client.Logger.Info($"{client.IP}:{client.Port}》接收到光电信息:{message}");
|
|
|
|
|
SerialSignalPushEvent?.Invoke(client.IP, result);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else //扫码器及相机
|
|
|
|
|
{
|
|
|
|
|
//从客户端收到信息
|
|
|
|
|
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
|
|
|
|
@ -80,7 +106,7 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
else if (mes == "NoRead")
|
|
|
|
|
{
|
|
|
|
|
client.Logger.Info($"客户端{client.IP}:{client.Port}》NoRead事件{mes}");
|
|
|
|
|
// TODO
|
|
|
|
|
// TODO扫码器扫码失败报警
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -104,6 +130,9 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"socket接收数据异常:{ex.Message}");
|
|
|
|
@ -158,5 +187,39 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 转换光电信号
|
|
|
|
|
/// 释放 01 03 02 01 00 B9 D4
|
|
|
|
|
/// 触发 01 03 02 01 FF F9 94
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int ChangeSerialSignal(byte[] data,int len)
|
|
|
|
|
{
|
|
|
|
|
if (data == null || len < 0)
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
len = Math.Min(len, data.Length);
|
|
|
|
|
byte[] CheckByte = new byte[len];
|
|
|
|
|
Array.Copy(data, 0, CheckByte, 0, len);
|
|
|
|
|
|
|
|
|
|
byte[] release = new byte[] { (byte)0x01, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0x00, (byte)0xB9, (byte)0xD4 };
|
|
|
|
|
byte[] trigger = new byte[] { (byte)0x01, (byte)0x03, (byte)0x02, (byte)0x01, (byte)0xFF, (byte)0xF9, (byte)0x94 };
|
|
|
|
|
|
|
|
|
|
if (CheckByte.Length == release.Length && CheckByte.SequenceEqual(release))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else if (CheckByte.Length == trigger.Length && CheckByte.SequenceEqual(trigger))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 异常
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|