电池自动移仓任务,tbox多次的读,plcreset

zw
lxw 6 months ago
parent 5eaae41b80
commit 3322b2867c

@ -121,6 +121,11 @@ public class ModbusTcpMaster
GetLog().Info("stop listen");
}
public void Reset()
{
ReadAction(this);
}
public byte[]? ReadRegister(int registerNo, int start, int length)
{
start = start % 16 == 0 ? start / 16 : start / 16 + 1;
@ -207,7 +212,6 @@ public class ModbusTcpMaster
{
return ModbusTcpNet.Write(address, value);
}
public bool WriteValue<T>(ModbusProperty<T> property)
@ -255,7 +259,7 @@ public class ModbusTcpMaster
else
{
var preWriteCont = BitUtls.ProcessEnding(setValue, ByteSeq, WordSeq);
operateResult = ModbusTcpNet.Write("x=16;" + registerNo, preWriteCont);
result = operateResult.IsSuccess;
}

@ -0,0 +1,75 @@
using Autofac;
using Entity.Constant;
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Entity;
using log4net;
using Repository.Station;
using Service.Execute;
using Service.Execute.Api;
using Service.Execute.Model;
using Service.Plc.Client;
using Service.Station;
namespace Service.BusinessTask.MyTask;
/// <summary>
/// 电池移仓任务
/// </summary>
public class BatteryMoveTask : AbstractTaskHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(BatteryMoveTask));
private readonly BinInfoRepository _binInfoRepository =
AppInfo.Container.Resolve<BinInfoRepository>();
private readonly MonitorService _monitorService =
AppInfo.Container.Resolve<MonitorService>();
protected override int Interval()
{
return 20 * 1000;
}
/// <summary>
/// 自动移仓 当缓存仓没有电池的时候 如果有电池充满了 就移仓
/// </summary>
protected override void Handle()
{
var cacheBin = _binInfoRepository.QueryByClause(i => i.CacheBinFlag == 1);
if (cacheBin.Exists == 1)
{
return;
}
BinInfo? binInfo = _binInfoRepository.QueryListByClause(i => i.ChargeStatus == 4, "battery_enter_seq asc")
.First();
if (binInfo == null)
{
return;
}
Result<bool> success = _monitorService.BatteryRelocation(ushort.Parse(binInfo.No), ushort.Parse(cacheBin.No));
//查询人物状态
if (success.IsSuccess)
{
bool readPlcTaskStatus9000 = false;
while (!readPlcTaskStatus9000)
{
Thread.Sleep(1000);
readPlcTaskStatus9000 = PlcMgr.ReadPlcTaskStatus() == 9000;
}
Log.Info($"execute BatteryMoveTask success from binNo ={binInfo.No}");
}
}
protected override string Name()
{
return "SwapOrderReportCloudTask";
}
}

@ -17,11 +17,12 @@ public class PlcApi
/// PLC是否连接
/// </summary>
public static bool con;
/// <summary>
/// 数据有效时间。单位秒
/// </summary>
static int DataTimeSeconds = 2;
/// <summary>
/// 数据刷新时间
/// </summary>
@ -41,6 +42,7 @@ public class PlcApi
{
return PlcMgr.IsAuto();
}
/// <summary>
/// 入口雷达检测
/// </summary>
@ -101,10 +103,10 @@ public class PlcApi
/// <returns></returns>
public static bool StartSwapping(string inBinNo, string outBinNo)
{
return PlcMgr.DistributeTask(ushort.Parse(inBinNo),ushort.Parse(outBinNo),1);
return PlcMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo), 1);
}
/// <summary>
/// 读取任务状态
/// </summary>
@ -129,9 +131,10 @@ public class PlcApi
/// <returns></returns>
public static ushort ChannelStatus()
{
PlcMgr.ResetPlc();
var channelStatus = PlcMgr.ChannelStatus();
Log.Info($"plc ChannelStatus = {channelStatus}");
return channelStatus;
return channelStatus;
}
@ -143,5 +146,4 @@ public class PlcApi
{
return PlcMgr.ReadPlcTaskStatus();
}
}

@ -12,6 +12,8 @@ public class TBoxApi
//TODO::TBox 服务地址
private static readonly string BASE_URL = "http://localhost:5036";
private static int _times = 5;
private static int _successTimes = 3;
private static readonly HttpClient _httpClient = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(60)
@ -81,6 +83,35 @@ public class TBoxApi
}
}
public static async Task<bool> UnLockCarManyTimes(string carNo)
{
List<bool> bools = new List<bool>();
for (int i = 0; i < _times; i++)
{
Thread.Sleep(100);
var unLockCar = await UnLockCar(carNo);
bools.Add(unLockCar);
}
return bools.Select(i => i).Count() > _successTimes;
}
public static async Task<bool> LockCarManyTimes(string carNo)
{
List<bool> bools = new List<bool>();
for (int i = 0; i < _times; i++)
{
Thread.Sleep(100);
var unLockCar = await LockCar(carNo);
bools.Add(unLockCar);
}
return bools.Select(i => i).Count() > _successTimes;
}
/// <summary>
/// 车辆解锁
/// </summary>

@ -225,6 +225,9 @@ public class CommonMgr
inBinInfo.Soc = -1;
inBinInfo.Soe = -1;
inBinInfo.BatteryNo = "-1";
//修改入仓顺序
BinInfo binInfo = _binInfoRepository.QueryListByClause(i=>i.BatteryEnterSeq!=null,"battery_enter_seq desc").First();
inBinInfo.BatteryEnterSeq = binInfo.BatteryEnterSeq + 1;
_binInfoRepository.Update(inBinInfo);
var upBinInfo = machineSwapOrderBatteryInfo.UpBinInfo;
@ -233,6 +236,8 @@ public class CommonMgr
upBinInfo.BatteryNo = "-1";
_binInfoRepository.Update(upBinInfo);
}
}

@ -13,6 +13,8 @@ namespace Service.Execute
private static readonly AbstractTaskHandler SwapOrderReportCloudTask = new SwapOrderReportCloudTask();
private static readonly AbstractTaskHandler BatteryMoveTask = new BatteryMoveTask();
#region Task
@ -22,6 +24,7 @@ namespace Service.Execute
public static void StartTasks()
{
SwapOrderReportCloudTask.Start();
BatteryMoveTask.Start();
}
/// <summary>

@ -50,7 +50,7 @@ public class CarCtrlState : IState
return Invoker.Invoke("UnLockCar", 500, 100, machine.IsCanceled,
() => machine.VelUnlockFlag, () =>
{
Task<bool> result = TBoxApi.UnLockCar(machine.RfidReadModel.VelNo);
Task<bool> result = TBoxApi.UnLockCarManyTimes(machine.RfidReadModel.VelNo);
bool unLock = result.Result;
if (unLock)
{

@ -115,7 +115,7 @@ public class DoSwappingState : IState
return Invoker.Invoke("UnLockCar", 1000, 5, machine.IsCanceled,
() => machine.StartSwappingFlag, () =>
{
Task<bool> result = TBoxApi.UnLockCar(machine.RfidReadModel.VelNo);
Task<bool> result = TBoxApi.UnLockCarManyTimes(machine.RfidReadModel.VelNo);
bool unLock = result.Result;
if (unLock)
{
@ -357,7 +357,7 @@ public class DoSwappingState : IState
else if (channelStatus == 1020)
{
//需要移车 先解锁 提示移动车辆,等待3分钟
var lockCar = TBoxApi.LockCar(machine.RfidReadModel.VelNo);
var lockCar = TBoxApi.LockCarManyTimes(machine.RfidReadModel.VelNo);
if (lockCar.Result)
{
// machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrChannelStatus.GetLed());

@ -76,7 +76,7 @@ public class SwapDoneState : IState
return Invoker.Invoke("LockCar", 500, 100, machine.IsCanceled,
() => machine.VelLockFlag, () =>
{
Task<bool> result = TBoxApi.LockCar(machine.RfidReadModel.VelNo);
Task<bool> result = TBoxApi.LockCarManyTimes(machine.RfidReadModel.VelNo);
bool unLock = result.Result;
if (unLock)
{

@ -20,7 +20,7 @@ public class PlcClient : ModbusTcpMaster
ReadAction = BatchRead;
Ip = "172.0.20.66";
Port = 502;
Duration = 2000;
Duration = 1000;
AutoReConnect = true;
_binInfoRepository = binInfoRepository;
//DataFormat = HslCommunication.Core.DataFormat.DCBA;

@ -280,6 +280,14 @@ public class PlcMgr
return 0;
}
/// <summary>
/// 重新读
/// </summary>
public static void ResetPlc()
{
PlcClient.Reset();
}
/// <summary>
/// 读plc任务状态

@ -115,10 +115,13 @@ public class MonitorService
{
SwapAndChargingCountResp chargingCountResp = new()
{
ChargeTodayCount = ChargeOrderRepository.GetCount(i => DateTime.Today<=i.EndTime && i.EndTime<= DateUtils.GetTomorrowFirst()),
ChargeTodayCount = ChargeOrderRepository.GetCount(i =>
DateTime.Today <= i.EndTime && i.EndTime <= DateUtils.GetTomorrowFirst()),
ChargeTotalCount = ChargeOrderRepository.GetCount(i => i.EndTime != null),
SwapTodayCount =
SwapOrderRepository.GetCount(i => i.SwapResult != 0 && DateTime.Today<=i.SwapEndTime && i.SwapEndTime<= DateUtils.GetTomorrowFirst()),
SwapOrderRepository.GetCount(i =>
i.SwapResult != 0 && DateTime.Today <= i.SwapEndTime &&
i.SwapEndTime <= DateUtils.GetTomorrowFirst()),
SwapTotalCount = SwapOrderRepository.GetCount(i => i.SwapResult != 0),
};
@ -135,7 +138,8 @@ public class MonitorService
{
//校验:出仓位
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(removeBinNo) && (i.ChargeStatus == 2 || i.ChargeStatus==4) && i.Exists == 1 && i.AmtLock == 0);
i.No.Equals(removeBinNo) && (i.ChargeStatus == 2 || i.ChargeStatus == 4) && i.Exists == 1 &&
i.AmtLock == 0);
if (removeBin == null)
{
@ -143,18 +147,27 @@ public class MonitorService
}
BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(putBinNo) && (i.ChargeStatus == 2 || i.ChargeStatus==4) && i.Exists == 0 && i.AmtLock == 0 && i.Status == 1);
i.No.Equals(putBinNo) && (i.ChargeStatus == 2 || i.ChargeStatus == 4) && i.Exists == 0 && i.AmtLock == 0 &&
i.Status == 1);
if (putBin == null)
{
return Result<bool>.Fail("入仓位状态有误");
}
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2) ? Result<bool>.Success() : Result<bool>.Fail();
if (!result.IsSuccess)
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2);
if (!result)
{
return Result<bool>.Fail();
}
bool taskSuccess = false;
if (!taskSuccess)
{
taskSuccess=PlcMgr.ReadTaskStatus(2);
PlcMgr.DistributeTask(putBinNo, removeBinNo, 2);
}
var succ = PlcMgr.HoldOn();
if (!succ)

Loading…
Cancel
Save