|
|
|
@ -6,6 +6,10 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using HslCommunication;
|
|
|
|
|
using HybirdFrameworkCore.Utils;
|
|
|
|
|
using Service.Charger.Server;
|
|
|
|
|
using Service.Execute.Model;
|
|
|
|
|
|
|
|
|
|
namespace Service.PlcAfrica.Client
|
|
|
|
|
{
|
|
|
|
@ -20,8 +24,6 @@ namespace Service.PlcAfrica.Client
|
|
|
|
|
static int DataTimeSeconds = 20;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数据刷新时间
|
|
|
|
|
/// </summary>
|
|
|
|
@ -36,5 +38,199 @@ namespace Service.PlcAfrica.Client
|
|
|
|
|
|
|
|
|
|
Task.Run(() => PlcAfricaClient.Connect());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void Reset()
|
|
|
|
|
{
|
|
|
|
|
if (PlcAfricaClient == null)
|
|
|
|
|
{
|
|
|
|
|
PlcAfricaClient.Reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 0 无动作
|
|
|
|
|
/// 1 急停指令
|
|
|
|
|
/// 2 自动换电启动指令
|
|
|
|
|
/// 3 自动调仓启动指令
|
|
|
|
|
/// 4 暂停指令
|
|
|
|
|
/// 5 继续指令
|
|
|
|
|
/// 6 停止指令
|
|
|
|
|
/// 7 结束指令
|
|
|
|
|
/// 11 测量轴启动
|
|
|
|
|
/// 12 回原点
|
|
|
|
|
/// 101 此行及以下未实装,维持《上位机PLC通讯内容V1.5》内容
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
|
|
|
|
|
public static bool StartSwap()
|
|
|
|
|
{
|
|
|
|
|
if (PlcAfricaClient == null)
|
|
|
|
|
{
|
|
|
|
|
PlcAfricaMsg.OperationInstruction.Value = 2;
|
|
|
|
|
PlcAfricaClient!.WriteValue(PlcAfricaMsg.OperationInstruction);
|
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
|
|
return PlcAfricaMsg.StationCommandFeedback.Value == 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作指令
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool OperationInstruction(ushort cmd)
|
|
|
|
|
{
|
|
|
|
|
if (PlcAfricaClient == null)
|
|
|
|
|
{
|
|
|
|
|
PlcAfricaMsg.OperationInstruction.Value = cmd;
|
|
|
|
|
PlcAfricaClient!.WriteValue(PlcAfricaMsg.OperationInstruction);
|
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
|
|
return PlcAfricaMsg.StationCommandFeedback.Value == cmd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 读8000 自动任务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static ushort AutoActionStatus()
|
|
|
|
|
{
|
|
|
|
|
return PlcAfricaMsg.ActionCode.Value ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 机器人状态 7001
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool RobotStatus(ushort cmd)
|
|
|
|
|
{
|
|
|
|
|
return PlcAfricaMsg.PowerChangeModeRobot.Value == cmd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 机器人状态 就绪
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool RobotReady()
|
|
|
|
|
{
|
|
|
|
|
return PlcAfricaMsg.PowerChangeModeRobot.Value == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 机器人状态 工作完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool RobotWorkFinish()
|
|
|
|
|
{
|
|
|
|
|
return PlcAfricaMsg.PowerChangeModeRobot.Value == 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下发车辆信息 0无车辆,1车辆解锁,2车辆上锁
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool CarStatus(ushort cmd)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (PlcAfricaClient == null)
|
|
|
|
|
{
|
|
|
|
|
PlcAfricaMsg.TboxUnlock.Value = cmd;
|
|
|
|
|
return PlcAfricaClient!.WriteValue(PlcAfricaMsg.TboxUnlock);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
///下发取放仓位
|
|
|
|
|
///
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下发换电
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool DistributeTask(ushort inBinNo, ushort outBinNo)
|
|
|
|
|
{
|
|
|
|
|
//下发任务前,增加待机状态判断
|
|
|
|
|
if (!RobotReady())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DistributeTask distributeTask = new()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
InBinNo = inBinNo,
|
|
|
|
|
OutBinNo = outBinNo,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
byte[] encode = ModelConvert.Encode(distributeTask);
|
|
|
|
|
//TODO::現在手動處理encode
|
|
|
|
|
for (int i = 0; i < encode.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i % 2 == 0)
|
|
|
|
|
{
|
|
|
|
|
var temp = encode[i + 1];
|
|
|
|
|
encode[i + 1] = encode[i];
|
|
|
|
|
encode[i] = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//需要将数据转换成byte数组
|
|
|
|
|
OperateResult operateResult = PlcAfricaClient.Write("x=16;111", encode);
|
|
|
|
|
|
|
|
|
|
return operateResult.IsSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static bool IsAutoAndRemote()
|
|
|
|
|
{
|
|
|
|
|
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
|
|
|
|
|
{
|
|
|
|
|
return PlcAfricaMsg.PowerChangeMode.Value == 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 红绿灯 0-不亮,1-亮红灯,2-绿灯,3-绿灯闪
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool LightControl(ushort cmd)
|
|
|
|
|
{
|
|
|
|
|
if (PlcAfricaClient == null)
|
|
|
|
|
{
|
|
|
|
|
PlcAfricaMsg.TrafficLightFunction.Value = cmd;
|
|
|
|
|
return PlcAfricaClient!.WriteValue(PlcAfricaMsg.TrafficLightFunction);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|