换电流程

master
lxw 3 days ago
parent 64807c8800
commit 18c671dbda

@ -3,6 +3,7 @@ using log4net;
using Service.Charger.Client;
using Service.Mgr;
using Service.Padar.Client;
using Service.PlcAfrica.Client;
namespace Service.Execute.Api;
@ -17,6 +18,26 @@ public class PlcApi
/// </summary>
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>
/// 是否远程模式
@ -24,17 +45,17 @@ public class PlcApi
/// <returns></returns>
public static bool IsRemote()
{
return ClientMgr.PlcClient!.Remote;
return PlcAfricaMgr.IsAutoAndRemote();
}
/// <summary>
/*/// <summary>
/// 是否初始化完成
/// </summary>
/// <returns></returns>
public static bool IsInit()
{
return ClientMgr.PlcClient!.Init;
}
}*/
/// <summary>
/// 是否自动
@ -42,11 +63,7 @@ public class PlcApi
/// <returns></returns>
public static bool IsAuto()
{
if (ClientMgr.PlcClient!=null)
{
return ClientMgr.PlcClient.Auto;
}
return false;
return PlcAfricaMgr.IsAutoAndRemote();
}
/// <summary>
@ -61,11 +78,12 @@ public class PlcApi
$"出仓位:{outBinNo},入仓位:{inBinNo}" ,(int)SwapConstant.CommunicationType.Send);
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
ClientMgr.PlcClient?.SendStartBatterySwapReq(Convert.ToByte(outBinNo), Convert.ToByte(inBinNo));
Log.Info($"PlcApi StartSwapping done");
return ClientMgr.PlcClient.SwapStart;
if (PlcAfricaMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo)))
{
Log.Info($"PlcApi StartSwapping done");
return PlcAfricaMgr.StartSwap();
}
return false;
}
/// <summary>
@ -89,7 +107,7 @@ public class PlcApi
/// <summary>
/*/// <summary>
/// 发送初始化命令
/// </summary>
/// <returns></returns>
@ -99,18 +117,24 @@ public class PlcApi
ClientMgr.PlcClient?.SendInitializeCommandReq();
Log.Info($"PlcApi Init done");
return true;
}
}*/
/// <summary>
/// 发送红绿灯
/// </summary>
/// <returns></returns>
public static bool Traffic(byte Light)
public static bool Traffic(ushort light)
{
Log.Info($"PlcApi Init ");
ClientMgr.PlcClient?.SendTrafficLightReq(Light);
Log.Info($"PlcApi Init done");
return true;
return PlcAfricaMgr.LightControl(light);
}
/// <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
{
/// <summary>
/*/// <summary>
/// 任务类型
/// 0.无任务
/// 1.换电任务
@ -15,23 +15,23 @@ public class DistributeTask
/// 5.消防任务
/// </summary>
[Property(0, 16)]
public ushort TaskNo { get; set; }
public ushort TaskNo { get; set; }*/
/// <summary>
/// 入仓位选择
/// </summary>
[Property(16, 16)]
[Property(0, 16)]
public ushort InBinNo { get; set; }
/// <summary>
/// 出仓仓位选择
/// </summary>
[Property(32, 16)]
[Property(16, 16)]
public ushort OutBinNo { get; set; }
/// <summary>
/*/// <summary>
/// 电池包类型 0
/// </summary>
[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);
if (InvokeStatus.Done != adjustCarByRadar)

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

@ -152,26 +152,8 @@ public class StationReadyState : IState
{
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;
}
}
},
() =>
@ -216,7 +198,7 @@ public class StationReadyState : IState
if (PadarMgr._PadarClient?.CarState == 6 || machine.ManualSkipRadar)
{
PlcApi.Traffic(0);
PlcApi.Traffic(1);
i = 0;
a = 0;
LedClient.SendMsgByKey(InfoEnum.SwapInfo.diparkir.GetLed());

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

@ -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;
}
}
}
}

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

Loading…
Cancel
Save