换电流程修改

master
xjl 4 months ago
parent 53c2307b80
commit e00d94e103

@ -110,7 +110,7 @@ public class PlcApi
{
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
var distributeTask = PlcMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo), 1);
var distributeTask = PlcMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo), 2);
Log.Info($"PlcApi StartSwapping resp={distributeTask}");
return distributeTask;
@ -160,15 +160,17 @@ public class PlcApi
/// 查看拍照状态
/// </summary>
/// <returns></returns>
public static ushort ChannelStatus()
public static ushort[] ChannelStatus()
{
Log.Info($"PlcApi start ChannelStatus ");
PlcMgr.ResetPlc();
var channelStatus = PlcMgr.ChannelStatus();
ushort[] channelStatus=new ushort[2];
channelStatus[0] = PlcMgr.ChannelStatus(1);
channelStatus[1] = PlcMgr.ChannelStatus(2);
Log.Info($"PlcApi ChannelStatus resp= {channelStatus}");
return channelStatus;
}
/// <summary>
/// 读plc任务状态

@ -119,8 +119,57 @@ public class Invoker
Log.Info($" {name} done");
return InvokeStatus.Done;
}
public static InvokeStatus Invoke(string name, int duration, int times, Func<bool> cancel, Func<bool> abnormal, Func<bool> done,
Action doAction,
Action timeoutAction, bool isTimeOutExit, int timeOutActionTime,
InvokeStatus timeOutException)
{
int count = 0;
while (!done())
{
Log.Info($"begin {name}");
Thread.Sleep(duration);
if (cancel())
{
Log.Info($" {name} canceled");
return InvokeStatus.Cancel;
}
if (abnormal())
{
Log.Info($" {name} Exception");
return InvokeStatus.Exception;
}
try
{
doAction();
}
catch (Exception e)
{
Log.Error($"{name}", e);
}
if (count++ > times)
{
if (count % timeOutActionTime == 0)
{
timeoutAction();
Log.Info($" {name} timeout");
if (isTimeOutExit)
{
return timeOutException;
}
}
}
}
Log.Info($" {name} done");
return InvokeStatus.Done;
}
public static InvokeStatus Invoke(string name, int duration, int times, Func<bool> cancel,Func<bool> succ, Func<bool> done,
Action doAction,
Action timeoutAction, bool isTimeOutExit, Action exceptionAction, int timeOutActionTime,

@ -174,7 +174,7 @@ public class CommonMgr
/// </summary>
/// <param name="orderBatteryInfo"></param>
public void UpBin(SwapOrderBatteryInfo orderBatteryInfo)
{
{//TODO 选包只选右侧的1~8
SelectPackDto selectPack =
_binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime,
QueryMoveBinNo()[0]);

@ -7,12 +7,14 @@ public class DistributeTask
{
/// <summary>
/// 任务类型
/// 0.无任务
/// 1.换电任务
/// 2.移舱任务
/// 3.移出任务
/// 4.移入任务
/// 5.消防任务
/// <para>0.待机</para>
/// <para>1.任务异常结束</para>
/// <para>2.换电任务</para>
/// <para>3.入库任务</para>
/// <para>4.出库任务</para>
/// <para>5.维护任务</para>
/// <para>6.调库任务</para>
/// <para>7.消防任务</para>
/// </summary>
[Property(0, 16)]
public ushort TaskNo { get; set; }

@ -9,6 +9,9 @@ using Service.Mgr;
namespace Service.Execute.Step;
/// <summary>
/// 人工确认失败
/// </summary>
public class CancelState : IState
{
private readonly CommonMgr _CommonMgr = AppInfo.Container.Resolve<CommonMgr>();

@ -240,7 +240,7 @@ public class CarCtrlState : IState
count++;
if (channelStatus == 1000)
if (channelStatus[0] == 1000 && channelStatus[1] == 1000)
{
machine.ChannelStatusOkFlag = true;
return null;

@ -121,7 +121,7 @@ public class DoSwappingState : IState
machine.SwapOrderBatteryInfo.UpBinInfo.No);
//查詢當前任務狀態是否被更改
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1);
var readPlcTaskStatus = PlcApi.ReadTaskStatus(2);
if (startSwapping && readPlcTaskStatus)
{
machine.SwapOrder.SwapBeginTime = DateTime.Now;
@ -150,7 +150,7 @@ public class DoSwappingState : IState
() => machine.PlcHoldFlag, () =>
{
//查询车辆锁止状态
var taskPrepare = PlcApi.ReadTaskStatus(1);
var taskPrepare = PlcApi.ReadTaskStatus(2);
if (taskPrepare)
{
bool holdOn = PlcApi.HoldOn();
@ -174,12 +174,20 @@ public class DoSwappingState : IState
/// <returns></returns>
public InvokeStatus UnPack(SwappingStateMachine machine)
{
return Invoker.Invoke("plc UnPack", 500, 5, machine.IsCanceled,
return Invoker.Invoke("plc UnPack", 500, 5, machine.IsCanceled, machine.IsPLCAbnormal,
() => machine.UnOldBatteryFlag, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoUnPack.GetLed());
//plc任务异常结束流程
if (PlcApi.ReadTaskStatus(1))
{
machine.PLCAbnormalFlag = true;
machine.SwapStatus = (int)InfoEnum.SwapOrderResult.Fail;
machine.SwapFailReason = "PLC任务异常结束";
}
int status = PlcApi.ReadPlcTaskStatus();
//处理程序太快plc还没有初始值的状态
if (status == 1002 || status != 1003)
@ -195,16 +203,24 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.UnOldBatteryFlag,
machine);
}
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoUnPack); }, false, () => { }, 10,
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoUnPack); }, false, 10,
InvokeStatus.None);
}
public InvokeStatus OldBatteryCarryIn(SwappingStateMachine machine)
{
return Invoker.Invoke("plc OldBatteryCarryIn", 500, 5, machine.IsCanceled,
return Invoker.Invoke("plc OldBatteryCarryIn", 500, 5, machine.IsCanceled, machine.IsPLCAbnormal,
() => machine.StorageOldBatteryFlag, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoOldBatteryCarryIn.GetLed());
//plc任务异常结束流程
if (PlcApi.ReadTaskStatus(1))
{
machine.PLCAbnormalFlag = true;
machine.SwapStatus = (int)InfoEnum.SwapOrderResult.Fail;
machine.SwapFailReason = "PLC任务异常结束";
}
var readPlcTaskStatus = PlcApi.ReadPlcTaskStatus();
if (readPlcTaskStatus == 1003 || readPlcTaskStatus != 1004)
@ -222,17 +238,24 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StorageOldBatteryFlag,
machine);
}
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoOldBatteryCarryIn); }, false, () => { }, 10,
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoOldBatteryCarryIn); }, false, 10,
InvokeStatus.None);
}
public InvokeStatus NewBatteryCarryOut(SwappingStateMachine machine)
{
return Invoker.Invoke("plc NewBatteryCarryOut", 500, 5, machine.IsCanceled,
return Invoker.Invoke("plc NewBatteryCarryOut", 500, 5, machine.IsCanceled, machine.IsPLCAbnormal,
() => machine.OutNewBatteryFlag, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoNewBatteryCarryOut.GetLed());
//plc任务异常结束流程
if (PlcApi.ReadTaskStatus(1))
{
machine.PLCAbnormalFlag = true;
machine.SwapStatus = (int)InfoEnum.SwapOrderResult.Fail;
machine.SwapFailReason = "PLC任务异常结束";
}
if (PlcApi.ReadPlcTaskStatus() == 1004)
{
@ -247,16 +270,24 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.OutNewBatteryFlag,
machine);
}
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoNewBatteryCarryOut);}, false, () => { }, 10,
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoNewBatteryCarryOut);}, false, 10,
InvokeStatus.None);
}
public InvokeStatus Pack(SwappingStateMachine machine)
{
return Invoker.Invoke("plc Pack ing", 500, 5, machine.IsCanceled,
return Invoker.Invoke("plc Pack ing", 500, 5, machine.IsCanceled, machine.IsPLCAbnormal,
() => machine.InstallNewBatteryFlag, () =>
{
//plc任务异常结束流程
if (PlcApi.ReadTaskStatus(1))
{
machine.PLCAbnormalFlag = true;
machine.SwapStatus = (int)InfoEnum.SwapOrderResult.Fail;
machine.SwapFailReason = "PLC任务异常结束";
}
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1005)
{
@ -275,16 +306,24 @@ public class DoSwappingState : IState
}, () =>
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack);
},false, () => { },
},false,
10,InvokeStatus.None);
}
public InvokeStatus PackFinish(SwappingStateMachine machine)
{
return Invoker.Invoke("plc Pack Finish", 500, 5, machine.IsCanceled,
return Invoker.Invoke("plc Pack Finish", 500, 5, machine.IsCanceled, machine.IsPLCAbnormal,
() => machine.FinishNewBatteryFlag, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
//plc任务异常结束流程
if (PlcApi.ReadTaskStatus(1))
{
machine.PLCAbnormalFlag = true;
machine.SwapStatus = (int)InfoEnum.SwapOrderResult.Fail;
machine.SwapFailReason = "PLC任务异常结束";
}
var readPlcTaskStatus = PlcApi.ReadPlcTaskStatus();
if (readPlcTaskStatus == 1006 || readPlcTaskStatus == 1007)
{
@ -298,7 +337,7 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag,
machine);
}
}, () => { },false, () => { },
}, () => { },false,
10,InvokeStatus.None);
}

@ -40,6 +40,9 @@ public class SwappingStateMachine : IDisposable
//手动确认解锁/上锁成功
public bool ManualConfirmCarLockFlag { get; set; }
//plc任务异常流程结束
public bool PLCAbnormalFlag { get; set; }
public OperateModel OperateModel = null;
public readonly LedTool? LedTool = null;
@ -204,6 +207,10 @@ public class SwappingStateMachine : IDisposable
{
return new StateResult() { SwappingState = SwappingState.ManualSucc };
}
else if(status == InvokeStatus.Exception)
{
return new StateResult() { SwappingState = SwappingState.SwapDone };
}
else
{
return StateResult.Exception(exceptionReason, null);
@ -247,7 +254,11 @@ public class SwappingStateMachine : IDisposable
{
return CancelFlag;
}
public bool IsPLCAbnormal()
{
return PLCAbnormalFlag;
}
public bool IsManualSwapSucc()
{
return ManualSwapSuccFlag;
@ -358,6 +369,7 @@ public class SwappingStateMachine : IDisposable
ManualConfirmCarLockFlag = false;
CancelFlag = false;
StopFlag = false;
PLCAbnormalFlag=false;
}
private void ResetStep()

@ -43,10 +43,10 @@ public class PlcTaskMgr
{
Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute ing");
if (taskNo == 2)
if (taskNo == 6)
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoBatteryMove);
}else if (taskNo == 5)
}else if (taskNo == 7)
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoFireRemove);
}

@ -237,16 +237,23 @@ public class PlcMgr
/// <summary>
/// 下发启动换电
/// 下发换电任务以外的任务 6:调库 7消防
/// </summary>
/// <param name="inBinNo"> 入仓位</param>
/// <param name="outBinNo">出仓位</param>
/// <param name="taskNo">任务类型</param>
/// <returns></returns>
public static bool StartSwapping()
public static bool StartSwapping(ushort inBinNo, ushort outBinNo, ushort taskNo)
{
if (PlcClient != null)
{
HostToPlc writeHostToPlc = new HostToPlc();
writeHostToPlc.TaskType.Value = (ushort)1;
// writeHostToPlc.TaskEnablement.Value = (ushort)1000;
writeHostToPlc.TaskType.Value = taskNo;
writeHostToPlc.EntrySelection2.Value = inBinNo;
writeHostToPlc.ExitSelection2.Value = outBinNo;
//writeHostToPlc.TaskEnablement.Value = (ushort)1000;
bool write1 = PlcClient.WriteValue(writeHostToPlc.TaskType);
//bool write2 = PlcClient.WriteValue(writeHostToPlc.TaskEnablement);
return write1;
@ -262,12 +269,20 @@ public class PlcMgr
/// <summary>
/// 查看拍照状态
/// </summary>
/// <param name="location">位置 1左侧 2右侧 </param>
/// <returns></returns>
public static ushort ChannelStatus()
public static ushort ChannelStatus(int location)
{
if (PlcClient != null)
{
return PlcToHostData.ChannelLocationState.Value;
if (location==1)
{
return PlcToHostData.ChannelLocationState2.Value;
}
else
{
return PlcToHostData.ChannelLocationState.Value;
}
}
return 0;

@ -259,7 +259,7 @@ namespace Service.Plc.Msg
/// <para>5.维护任务</para>
/// <para>6.调库任务</para>
/// <para>7.消防任务</para>
/// <summary>
/// </summary>
public ModbusProperty<ushort> TaskType { get; set; } = new(40407);
/// <summary>
/// 堆垛机任务状态

@ -82,14 +82,15 @@ namespace Service.Station
}
}
var result = PlcMgr.DistributeTask(0, ushort.Parse(entrySelection), 5);
//var result = PlcMgr.DistributeTask(0, ushort.Parse(entrySelection), 5);
var result = PlcMgr.StartSwapping(0, ushort.Parse(entrySelection), 7);
if (!result)
{
return Result<bool>.Fail();
}
result = PlcMgr.ReadTaskStatus(5);
result = PlcMgr.ReadTaskStatus(7);
if (!result)
{
return Result<bool>.Fail();
@ -104,7 +105,7 @@ namespace Service.Station
Log.Info($"FireProtectionRelocation task Manual removeBinNo={entrySelection} ");
return PlcTaskMgr.QueryPlcTask(5, 1100, 1101) ? Result<bool>.Success() : Result<bool>.Fail();
return PlcTaskMgr.QueryPlcTask(7, 1100, 1101) ? Result<bool>.Success() : Result<bool>.Fail();
}

@ -200,7 +200,7 @@ public class MonitorService
/// <summary>
/// 电池移仓
/// </summary>
/// <param name="removeBinNo"></param>
/// <param name="removeBinNo">出仓位</param>
/// <param name="putBinNo"></param>
/// <returns></returns>
public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo, int type = 0)
@ -209,22 +209,31 @@ public class MonitorService
try
{
//校验:出仓位
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(removeBinNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
i.AmtLock == 0);
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(removeBinNo) && (i.ChargeStatus != 1) && i.Exists == 1 &&
i.AmtLock == 0);
if (removeBin == null)
{
if (removeBin == null)
{
return Result<bool>.Fail("出仓位状态有误");
}
}
BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 &&
i.Status == 1);
if (putBin == null)
{
BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 );//&& i.Status == 1
if (putBin == null)
{
return Result<bool>.Fail("入仓位状态有误");
}
}
bool ipsilateral = false;
if ((removeBinNo <=8 && putBinNo <= 8)||( removeBinNo > 8 && putBinNo > 8))
{
ipsilateral = true;
}
if (!ipsilateral)
{
return Result<bool>.Fail("出仓位和入仓位不在同侧");
}
if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
{
@ -232,35 +241,36 @@ public class MonitorService
return Result<bool>.Fail("当前存在其他任务");
}
PlcMgr.PlcClient?.ExChangeTaskNo(2);
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2);
if (!result)
{
PlcMgr.PlcClient?.ExChangeTaskNo(6);
//var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2);
var result = PlcMgr.StartSwapping(putBinNo, removeBinNo, 6);
if (!result)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Fail();
}
return Result<bool>.Fail();
}
int count = 3;
while (count > 0)
{
result = PlcMgr.ReadTaskStatus(2);
if (result)
int count = 3;
while (count > 0)
{
break;
result = PlcMgr.ReadTaskStatus(6);
if (result)
{
break;
}
count--;
Thread.Sleep(1000);
}
count--;
Thread.Sleep(1000);
}
if (!result)
{
if (!result)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false");
return Result<bool>.Fail();
}
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(6) =false");
return Result<bool>.Fail();
}
moveBinRecord = new MoveBinRecord()
{
@ -274,62 +284,60 @@ public class MonitorService
Type = type,
CreatedTime = DateTime.Now
};
moveBinRecord= MoveBinRecordRepository.Insert(moveBinRecord);
moveBinRecord = MoveBinRecordRepository.Insert(moveBinRecord);
result = PlcMgr.HoldOn();
if (!result)
{
result = PlcMgr.HoldOn();
if (!result)
{
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.HoldOn() =false");
Log.Error("BatteryRelocation PlcMgr.HoldOn() =false");
return Result<bool>.Fail();
}
}
Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} type={type} ");
moveBinRecord.Status = 1;
MoveBinRecordRepository.Update(moveBinRecord);
var queryPlcTask = PlcTaskMgr.QueryPlcTask(2, 1200, 1201);
if (!queryPlcTask)
{
var queryPlcTask = PlcTaskMgr.QueryPlcTask(6, 1200, 1201);
if (!queryPlcTask)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Info($"move battery fail update moveBin={JsonConvert.SerializeObject(moveBinRecord)}");
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
return Result<bool>.Fail();
}
return Result<bool>.Fail();
}
Log.Info($"move battery success update moveBin={JsonConvert.SerializeObject(moveBinRecord)}");
//如果是缓存仓 更新缓存仓的数据
if (putBin.CacheBinFlag == 1)
{
putBin.Exists = 1;
putBin.BatteryNo = removeBin.BatteryNo;
putBin.Soc = removeBin.Soc;
putBin.Soe = removeBin.Soe;
putBin.Soh = removeBin.Soh;
putBin.BatteryEnterSeq = removeBin.BatteryEnterSeq;
putBin.InTime = removeBin.InTime;
BinInfoRepository.Update(putBin);
}
if (putBin.CacheBinFlag == 1)
{
putBin.Exists = 1;
putBin.BatteryNo = removeBin.BatteryNo;
putBin.Soc = removeBin.Soc;
putBin.Soe = removeBin.Soe;
putBin.Soh = removeBin.Soh;
putBin.BatteryEnterSeq = removeBin.BatteryEnterSeq;
putBin.InTime = removeBin.InTime;
BinInfoRepository.Update(putBin);
}
if (removeBin.CacheBinFlag == 1)
{
removeBin.Exists = 0;
removeBin.BatteryNo = "-1";
removeBin.Soc = -1;
removeBin.Soe = -1;
removeBin.Soh = -1;
}
removeBin.BatteryEnterSeq = 0;
BinInfoRepository.Update(removeBin);
removeBin.BatteryEnterSeq = 0;
BinInfoRepository.Update(removeBin);
moveBinRecord.Status = 2;
Log.Info($"move battery success update moveBin={JsonConvert.SerializeObject(moveBinRecord)}");
MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0);
}
catch (Exception e)
{

@ -119,6 +119,7 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")]
public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{
//TODO 只能同侧移仓
return _monitorService.BatteryRelocation(removeBinNo, putBinNo);
}

Loading…
Cancel
Save