新增给plc下发红绿灯

master
zby 3 months ago
parent 4942e09aba
commit 0a61c7d888

@ -84,6 +84,25 @@ public class PlcClient : TcpClient<IBaseHandler, Decoder, Encoder>
}
/// <summary>
/// 发送红绿灯
/// </summary>
/// <param name="trafficLight">出库方式</param>
public Result<bool> SendTrafficLightReq(byte trafficLight)
{
if (!Connected)
{
return Result<bool>.Fail($"Plc{Sn}未连接");
}
TrafficLightReq req = new TrafficLightReq(trafficLight)
{
TrafficLight = trafficLight,
};
this.Channel.WriteAndFlushAsync(req);
return Result<bool>.Success();
}
/// <summary>
/// 发送开始换电命令
/// </summary>

@ -196,6 +196,8 @@ public class Decoder : ByteToMessageDecoder
117 => ModelConvert.Decode<PowerTransferCompletedReq>(bytes),
/*0x*/
94 => ModelConvert.Decode<MoveCommandResq>(bytes),
119=> ModelConvert.Decode < TrafficLightResq>(bytes),
_ => new ASDU()
};

@ -0,0 +1,35 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Utils;
using log4net;
using Newtonsoft.Json;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
namespace Service.Charger.Handler;
/// <summary>
/// 红绿灯命令回复 处理器
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class TrafficLightResqHandler : SimpleChannelInboundHandler<TrafficLightResq>, IBaseHandler
{
/// <summary>
///
/// </summary>
private static readonly ILog Log = LogManager.GetLogger(typeof(TrafficLightResqHandler));
/// <summary>
///
/// </summary>
protected override void ChannelRead0(IChannelHandlerContext ctx, TrafficLightResq msg)
{
Log.Info("TrafficLightResq Order Reply");
}
}

@ -0,0 +1,27 @@
using System;
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Host.Req;
/// <summary>
/// 红绿灯命令
/// </summary>
public class TrafficLightReq: ASDU {
/// <summary>
/// 红绿灯 0x00-红灯, 0x01-绿灯
/// </summary>
[Property(0, 8 )]
public byte TrafficLight { get;set;}
public TrafficLightReq(byte trafficLight)
{
FrameTypeNo = 118;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
TrafficLight = trafficLight;
}
}

@ -0,0 +1,17 @@
using System;
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Charger.Resp;
/// <summary>
/// 红绿灯命令回复
/// </summary>
public class TrafficLightResq : ASDU
{
/// <summary>
/// 应答结果
/// </summary>
[Property(0, 8 )]
public byte AnswerResult {get;set;}
}

@ -120,6 +120,23 @@ public class PlcController : ControllerBase
return Result<bool>.Fail("充电机未连接");
}
/// <summary>
/// 发送红绿灯命令
/// </summary>
/// <param name="sn">充电机编号</param>
/// <param name="msg">消息</param>
[HttpGet]
[Route("SendTrafficLightReq/{trafficLight}")]
public Result<bool> SendTrafficLightReq(byte trafficLight)
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)
{
return chargerClient.SendTrafficLightReq(trafficLight);
}
return Result<bool>.Fail("充电机未连接");
}
/// <summary>
/// 发送继续命令
/// </summary>
@ -144,7 +161,7 @@ public class PlcController : ControllerBase
/// <param name="msg">消息</param>
[HttpGet]
[Route("SendPauseCommandReq")]
public Result<bool> SendPauseCommandReq( )
public Result<bool> SendPauseCommandReq()
{
Service.Charger.Server.PlcClient? chargerClient = ClientMgr.PlcClient;
if (chargerClient != null)

Loading…
Cancel
Save