关于并行任务的更改

master
rszn 5 months ago
parent 0e34dab0ca
commit 4fb7cbfbf4

@ -0,0 +1,70 @@
using SqlSugar;
namespace Entity.DbModel.Station;
///<summary>
///充电订单;充电订单表
///</summary>
[SugarTable("move_bin_record")]
public class MoveBinRecord : BaseModel
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "id")]
public int Id { get; set; }
/// <summary>
/// in_bin_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "in_bin_no")]
public string? InBinNo { get; set; }
/// <summary>
/// in_battery_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "in_battery_no")]
public string? InBatteryNo { get; set; }
/// <summary>
/// in_battery_soc
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "in_battery_soc")]
public string? InBatterySoc { get; set; }
/// <summary>
/// in_bin_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "up_bin_no")]
public string? UpBinNo { get; set; }
/// <summary>
/// in_battery_no
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "up_battery_no")]
public string? UpBatteryNo { get; set; }
/// <summary>
/// in_battery_soc
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "up_battery_soc")]
public string? UpBatterySoc { get; set; }
/// <summary>
/// 狀態 0初始化 1進行中 2成功 3失敗
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "status")]
public int Status { get; set; }
/// <summary>
/// 类型 0自动 1:手动
/// </summary>
[SugarColumn(IsPrimaryKey = true, ColumnName = "type")]
public int Type { get; set; }
}

@ -19,25 +19,36 @@ public class BinInfoRepository : BaseRepository<BinInfo>
/// <param name="swapSoc"> StaticStationInfo.SwapSoc </param>
/// <param name="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param>
/// <returns></returns>
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime)
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime, string upMoveNo)
{
SelectPackDto selectPackDto = new()
{
SuccessFlag = false,
};
List<BinInfo> list =
QueryListByClause(i => i.CacheBinFlag == 0 && i.CanSwapFlag==1 &&
QueryListByClause(i => i.CanSwapFlag == 1 &&
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock,
"in_time asc");
BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc);
if (list.Count <= 0 && cacheBinBattery == null)
// BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc);
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery;
return selectPackDto;
}
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus==4).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
list = list.OrderBy(i => i.CacheBinFlag).ToList();
if (!string.IsNullOrWhiteSpace(upMoveNo))
{
list = list.Where(i => !upMoveNo.Equals(i.No) && (i.No != "" || i.No != "-1")).ToList();
}
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList();
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
return selectPackDto;
@ -45,7 +56,7 @@ public class BinInfoRepository : BaseRepository<BinInfo>
list = list.Where(i => i.Soc != null && i.Soc >= swapSoc).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
return selectPackDto;
@ -54,20 +65,15 @@ public class BinInfoRepository : BaseRepository<BinInfo>
list = list.Where(i => i.LastChargeFinishTime != null && new TimeSpan(DateTime.Now.Ticks -
i.LastChargeFinishTime.ToDateTime().Ticks)
.TotalMinutes > swapFinishChargeTime).ToList();
if (list.Count <= 0 && cacheBinBattery == null)
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute;
return selectPackDto;
}
if (list.Count > 0)
{
selectPackDto.BinInfo = list[0];
}
else
{
selectPackDto.BinInfo = cacheBinBattery;
}
selectPackDto.BinInfo = list[0];
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success;
selectPackDto.SuccessFlag = true;
@ -84,7 +90,7 @@ public class BinInfoRepository : BaseRepository<BinInfo>
public BinInfo? ChooseCacheBinBattery(int swapSoc)
{
return
QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag==1 && i.Soc >= swapSoc &&
QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag == 1 && i.Soc >= swapSoc &&
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock);
}
}

@ -0,0 +1,14 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope("SingleInstance")]
public class MoveBinRecordRepository:BaseRepository<MoveBinRecord>
{
public MoveBinRecordRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -123,12 +123,26 @@ public class PlcApi
/// <returns></returns>
public static bool ReadTaskStatus(ushort taskNo)
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi ReadTaskStatus param= taskNo={taskNo}");
var readTaskStatus = PlcMgr.ReadTaskStatus(taskNo);
Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}");
return readTaskStatus;
}
/// <summary>
/// 读取任务状态
/// </summary>
/// <returns></returns>
public static bool ReadTaskStatusReset()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi ReadTaskStatus param= taskNo={0}");
var readTaskStatus = PlcMgr.ReadTaskStatus(0);
Log.Info($"PlcApi ReadTaskStatus resp={readTaskStatus}");
return readTaskStatus;
}
/// <summary>
/// plc上使能
/// </summary>
@ -162,6 +176,7 @@ public class PlcApi
/// <returns>6未连接</returns>
public static int ReadPlcTaskStatus()
{
PlcMgr.ResetPlc();
Log.Info($"PlcApi start ReadPlcTaskStatus ");
var readPlcTaskStatus = PlcMgr.ReadPlcTaskStatus();
Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}");

@ -6,9 +6,12 @@ using Entity.Dto;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using Repository.Station;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Init;
using Service.Plc.Client;
using Service.Station;
using SqlSugar;
namespace Service.Execute.Utils;
@ -24,6 +27,8 @@ public class CommonMgr
public SwapOrderReportCloudRepository _swapOrderReportCloudRepository { get; set; }
public MoveBinRecordRepository MoveBinRecordRepository { get; set; }
/// <summary>
/// 新增小步状态
/// </summary>
@ -156,17 +161,43 @@ public class CommonMgr
/// <summary>
/// 取电池判断
/// 不能选正在执行移仓的电池
/// </summary>
/// <param name="orderBatteryInfo"></param>
public void UpBin(SwapOrderBatteryInfo orderBatteryInfo)
{
SelectPackDto selectPack =
_binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime);
_binInfoRepository.SelectPack(StaticStationInfo.SwapSoc, StaticStationInfo.SwapFinishChargeTime,
queryMoveBinNo()[0]);
orderBatteryInfo.UpBinInfo = selectPack.BinInfo;
orderBatteryInfo.CanSwap = selectPack.Info;
}
private List<string> queryMoveBinNo()
{
string moveUp = "";
string moveIn = "";
//当前有移仓任务
if (PlcMgr.PlcClient.ReadTaskNo() == 2)
{
MoveBinRecord queryByClause = MoveBinRecordRepository.QueryByClause(i => i.Status == 0 || i.Status == 1,
i => i.CreatedTime,
OrderByType.Desc);
if (queryByClause != null)
{
moveUp = queryByClause.UpBinNo;
moveIn = queryByClause.InBinNo;
}
}
return new List<string>()
{
moveUp, moveIn
};
}
/// <summary>
/// 放电池判断:取出来的电池仓位能不能放
/// </summary>
@ -185,6 +216,17 @@ public class CommonMgr
return;
}
var value = queryMoveBinNo()[1];
if (!string.IsNullOrWhiteSpace(value))
{
list = list.Where(i => i.No != value).ToList();
}
if (list.Count <= 0)
{
orderBatteryInfo.CanSwap = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin;
return;
}
orderBatteryInfo.InBinInfo = list[0];
orderBatteryInfo.InBinInfo.BatteryNo = "-1";
orderBatteryInfo.InBinInfo.Soc = -1;
@ -194,7 +236,7 @@ public class CommonMgr
if (carInfoBatteryInfos != null && carInfoBatteryInfos.Count > 0)
{
orderBatteryInfo.InBinInfo.BatteryNo = carInfoBatteryInfos[0].BatteryNo;
// orderBatteryInfo.InBinInfo.Soc = carInfoBatteryInfos[0].Soc;
// orderBatteryInfo.InBinInfo.Soc = carInfoBatteryInfos[0].Soc;
orderBatteryInfo.InBinInfo.Soe = carInfoBatteryInfos[0].Soe;
orderBatteryInfo.InBinInfo.Soh = carInfoBatteryInfos[0].Soh;
}
@ -277,4 +319,4 @@ public class CommonMgr
Vtm = Convert.ToSingle(machine.BoxCarInfoModel?.ElecMsg?.TotalMile),
});
}
}
}

@ -11,6 +11,7 @@ using Service.Execute.StaticTools;
using Service.Execute.SwapException;
using Service.Execute.Utils;
using Service.Init;
using Service.Plc.Client;
using Service.Station;
namespace Service.Execute.Step;
@ -100,6 +101,7 @@ public class DoSwappingState : IState
{
return SwappingStateMachine.ReturnWithInvokeErr(toInvokeStatus, ExceptionReason.None);
}
//查询换电任务是否结束
return new StateResult()
@ -121,26 +123,36 @@ public class DoSwappingState : IState
bool unLock = result.Result;
if (unLock)
{
//查询车辆锁止状态
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
//查询当前是否有任务执行
//查詢當前任務狀態是否被更改
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1);
if (startSwapping && readPlcTaskStatus)
var readTaskNo = PlcMgr.PlcClient?.ReadTaskNo();
if (readTaskNo == 0 || readTaskNo==1)
{
machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine);
machine.SwapStatus = 0;
machine.StartSwappingFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine);
PlcMgr.PlcClient?.ExChangeTaskNo(1);
//查询车辆锁止状态
var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
//查詢當前任務狀態是否被更改
var readPlcTaskStatus = PlcApi.ReadTaskStatus(1);
if (startSwapping && readPlcTaskStatus)
{
machine.SwapOrder.SwapBeginTime = DateTime.Now;
_CommonMgr.UpdateSwapOrder(machine);
machine.SwapStatus = 0;
machine.StartSwappingFlag = true;
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.StartSwappingFlag,
machine);
}
}
else
{
_log.Info("当前有任务在执行");
}
}
}, () =>
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap);
},false, () => { },10,InvokeStatus.None);
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrStartSwap); }, false, () => { }, 10,
InvokeStatus.None);
}
@ -240,7 +252,6 @@ public class DoSwappingState : IState
if (PlcApi.ReadPlcTaskStatus() == 1004)
{
}
else
{
@ -252,7 +263,7 @@ 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);
}
@ -265,7 +276,6 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPack.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1005)
{
}
else
{
@ -277,11 +287,8 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.InstallNewBatteryFlag,
machine);
}
}, () =>
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack);
},false, () => { },
10,InvokeStatus.None);
}, () => { SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoPack); }, false, () => { },
10, InvokeStatus.None);
}
public InvokeStatus PackFinish(SwappingStateMachine machine)
@ -303,8 +310,8 @@ public class DoSwappingState : IState
_CommonMgr.InsertStep(InfoEnum.BusinessSwappingStep.FinishNewBatteryFlag,
machine);
}
}, () => { },false, () => { },
10,InvokeStatus.None);
}, () => { }, false, () => { },
10, InvokeStatus.None);
}
/// <summary>
@ -318,14 +325,18 @@ public class DoSwappingState : IState
() => machine.ToSafePositionFlag, () =>
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.InfoPackFinish.GetLed());
if (PlcApi.ReadPlcTaskStatus() == 1007)
{
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition);
machine.ToSafePositionFlag = true;
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
if (PlcApi.ReadTaskStatusReset())
{
PlcMgr.PlcClient?.ResetTaskNo();
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.InfoToSafePosition);
machine.ToSafePositionFlag = true;
machine.BusinessSwappingStateUpdateTime = DateTime.Now;
machine.SwapStatus = 1;
machine.SwapStatus = 1;
}
}
}, () => { });
}
@ -344,13 +355,12 @@ public class DoSwappingState : IState
int count = 0;
while (!machine.ChannelStatusOkFlag)
{
if (machine.CancelFlag)
{
_log.Info($" CheckChannelStatus canceled");
return StateResult.Cancel;
return StateResult.Cancel;
}
_log.Info("begin plc CheckChannelStatus");
Thread.Sleep(2000);
var channelStatus = PlcApi.ChannelStatus();
@ -375,7 +385,7 @@ public class DoSwappingState : IState
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrChannelStatus.GetLed());
SoundApi.PlayOneSound((int)InfoEnum.SwapInfo.ErrChannelStatus);
//等待2分钟
Thread.Sleep(3*60 *1000);
Thread.Sleep(3 * 60 * 1000);
machine.VehiclesInPlace2Flag = false;
machine.StartSwappingFlag = false;
machine.PlcHoldFlag = false;
@ -448,8 +458,8 @@ public class DoSwappingState : IState
succCount++;
}
}
if (succCount==successCount)
if (succCount == successCount)
{
machine.VehiclesInPlace2Flag = true;
}
@ -461,4 +471,4 @@ public class DoSwappingState : IState
}, false, () => { }
, 20, InvokeStatus.None);
}
}
}

@ -12,6 +12,7 @@ using Service.Execute.Model.Tbox;
using Service.Execute.StaticTools;
using Service.Execute.Step;
using Service.Execute.SwapException;
using Service.Plc.Client;
namespace Service.Execute;
@ -249,6 +250,11 @@ public class SwappingStateMachine : IDisposable
public void Reset()
{
Log.Info("reset data");
if (PlcMgr.PlcClient?.ReadTaskNo() == 1)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
}
ResetOrderAmtStatus();
if (RfidReadModel != null)
{
@ -280,7 +286,7 @@ public class SwappingStateMachine : IDisposable
Log.Info($"ManualSwapSuccFlag machine ok");
return true;
}
public bool ManualConfirmLockCar()
{
ManualConfirmCarLockFlag = true;
@ -288,7 +294,7 @@ public class SwappingStateMachine : IDisposable
Log.Info($"ManualConfirmLockCar ok");
return true;
}
public bool ManualConfirmUnLockCar()
{
ManualConfirmCarUnlockFlag = true;
@ -298,7 +304,6 @@ public class SwappingStateMachine : IDisposable
}
private void ResetData()
{
BusinessSwappingForCloudState = InfoEnum.BusinessSwappingForCloudState.Idle;
@ -417,7 +422,7 @@ public class SwappingStateMachine : IDisposable
}
}
//预约单
//预约单
List<SwapAmtOrder> amtOrderInfos = AmtOrderRepository.QueryListByClause(it =>
it.ExpireTime < DateTime.Now
&& it.Status == (byte)InfoEnum.AmtOrderStatus.Success).ToList();
@ -454,4 +459,4 @@ public enum SwappingState
Exception,
Canceled,
ManualSucc,
}
}

@ -48,7 +48,7 @@ public class BatteryMoveTask : ITask
}
List<BinInfo> queryListByClause =
_binInfoRepository.QueryListByClause(i => i.ChargeStatus == 4 && i.CacheBinFlag == 0 && i.Soc>=StaticStationInfo.SwapSoc
_binInfoRepository.QueryListByClause(i => i.ChargeStatus == 4 && i.CacheBinFlag == 0 && i.Soc>=StaticStationInfo.SwapSoc
&& i.AmtLock == 0 && i.Status == 1, "battery_enter_seq asc");
@ -57,6 +57,11 @@ public class BatteryMoveTask : ITask
return;
}
//不能进行移仓
if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
{
return;
}
var binInfo = queryListByClause[0];
Result<bool> success =
@ -70,6 +75,7 @@ public class BatteryMoveTask : ITask
}
catch (Exception e)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error($" SwapOrderReportCloudTask err e={e}");
}
}
@ -88,4 +94,4 @@ public class BatteryMoveTask : ITask
{
_stop = false;
}
}
}

@ -17,11 +17,33 @@ public class PlcClient : ModbusTcpMaster
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcClient));
private long TaskNo=0;
public BinInfoRepository BinInfoRepository { get; set; }
public EquipAlarmDefineRepository EquipAlarmDefineRepository { get; set; }
public EquipAlarmRecordRepository EquipAlarmRecordRepository { get; set; }
public EquipAlarmProcessRecordRepository EquipAlarmProcessRecordRepository { get; set; }
//修改当前任务
public void ExChangeTaskNo(long taskNo)
{
Interlocked.Exchange(ref TaskNo, taskNo);
}
//重置当前任务
public void ResetTaskNo()
{
Interlocked.Exchange(ref TaskNo, 0);
}
//读取当前任务
public long ReadTaskNo()
{
return Interlocked.Read( ref TaskNo);
}
public PlcClient()
{
ReadAction = BatchRead;
@ -35,6 +57,7 @@ public class PlcClient : ModbusTcpMaster
private void BatchRead(ModbusTcpMaster master)
{
PlcMgr.SendHear();
var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null)
@ -139,14 +162,14 @@ public class PlcClient : ModbusTcpMaster
if (lstAlarm.Count > 0)
{
#region 有报警比较两边差异,新出现的报警就添加,消失的报警就处理并记录
var lstEquipAlarmRecord=EquipAlarmRecordRepository.Query();
var sqllstAlarm=lstEquipAlarmRecord.Select(obj => obj.ErrorCode).ToList();
// 找出实时报警中存在但数据库中不存在的元素
List<string> uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList();
// 找出数据库中存在但实时报警中不存在的元素
// 找出实时报警中存在但数据库中不存在的元素
List<string> uniqueToList1 = lstAlarm.Except(sqllstAlarm).ToList();
// 找出数据库中存在但实时报警中不存在的元素
List<string> uniqueToList2 = sqllstAlarm.Except(lstAlarm).ToList();
if (uniqueToList1.Count > 0)
@ -165,7 +188,7 @@ public class PlcClient : ModbusTcpMaster
ErrorMsg = alarmDefine.ErrorMsg,
ProcessMethod = alarmDefine.ProcessMethod,
StartTime= DateTime.Now
};
};
EquipAlarmRecordRepository.Insert(record);
}
}
@ -173,9 +196,9 @@ public class PlcClient : ModbusTcpMaster
if (uniqueToList2.Count > 0)
{//这些是要清除实时报警,并且处理记录的。
// 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
List<EquipAlarmRecord> filteredObjectList = lstEquipAlarmRecord
.Where(obj => uniqueToList2.Contains(obj.ErrorCode))
// 使用LINQ找出ErrorCode在uniqueToList2中的EquipAlarmRecord对象
List<EquipAlarmRecord> filteredObjectList = lstEquipAlarmRecord
.Where(obj => uniqueToList2.Contains(obj.ErrorCode))
.ToList();
foreach (var VARIABLE in filteredObjectList)
{
@ -193,7 +216,7 @@ public class PlcClient : ModbusTcpMaster
}
EquipAlarmRecordRepository.Delete(filteredObjectList);
}
#endregion
}
else
@ -219,10 +242,10 @@ public class PlcClient : ModbusTcpMaster
}
}
EquipAlarmRecordRepository.Delete(i=>i.Id>0);
#endregion
}
}
@ -245,7 +268,7 @@ public class PlcClient : ModbusTcpMaster
it => it.No == binNo);
}
private void UpdateBinInfoCache(int exists, string binNo)
{
if (exists == 0)
@ -253,7 +276,7 @@ public class PlcClient : ModbusTcpMaster
it =>
new BinInfo(){
Exists = 0,
},
it => it.No == binNo);
else

@ -18,6 +18,8 @@ public class PlcMgr
public static readonly PlcFault PlcFaultData = new PlcFault();
public
/// <summary>
/// 数据有效时间。单位秒
/// </summary>
@ -305,7 +307,7 @@ public class PlcMgr
bool writeCharge6 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus06);
bool writeCharge7 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus07);
bool writeCharge8 = PlcClient.WriteValue(writeHostToPlc.ChargingStatus08);
return write1 && write2 && write3 && write4 && write5 && write6;
}
@ -396,4 +398,4 @@ public class PlcMgr
return bResult;
}
}
}

@ -3,7 +3,7 @@
namespace Service.Plc.Msg
{
/// <summary>
///
///
/// </summary>
public class PlcToHost
{
@ -43,14 +43,14 @@ namespace Service.Plc.Msg
/// </summary>
public ModbusProperty<ushort> RemoteLocalControlState { get; set; } = new(40207);
/// <summary>
/// 灯光状态
/// 灯光状态
/// <para>0无状态</para>
/// <para>1000已全部打开</para>
/// <para>1010已全部关闭</para>
/// </summary>
public ModbusProperty<ushort> LightStatus { get; set; } = new(40208);
/// <summary>
/// 排风扇状态
/// 排风扇状态
/// <para>0无状态</para>
/// <para>1000已全部打开</para>
/// <para>1010已全部关闭</para>
@ -58,7 +58,7 @@ namespace Service.Plc.Msg
public ModbusProperty<ushort> ExhaustFanStatus { get; set; } = new(40209);
/// <summary>
/// 站内积水状态
/// BIT0积水预警
/// BIT0积水预警
/// BIT1积水报警
/// </summary>
public ModbusProperty<ushort> WaterStatusStation { get; set; } = new(40210);
@ -172,7 +172,7 @@ namespace Service.Plc.Msg
/// <para>1020红灯</para>
/// <para>1030红灯闪烁</para>
/// <para>1040黄灯</para>
/// <para>1050黄灯闪烁</para>
/// <para>1050黄灯闪烁</para>移舱任务
/// <para>1100所有灯亮</para>
/// </summary>
public ModbusProperty<ushort> LightOut { get; set; } = new(40406);

@ -27,6 +27,8 @@ public class MonitorService
public ChargeOrderRepository ChargeOrderRepository { get; set; }
public PlcTaskMgr PlcTaskMgr { get; set; }
public MoveBinRecordRepository MoveBinRecordRepository { get; set; }
public Result<SwapMonitorScreenResp> GetSwapMonitorData()
{
var configBinInfo =
@ -145,7 +147,7 @@ public class MonitorService
/// <param name="removeBinNo"></param>
/// <param name="putBinNo"></param>
/// <returns></returns>
public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo,int type=0)
{
//校验:出仓位
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
@ -165,13 +167,22 @@ public class MonitorService
return Result<bool>.Fail("入仓位状态有误");
}
if (PlcMgr.PlcClient?.ReadTaskNo() != 0)
{
Log.Info("当前存在其他任务");
return Result<bool>.Fail("当前存在其他任务");
}
PlcMgr.PlcClient?.ExChangeTaskNo(2);
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2);
if (!result)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Fail();
}
int count = 3;
while (count > 0)
{
@ -187,22 +198,40 @@ public class MonitorService
if (!result)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.ReadTaskStatus(2) =false");
return Result<bool>.Fail();
}
MoveBinRecord moveBinRecord = new MoveBinRecord()
{
UpBinNo = removeBinNo.ToString(),
UpBatteryNo = removeBin.BatteryNo,
UpBatterySoc = removeBin.Soc.ToString(),
InBatteryNo = putBin.BatteryNo,
InBatterySoc = putBin.Soc.ToString(),
InBinNo = putBinNo.ToString(),
Status = 0,
Type = type
};
MoveBinRecordRepository.Insert(moveBinRecord);
result = PlcMgr.HoldOn();
if (!result)
{
{ PlcMgr.PlcClient?.ExChangeTaskNo(0);
Log.Error("BatteryRelocation PlcMgr.HoldOn() =false");
return Result<bool>.Fail();
}
Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} ");
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)
{
PlcMgr.PlcClient?.ExChangeTaskNo(0);
moveBinRecord.Status = 3;
MoveBinRecordRepository.Update(moveBinRecord);
return Result<bool>.Fail();
}
@ -231,8 +260,9 @@ public class MonitorService
removeBin.BatteryEnterSeq = 0;
BinInfoRepository.Update(removeBin);
moveBinRecord.Status = 2;
MoveBinRecordRepository.Update(moveBinRecord);
PlcMgr.PlcClient?.ExChangeTaskNo(0);
return Result<bool>.Success();
}
@ -246,4 +276,4 @@ public class MonitorService
return Result<List<BinInfoResp>>.Success(mapperBinInfo.Map<List<BinInfoResp>>(queryListByClause));
}
}
}

@ -28,7 +28,7 @@ public class ChargeMonitorController
_binInfoService = binInfoService;
_monitorService = monitorService;
}
/// <summary>
/// 仓位预约
/// </summary>
@ -49,7 +49,7 @@ public class ChargeMonitorController
else
return Result<bool>.Fail(result);
}
/// <summary>
/// 修改仓位电池编码
/// </summary>
@ -76,8 +76,8 @@ public class ChargeMonitorController
else
return Result<bool>.Fail(result);
}
/// <summary>
/// 充电仓查询:条件:仓位编号 仓位名称
/// </summary>
@ -119,7 +119,7 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")]
public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{
return _monitorService.BatteryRelocation(removeBinNo, putBinNo);
return _monitorService.BatteryRelocation(removeBinNo, putBinNo,1);
}
/// <summary>
@ -130,4 +130,4 @@ public class ChargeMonitorController
{
return _monitorService.GetChargeBinOption();
}
}
}

Loading…
Cancel
Save