|
|
|
@ -86,6 +86,8 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
|
|
|
|
|
private string TestClientID = "";
|
|
|
|
|
|
|
|
|
|
public int Vport;
|
|
|
|
|
|
|
|
|
|
public TcpServer(ILogger<TcpServer> logger, TcpService tcpService, AppConfig appConfig)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
@ -108,40 +110,44 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
{
|
|
|
|
|
_service.Connecting = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}正在接入服务");
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}:{client.Port}正在接入服务");
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
_service.Connected = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}接入服务成功");
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}:{client.Port}接入服务成功");
|
|
|
|
|
RefreshClientInfoEvent?.Invoke(_service);
|
|
|
|
|
RefreshStateAction?.Invoke(client.IP, true);
|
|
|
|
|
client.ResetId(client.Port.ToString());
|
|
|
|
|
TestClientID = client.Port.ToString();
|
|
|
|
|
Vport = client.Port;
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
_service.Disconnected = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}断开连接");
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}:{client.Port}断开连接");
|
|
|
|
|
RefreshStateAction?.Invoke(client.IP, false);
|
|
|
|
|
RefreshClientInfoEvent?.Invoke(_service);
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
|
};
|
|
|
|
|
_service.Received = (client, e) =>
|
|
|
|
|
{
|
|
|
|
|
var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}:" + mes);
|
|
|
|
|
//区分一下指令类型,委托传参
|
|
|
|
|
|
|
|
|
|
if (mes == "heartbeat")
|
|
|
|
|
{
|
|
|
|
|
RefreshStateAction?.Invoke(client.IP, true);
|
|
|
|
|
}
|
|
|
|
|
//var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
|
|
|
|
|
|
|
|
|
|
//_logger.LogInformation($"客户端{client.IP}:{client.Port} :" + mes);
|
|
|
|
|
|
|
|
|
|
//区分一下指令类型,委托传参
|
|
|
|
|
|
|
|
|
|
//if (mes == "heartbeat")
|
|
|
|
|
//{
|
|
|
|
|
// RefreshStateAction?.Invoke(client.IP, true);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
byte[] receivedBuffer = new byte[e.ByteBlock.Len];
|
|
|
|
|
Array.Copy(e.ByteBlock.Buffer, 0, receivedBuffer, 0, e.ByteBlock.Len);
|
|
|
|
|
|
|
|
|
|
var mes = ByteArrayToHexString(receivedBuffer);
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}:{client.Port} :" + mes);
|
|
|
|
|
DataClassify(BufferDataAnalysis.BufferRootAnalysis(receivedBuffer), client.Id);
|
|
|
|
|
|
|
|
|
|
return EasyTask.CompletedTask;
|
|
|
|
@ -168,6 +174,21 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// byte数组转字符串
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="byteArray"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private string ByteArrayToHexString(byte[] byteArray)
|
|
|
|
|
{
|
|
|
|
|
if (byteArray == null || byteArray.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Join(" ", byteArray.Select(b => b.ToString("X2")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//private void Test()
|
|
|
|
|
//{
|
|
|
|
|
// try
|
|
|
|
@ -362,15 +383,20 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void VisionStateRequest(TcpVisionEntity entity, string id)
|
|
|
|
|
{
|
|
|
|
|
SendRequestVisionSysState(id);
|
|
|
|
|
if(entity.DataLength == 2)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//Thread.Sleep(1000);
|
|
|
|
|
//SendRequestVisionSysState(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// AMR就绪,请求视觉开始工作
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RequestVisionStartWork(StackState state, int port)
|
|
|
|
|
public void RequestVisionStartWork(StackState state, string id)
|
|
|
|
|
{
|
|
|
|
|
SendAMRRequestVisionStartWork(new byte[1] { (byte)state }, port.ToString());
|
|
|
|
|
SendAMRRequestVisionStartWork(new byte[1] { (byte)state }, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -404,67 +430,71 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
_logger.LogInformation($"视觉系统收到开始工作状态:{result}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VCount = 1;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 接受码垛结果
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void StackResultSend(TcpVisionEntity entity, string id)
|
|
|
|
|
{
|
|
|
|
|
string result;
|
|
|
|
|
if (entity.DataLength == 1)
|
|
|
|
|
{
|
|
|
|
|
if (entity.DataBytes[0] == 0x00)
|
|
|
|
|
{
|
|
|
|
|
result = "码垛完成";
|
|
|
|
|
_logger.LogInformation($"视觉系统一次码垛结束,码垛完成");
|
|
|
|
|
//上位机回复收到码垛结果
|
|
|
|
|
SendReplayStackResult(id);
|
|
|
|
|
if (true) //这里写是否继续下一次码垛的判断条件
|
|
|
|
|
if (VCount < 5) //这里写是否继续下一次码垛的判断条件
|
|
|
|
|
{
|
|
|
|
|
//如果码垛没结束继续发下一次的码垛信号
|
|
|
|
|
if (true) //这里写向哪个机器人码垛的判断条件
|
|
|
|
|
{
|
|
|
|
|
//发送向搬运机器人(AGVDeliver)码垛的信号
|
|
|
|
|
SendAMRRequestVisionStartWork(new byte[] { 0x10 }, id);
|
|
|
|
|
RequestVisionStartWork(StackState.AGVNoPositioning, id);
|
|
|
|
|
_logger.LogInformation("下一次码垛开始,方向:搬运机器人");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//发送向复合机器人(AMR)码垛的信号
|
|
|
|
|
SendAMRRequestVisionStartWork(new byte[] { 0x01 }, id);
|
|
|
|
|
RequestVisionStartWork(StackState.AMRNoPositioning, id);
|
|
|
|
|
_logger.LogInformation("下一次码垛开始,方向:复合机器人");
|
|
|
|
|
}
|
|
|
|
|
VCount++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//如果码垛结束就请求复位
|
|
|
|
|
SendStackOverRequestVisionSysReplace(id);
|
|
|
|
|
RequestVisionReplace(id);
|
|
|
|
|
_logger.LogInformation("本次码垛结束,请求复位");
|
|
|
|
|
VCount = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (entity.DataBytes[0] == 0x01)
|
|
|
|
|
{
|
|
|
|
|
result = "码垛过程失败";
|
|
|
|
|
_logger.LogInformation($"视觉系统一次码垛结束,码垛过程失败");
|
|
|
|
|
}
|
|
|
|
|
else if (entity.DataBytes[0] == 0x02)
|
|
|
|
|
{
|
|
|
|
|
result = "码垛检查失败";
|
|
|
|
|
_logger.LogInformation($"视觉系统一次码垛结束,码垛检查失败");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = "未知返回代码";
|
|
|
|
|
_logger.LogInformation($"视觉系统一次码垛结束,未知返回代码");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result = "返回数据格式错误";
|
|
|
|
|
_logger.LogInformation($"视觉系统一次码垛结束,返回数据格式错误");
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation($"视觉系统一次码垛结束:{result}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 码垛结束,请求视觉系统复位
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RequestVisionReplace(int port)
|
|
|
|
|
public void RequestVisionReplace(string port)
|
|
|
|
|
{
|
|
|
|
|
SendStackOverRequestVisionSysReplace(port.ToString());
|
|
|
|
|
SendStackOverRequestVisionSysReplace(port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -509,12 +539,12 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 搬运机器人码垛无需定位
|
|
|
|
|
/// </summary>
|
|
|
|
|
RGVNoPositioning = 0x10,
|
|
|
|
|
AGVNoPositioning = 0x10,
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 搬运机器人码垛需要定位
|
|
|
|
|
/// </summary>
|
|
|
|
|
RGVNeedPositioning = 0x11,
|
|
|
|
|
AGVNeedPositioning = 0x11,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|