换电流程

master
lxw 3 days ago
parent 64807c8800
commit 18c671dbda

@ -3,6 +3,7 @@ using log4net;
using Service.Charger.Client; using Service.Charger.Client;
using Service.Mgr; using Service.Mgr;
using Service.Padar.Client; using Service.Padar.Client;
using Service.PlcAfrica.Client;
namespace Service.Execute.Api; namespace Service.Execute.Api;
@ -17,6 +18,26 @@ public class PlcApi
/// </summary> /// </summary>
static int DataTimeSeconds = 2; static int DataTimeSeconds = 2;
/// <summary>
/// </summary>
/// <returns></returns>
public static ushort ReadAction()
{
return PlcAfricaMgr.AutoActionStatus();
}
public static bool RobotWorkFinish()
{
return PlcAfricaMgr.RobotWorkFinish();
}
public static bool RobotReady()
{
return PlcAfricaMgr.RobotReady();
}
/// <summary> /// <summary>
/// 是否远程模式 /// 是否远程模式
@ -24,17 +45,17 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool IsRemote() public static bool IsRemote()
{ {
return ClientMgr.PlcClient!.Remote; return PlcAfricaMgr.IsAutoAndRemote();
} }
/// <summary> /*/// <summary>
/// 是否初始化完成 /// 是否初始化完成
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static bool IsInit() public static bool IsInit()
{ {
return ClientMgr.PlcClient!.Init; return ClientMgr.PlcClient!.Init;
} }*/
/// <summary> /// <summary>
/// 是否自动 /// 是否自动
@ -42,11 +63,7 @@ public class PlcApi
/// <returns></returns> /// <returns></returns>
public static bool IsAuto() public static bool IsAuto()
{ {
if (ClientMgr.PlcClient!=null) return PlcAfricaMgr.IsAutoAndRemote();
{
return ClientMgr.PlcClient.Auto;
}
return false;
} }
/// <summary> /// <summary>
@ -61,11 +78,12 @@ public class PlcApi
$"出仓位:{outBinNo},入仓位:{inBinNo}" ,(int)SwapConstant.CommunicationType.Send); $"出仓位:{outBinNo},入仓位:{inBinNo}" ,(int)SwapConstant.CommunicationType.Send);
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}"); Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
ClientMgr.PlcClient?.SendStartBatterySwapReq(Convert.ToByte(outBinNo), Convert.ToByte(inBinNo)); if (PlcAfricaMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo)))
{
Log.Info($"PlcApi StartSwapping done"); Log.Info($"PlcApi StartSwapping done");
return ClientMgr.PlcClient.SwapStart; return PlcAfricaMgr.StartSwap();
}
return false;
} }
/// <summary> /// <summary>
@ -89,7 +107,7 @@ public class PlcApi
/// <summary> /*/// <summary>
/// 发送初始化命令 /// 发送初始化命令
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
@ -99,18 +117,24 @@ public class PlcApi
ClientMgr.PlcClient?.SendInitializeCommandReq(); ClientMgr.PlcClient?.SendInitializeCommandReq();
Log.Info($"PlcApi Init done"); Log.Info($"PlcApi Init done");
return true; return true;
} }*/
/// <summary> /// <summary>
/// 发送红绿灯 /// 发送红绿灯
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static bool Traffic(byte Light) public static bool Traffic(ushort light)
{ {
Log.Info($"PlcApi Init "); return PlcAfricaMgr.LightControl(light);
ClientMgr.PlcClient?.SendTrafficLightReq(Light); }
Log.Info($"PlcApi Init done");
return true; /// <summary>
/// 发送红绿灯
/// </summary>
/// <returns></returns>
public static bool CarStatus(ushort cmd)
{
return PlcAfricaMgr.CarStatus(cmd);
} }
} }

@ -5,7 +5,7 @@ namespace Service.Execute.Model;
public class DistributeTask public class DistributeTask
{ {
/// <summary> /*/// <summary>
/// 任务类型 /// 任务类型
/// 0.无任务 /// 0.无任务
/// 1.换电任务 /// 1.换电任务
@ -15,23 +15,23 @@ public class DistributeTask
/// 5.消防任务 /// 5.消防任务
/// </summary> /// </summary>
[Property(0, 16)] [Property(0, 16)]
public ushort TaskNo { get; set; } public ushort TaskNo { get; set; }*/
/// <summary> /// <summary>
/// 入仓位选择 /// 入仓位选择
/// </summary> /// </summary>
[Property(16, 16)] [Property(0, 16)]
public ushort InBinNo { get; set; } public ushort InBinNo { get; set; }
/// <summary> /// <summary>
/// 出仓仓位选择 /// 出仓仓位选择
/// </summary> /// </summary>
[Property(32, 16)] [Property(16, 16)]
public ushort OutBinNo { get; set; } public ushort OutBinNo { get; set; }
/// <summary> /*/// <summary>
/// 电池包类型 0 /// 电池包类型 0
/// </summary> /// </summary>
[Property(48, 16)] [Property(48, 16)]
public ushort BatteryPackType { get; set; } public ushort BatteryPackType { get; set; }*/
} }

@ -49,7 +49,6 @@ public class CarPrepareState : IState
} }
////调整车辆 ////调整车辆
var adjustCarByRadar = AdjustCarByRadar(machine); var adjustCarByRadar = AdjustCarByRadar(machine);
if (InvokeStatus.Done != adjustCarByRadar) if (InvokeStatus.Done != adjustCarByRadar)

@ -133,6 +133,7 @@ public class DoSwappingState : IState
{ {
if (ClientMgr.PlcClient.IsTaskFree()) if (ClientMgr.PlcClient.IsTaskFree())
{ {
PlcApi.CarStatus(1);
// ClientMgr.PlcClient.ExChangeTaskNo(1); // ClientMgr.PlcClient.ExChangeTaskNo(1);
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No); machine.SwapOrderBatteryInfo.UpBinInfo.No);
@ -143,11 +144,6 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag, _CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine); machine);
if (a == 0)
{
LedClient.SendMsgByKey(InfoEnum.SwapInfo.StartSwap.GetLed());
a = 1;
}
Thread.Sleep(1000); Thread.Sleep(1000);
@ -193,15 +189,11 @@ public class DoSwappingState : IState
return Invoker.Invoke("plc UnPack", 500, 5, machine.IsCanceled, return Invoker.Invoke("plc UnPack", 500, 5, machine.IsCanceled,
() => machine.UnOldBatteryFlag, () => () => machine.UnOldBatteryFlag, () =>
{ {
if (b==0)
{
LedClient.SendMsgByKey(InfoEnum.SwapInfo.StartSwap.GetLed());
b = 1;
}
SoundClient = AppInfo.Container.Resolve<SoundClient>(); SoundClient = AppInfo.Container.Resolve<SoundClient>();
machine.UnOldBatteryFlag = ClientMgr.PlcClient.DisassembleDone; machine.UnOldBatteryFlag = PlcApi.ReadAction() > 15;
if (machine.UnOldBatteryFlag) if (machine.UnOldBatteryFlag)
{ {
@ -234,7 +226,7 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed()); // machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPack.GetLed()); // LedClient.SendMsgByKey(InfoEnum.SwapInfo.InfoPack.GetLed());
machine.InstallNewBatteryFlag = ClientMgr.PlcClient.SwapDone; machine.InstallNewBatteryFlag =PlcApi.ReadAction() >29 ;
if (machine.InstallNewBatteryFlag) if (machine.InstallNewBatteryFlag)
{ {
@ -264,7 +256,7 @@ public class DoSwappingState : IState
return Invoker.Invoke("plc Pack Finish", 500, 5, machine.IsCanceled, return Invoker.Invoke("plc Pack Finish", 500, 5, machine.IsCanceled,
() => machine.FinishNewBatteryFlag, () => () => machine.FinishNewBatteryFlag, () =>
{ {
if (ClientMgr.PlcClient.SwapDone) if (PlcApi.ReadAction()==44 || PlcApi.RobotWorkFinish() || PlcApi.RobotReady())
{ {
machine.FinishNewBatteryFlag = true; machine.FinishNewBatteryFlag = true;
machine.BusinessSwappingForCloudState = machine.BusinessSwappingForCloudState =

@ -152,27 +152,9 @@ public class StationReadyState : IState
{ {
if (PlcApi.IsRemote()) if (PlcApi.IsRemote())
{ {
if (!PlcApi.IsInit())
{
//下发初始化
PlcApi.Init();
}
else
{
//LED显示-欢迎光临_换电站点_正在营业
//string welcomeContent = "欢迎光临换电站!(正在营业)";
//SoundClient.SoundPlay(AppSettingsHelper.GetContent("SoundAddr", "Address01"));
//if(SoundClient.SoundPlay!=null)
//{
// SoundClient.SoundPlay(SoundEnum.music41);
//}
// SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.WelcomeInfo);
// LedClient.SendMsgByKey(InfoEnum.SwapInfo.WelcomeInfo.GetLed());
isRemote = true; isRemote = true;
} }
}
}, },
() => () =>
{ {
@ -216,7 +198,7 @@ public class StationReadyState : IState
if (PadarMgr._PadarClient?.CarState == 6 || machine.ManualSkipRadar) if (PadarMgr._PadarClient?.CarState == 6 || machine.ManualSkipRadar)
{ {
PlcApi.Traffic(0); PlcApi.Traffic(1);
i = 0; i = 0;
a = 0; a = 0;
LedClient.SendMsgByKey(InfoEnum.SwapInfo.diparkir.GetLed()); LedClient.SendMsgByKey(InfoEnum.SwapInfo.diparkir.GetLed());

@ -299,7 +299,7 @@ public class SwapDoneState : IState
_log.Info("exist radar true"); _log.Info("exist radar true");
LedClient.SendMsgByKey(InfoEnum.SwapInfo.PleaseAwayyin.GetLed()); LedClient.SendMsgByKey(InfoEnum.SwapInfo.PleaseAwayyin.GetLed());
PlcApi.Traffic(1); PlcApi.Traffic(2);
//出口写红灯 //出口写红灯
//更新车辆离场时间,上报云平台 //更新车辆离场时间,上报云平台
//machine.BusinessSwappingForCloudState = //machine.BusinessSwappingForCloudState =

@ -6,6 +6,10 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using HslCommunication;
using HybirdFrameworkCore.Utils;
using Service.Charger.Server;
using Service.Execute.Model;
namespace Service.PlcAfrica.Client namespace Service.PlcAfrica.Client
{ {
@ -20,8 +24,6 @@ namespace Service.PlcAfrica.Client
static int DataTimeSeconds = 20; static int DataTimeSeconds = 20;
/// <summary> /// <summary>
/// 数据刷新时间 /// 数据刷新时间
/// </summary> /// </summary>
@ -36,5 +38,199 @@ namespace Service.PlcAfrica.Client
Task.Run(() => PlcAfricaClient.Connect()); 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;
}
} }
} }

@ -59,6 +59,7 @@ public class PlcAfricaMsg
/// <summary> /// <summary>
/// 站控操作指令 /// 站控操作指令
///
/// </summary> /// </summary>
public ModbusProperty<ushort> OperationInstruction {get;set;}= new(47010); public ModbusProperty<ushort> OperationInstruction {get;set;}= new(47010);

Loading…
Cancel
Save