重写tcp server的session管理

master
rszn 6 months ago
parent 3dc9ed6aaf
commit 28086f6c23

@ -1,29 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using HybirdFrameworkDriver.TcpClient;
using Service.Charger.Codec;
using Service.Charger.Handler;
namespace Service.Charger.Client;
/// <summary>
/// 示例程序
/// </summary>
[Scope("InstancePerDependency")]
public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
{
public void SessionAttr(int sn, int fEqmTypeNo, string eqmCode, string destAddr)
{
var ioSession = SessionMgr.GetSession(Channel.Id.ToString());
if (ioSession == null)
{
ioSession = new IoSession(Channel);
SessionMgr.RegisterSession(Channel, ioSession);
}
SessionMgr.SetAttr(ioSession, "charger_sn", sn);
SessionMgr.SetAttr(ioSession, "eqm_type_no", fEqmTypeNo);
SessionMgr.SetAttr(ioSession, "eqm_code", eqmCode);
SessionMgr.SetAttr(ioSession, "dest_addr", destAddr);
}
}

@ -1,14 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.TcpServer;
using Service.Charger.Codec;
using Service.Charger.Handler;
namespace Service.Charger.Client;
/// <summary>
/// 示例程序
/// </summary>
[Scope("InstancePerDependency")]
public class ChargerServer : TcpServer<IBaseHandler, Decoder, Encoder>
{
}

@ -1,29 +0,0 @@
using System.Text;
using Autofac;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using Service.Charger.Msg.Host.Req;
namespace Service.Charger.Client;
/// <summary>
/// 示例程序
/// </summary>
[Scope("SingleInstance")]
public class ClientMgr
{
public void InitClient()
{
var auth = new Auth(1, Encoding.UTF8.GetBytes("ddddddddd"), 1);
auth.DestAddr = new byte[] { 0x01, 0x02, 0x03 };
var chargerClient2 = AppInfo.Container.Resolve<ChargerClient>();
chargerClient2.InitBootstrap("127.0.0.1", 9998);
chargerClient2.BaseConnect();
chargerClient2.SessionAttr(12, 12, "12", "2");
chargerClient2.Channel.WriteAndFlushAsync(auth);
var chargerServer = AppInfo.Container.Resolve<ChargerServer>();
chargerServer.Start(9000);
}
}

@ -1,14 +0,0 @@
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using Service.Charger.Msg.Charger.Req;
namespace Service.Charger.Codec;
public class Decoder : ByteToMessageDecoder
{
protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
{
output.Add(new Login());
}
}

@ -1,14 +0,0 @@
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Transport.Channels;
using HybirdFrameworkDriver.Common;
namespace Service.Charger.Codec;
public class Encoder : MessageToByteEncoder<IToBytes>
{
protected override void Encode(IChannelHandlerContext context, IToBytes obj, IByteBuffer output)
{
output.WriteBytes(obj.ToBytes());
}
}

@ -1,6 +0,0 @@
namespace Service.Charger.Common;
public class ChargerConst
{
public static readonly byte[] ApciStartChar = { 0x68 /* ,0xEE*/ };
}

@ -1,28 +0,0 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using log4net;
using Service.Charger.Msg.Charger.Resp;
namespace Service.Charger.Handler;
/// <summary>
/// 接收到鉴权帧
/// <code>
/// 1保存日志到log
/// 2从SessionMgr中取目的地址解析后写入ChargerManager
/// 3保存鉴权状态和充电状态
/// </code>
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class AuthResHandler : SimpleChannelInboundHandler<AuthRes>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(AuthResHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, AuthRes msg)
{
var sn = (int)SessionMgr.GetAttrByKey(ctx.Channel.Id.ToString(), "charger_sn");
Log.Info($"receive {msg} from {sn}");
}
}

@ -1,7 +0,0 @@
using DotNetty.Transport.Channels;
namespace Service.Charger.Handler;
public interface IBaseHandler : IChannelHandler
{
}

@ -1,41 +0,0 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.Session;
using log4net;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Host.Resp;
namespace Service.Charger.Handler;
/// <summary>
/// 3.3.3 充放电机登陆签到
/// 监控平台应答充电设备登录签到报文
/// <code>
/// 1保存日志到log
/// 2回复签到应答
/// 3保存签到应答日志
/// </code>
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class LoginHandler : SimpleChannelInboundHandler<Login>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(LoginHandler));
protected override void ChannelRead0(IChannelHandlerContext ctx, Login msg)
{
msg.ConnProtocolVersion = msg.ConnProtocolVersion0 + "." + msg.ConnProtocolVersion1 + "." +
msg.ConnProtocolVersion2;
msg.ControllerHardwareVersion = msg.ControllerHardwareVersion0 + "." + msg.ControllerHardwareVersion1 +
"." + msg.ControllerHardwareVersion2;
msg.ControllerSoftwareVersion = msg.ControllerSoftwareVersion0 + "." + msg.ControllerSoftwareVersion1 +
"." + msg.ControllerSoftwareVersion2;
var sn = (int)SessionMgr.GetAttrByKey(ctx.Channel.Id.ToString(), "charger_sn");
Log.Info($"receive {msg} from {sn}");
var logSignMessage = new LogSignMessage(0);
logSignMessage.DestAddr = new byte[] { 0x01, 0x02, 0x03 };
ctx.Channel.WriteAndFlushAsync(logSignMessage);
}
}

@ -1,45 +0,0 @@
using HybirdFrameworkDriver.Common;
using Service.Charger.Common;
namespace Service.Charger.Msg;
public abstract class APCI : IToBytes
{
/// <summary>
/// 报文长度
/// </summary>
public ushort PackLen { get; set; }
/// <summary>
/// 控制域
/// </summary>
public uint CtlArea { get; set; }
/// <summary>
/// 目标地址
/// </summary>
public byte[] DestAddr { get; set; }
/// <summary>
/// 源地址
/// </summary>
public uint SrcAddr { get; set; }
public byte[] ToBytes()
{
var bodyBytes = GetBytes();
var list = new List<byte>();
list.AddRange(ChargerConst.ApciStartChar);
list.AddRange(BitConverter.GetBytes(bodyBytes.Length + 12));
list.AddRange(BitConverter.GetBytes(CtlArea));
list.AddRange(DestAddr);
list.AddRange(BitConverter.GetBytes(SrcAddr));
list.AddRange(bodyBytes);
return list.ToArray();
}
public abstract byte[] GetBytes();
}

@ -1,74 +0,0 @@
using DotNetty.Buffers;
using HybirdFrameworkCore.Utils;
using Service.Charger.Common;
namespace Service.Charger.Msg;
public class ASDU : APCI
{
/// <summary>
/// 帧类型号
/// </summary>
public byte FrameTypeNo { get; set; }
/// <summary>
/// 信息体个数
/// </summary>
public byte MsgBodyCount { get; set; }
/// <summary>
/// 传送原因-3.1.3.2
/// </summary>
public ushort TransReason { get; set; }
/// <summary>
/// 公共地址
/// </summary>
public ushort PublicAddr { get; set; }
/// <summary>
/// 信息体地址-3个字节
/// </summary>
public byte[]? MsgBodyAddr { get; set; }
public override byte[] GetBytes()
{
var list = new List<byte>();
list.Add(FrameTypeNo);
list.Add(MsgBodyCount);
list.AddRange(BitConverter.GetBytes(TransReason));
list.AddRange(BitConverter.GetBytes(PublicAddr));
list.AddRange(MsgBodyAddr);
list.AddRange(ModelConvert.Encode(this));
return list.ToArray();
}
public static void ParseHeader(IByteBuffer byteBuffer, ASDU asdu)
{
var start = ChargerConst.ApciStartChar.Length - 1;
asdu.PackLen = byteBuffer.GetUnsignedShortLE(start + 1);
asdu.CtlArea = byteBuffer.GetUnsignedInt(start + 3);
asdu.DestAddr = new[]
{
byteBuffer.GetByte(start + 7),
byteBuffer.GetByte(start + 8),
byteBuffer.GetByte(start + 9),
byteBuffer.GetByte(start + 10)
};
asdu.SrcAddr = byteBuffer.GetUnsignedInt(start + 11);
asdu.FrameTypeNo = byteBuffer.GetByte(start + 15);
asdu.MsgBodyCount = byteBuffer.GetByte(start + 16);
asdu.TransReason = byteBuffer.GetUnsignedShortLE(start + 17);
asdu.PublicAddr = byteBuffer.GetUnsignedShortLE(start + 19);
asdu.MsgBodyAddr = new[]
{
byteBuffer.GetByte(start + 21),
byteBuffer.GetByte(start + 22),
byteBuffer.GetByte(start + 23)
};
}
}

@ -1,93 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Charger.Req;
/// <summary>
/// 3.3.3 充放电机登陆签到
/// </summary>
public class Login : ASDU
{
/// <summary>
/// 记录类型
/// </summary>
[Property(0, 8)]
public byte RecordType { get; set; }
/// <summary>
/// 监控网关编号
/// </summary>
[Property(8, 16)]
public ushort GatewayNo { get; set; }
/// <summary>
/// 设备属性
/// </summary>
[Property(24, 8)]
public byte EquipType { get; set; }
/// <summary>
/// 通讯协议版本
/// </summary>
[Property(32, 8)]
public byte ConnProtocolVersion0 { get; set; }
[Property(40, 8)] public byte ConnProtocolVersion1 { get; set; }
[Property(48, 8)] public byte ConnProtocolVersion2 { get; set; }
public string ConnProtocolVersion { get; set; }
/// <summary>
/// 充电控制器硬件版本号
/// </summary>
[Property(56, 8)]
public byte ControllerHardwareVersion0 { get; set; }
[Property(64, 8)] public byte ControllerHardwareVersion1 { get; set; }
[Property(72, 8)] public byte ControllerHardwareVersion2 { get; set; }
public string ControllerHardwareVersion { get; set; }
/// <summary>
/// 充电控制器软件版本
/// </summary>
[Property(80, 8)]
public byte ControllerSoftwareVersion0 { get; set; }
[Property(88, 8)] public byte ControllerSoftwareVersion1 { get; set; }
[Property(96, 8)] public byte ControllerSoftwareVersion2 { get; set; }
public string ControllerSoftwareVersion { get; set; }
/// <summary>
/// 充电枪口数目
/// </summary>
[Property(104, 8)]
public byte GunNum { get; set; }
/// <summary>
/// 充电模块数目
/// </summary>
[Property(112, 8)]
public byte GunModuleNum { get; set; }
/// <summary>
/// 额定功率
/// </summary>
[Property(128, 16)]
public ushort RatedPower { get; set; }
/// <summary>
/// 当前功率
/// </summary>
[Property(136, 8)]
public byte CurrentPower { get; set; }
/// <summary>
/// 当前速率
/// </summary>
[Property(144, 8)]
public byte CurrentSpeed { get; set; }
/// <summary>
/// 分流器量程
/// </summary>
[Property(152, 16)]
public ushort DiverterRange { get; set; }
}

@ -1,34 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Charger.Resp;
/// <summary>
/// 3.3.2 充放电机应答鉴权认证
/// </summary>
public class AuthRes : ASDU
{
/// <summary>
/// 记录类型
/// </summary>
[Property(0, 8)]
public byte RecordType { get; set; }
/// <summary>
/// 连接序号
/// </summary>
[Property(8, 16)]
public ushort ConnSeq { get; set; }
/// <summary>
/// 鉴权结果
/// </summary>
[Property(24, 8)]
public byte AuthResult { get; set; }
/// <summary>
/// 失败原因
/// </summary>
[Property(32, 8)]
public byte FailReason { get; set; }
}

@ -1,57 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Host.Req;
/// <summary>
/// 3.3.1 监控平台鉴权认证
/// </summary>
public class Auth : ASDU
{
public Auth(ushort connseq, byte[] authcodes, byte authcodekey)
{
PackLen = 0;
CtlArea = 0;
SrcAddr = 0;
FrameTypeNo = 45;
MsgBodyCount = 1;
TransReason = 3;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
RecordType = 24;
ClientType = 1;
ConnSeq = connseq;
AuthCodes = authcodes;
AuthCodeKey = authcodekey;
}
/// <summary>
/// 记录类型
/// </summary>
public byte RecordType { get; set; }
/// <summary>
/// 客户端类型.1站控 2本地控制器 3测试客户端 4TCU模式 0未知设备
/// </summary>
[Property(0, 8)]
public byte ClientType { get; set; }
/// <summary>
/// 连接序号
/// </summary>
[Property(8, 16)]
public ushort ConnSeq { get; set; }
/// <summary>
/// 鉴权码字节数组
/// </summary>
[Property(24, 64)]
public byte[] AuthCodes { get; set; }
/// <summary>
/// 鉴码KEY
/// </summary>
[Property(88, 8)]
public byte AuthCodeKey { get; set; }
}

@ -1,88 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
namespace Service.Charger.Msg.Host.Resp;
/// <summary>
/// 3.3.4 监控平台应答充电设备登录签到报文
/// </summary>
public class LogSignMessage : ASDU
{
public LogSignMessage(byte result)
{
Result = result;
CtlArea = 0;
SrcAddr = 0;
FrameTypeNo = 45;
MsgBodyCount = 1;
TransReason = 4;
PublicAddr = 0;
MsgBodyAddr = new byte[] { 0, 0, 0 };
RecordType = 12;
var dtime = DateTime.Now;
TimeYear = Convert.ToUInt16(dtime.Year.ToString());
TimeMonth = Convert.ToByte(dtime.Month);
TimeDay = Convert.ToByte(dtime.Day);
TimeHour = Convert.ToByte(dtime.Hour);
TimeMinute = Convert.ToByte(dtime.Minute);
TimeSecond = Convert.ToByte(dtime.Second);
}
[Property(0, 8)] public byte RecordType { get; set; }
/// <summary>
/// 结果
/// 0:成功/确认
/// 1:失败-平台处理该消息失败
/// 2:消息有误-消息校验错误/消息长度有误
/// 4:该设备编码在系统没有找到
/// 5:该设备编码在系统中异常,可能存在冲突
/// 6:充电控制器数目不对
/// 255:其它错误
/// </summary>
[Property(8, 8)]
public byte Result { get; set; }
/// <summary>
/// 年
/// </summary>
[Property(16, 16)]
public ushort TimeYear { get; set; }
/// <summary>
/// 月
/// </summary>
[Property(32, 8)]
public byte TimeMonth { get; set; }
/// <summary>
/// 日
/// </summary>
[Property(40, 8)]
public byte TimeDay { get; set; }
/// <summary>
/// 时
/// </summary>
[Property(48, 8)]
public byte TimeHour { get; set; }
/// <summary>
/// 分
/// </summary>
[Property(56, 8)]
public byte TimeMinute { get; set; }
/// <summary>
/// 秒
/// </summary>
[Property(64, 8)]
public byte TimeSecond { get; set; }
/// <summary>
/// 保留:1位, 默认0xFF
/// </summary>
[Property(72, 8)]
public byte Time { get; set; }
}

@ -1,9 +1,4 @@
using HybirdFrameworkDriver.ModbusTcpMaster;
using log4net;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Service.Cloud.Msg.Cloud.Req;
using Service.Init.Entity;
using Service.Plc;
using Service.Plc.Client;
namespace Service.Execute.Api;
@ -13,14 +8,14 @@ public class PlcApi
private const int TimeSpan = 60;
private static readonly ILog Log = LogManager.GetLogger("PlcApi");
/// <summary>
/// 数据有效时间。单位秒
/// </summary>
static int DataTimeSeconds = 2;
/// <summary>
@ -29,7 +24,7 @@ public class PlcApi
/// <returns></returns>
public static bool IsRemote()
{
var isRemote = PlcMgr.IsRemote();
Log.Info($"PlcApi IsRemove resp={isRemote}");
return isRemote;
@ -110,10 +105,10 @@ public class PlcApi
/// <returns></returns>
public static bool StartSwapping(string inBinNo, string outBinNo)
{
Log.Info($"PlcApi StartSwapping param= inBinNo={inBinNo}, outBinNo={outBinNo}");
var distributeTask = PlcMgr.DistributeTask(ushort.Parse(inBinNo), ushort.Parse(outBinNo), 1);
Log.Info($"PlcApi StartSwapping resp={distributeTask}");
return distributeTask;
}
@ -166,4 +161,5 @@ public class PlcApi
Log.Info($"PlcApi ReadPlcTaskStatus resp= {readPlcTaskStatus}");
return readPlcTaskStatus;
}
}
}

@ -1,12 +0,0 @@
namespace Service.Init.Entity
{
/// <summary>
///PLC连接状态枚举
/// </summary>
public enum ConnectState
{
Disconnect = 0,
Connecting = 1,
Connected = 2
}
}

@ -1,459 +0,0 @@
using HybirdFrameworkDriver.ModbusTcpMaster;
using HybirdFrameworkDriver.Session;
using Service.Plc.Msg;
namespace Service.Init.Entity
{
public class PlcInfo
{
#region 字段
/// <summary>
/// 设备编号
/// </summary>
private string _devNo = "001";
/// <summary>
/// 设备名称
/// </summary>
private string _devname = "换电PLC";
/// <summary>
/// 服务端连接IP
/// </summary>
private string _ipaddr = "172.0.20.48";
/// <summary>
/// 服务端连接端口
/// </summary>
private int _port = 502;
/// <summary>
/// 站号
/// </summary>
private byte _site = 0x01;
/// <summary>
/// 连接超时时间。单位秒
/// </summary>
private int _connecttimeout = 10;
/// <summary>
/// 保持活跃时间。单位秒
/// </summary>
private int _keepalive = 30;
/// <summary>
/// 连接状态
/// </summary>
private ConnectState _connect_state = ConnectState.Disconnect;
#endregion 字段
public string ChannelId;
public int EqmSn;
public HostToPlc hostToPlc = new HostToPlc();
public PlcToHost plcToHost = new PlcToHost();
public PlcFault plcFault = new PlcFault();
#region
int DataTimeSeconds = 2;
DateTime DataValidityTime = DateTime.Now;
/// <summary>
/// plc是否连接
/// </summary>
public bool Connected { get; set; }
/// <summary>
/// plc是否处于远程模式
/// </summary>
public bool RemoteNot
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= DataTimeSeconds)
{
return RemoteNot;
}
else
{
return false;
}
}
set
{
RemoteNot = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读入口雷达是否感应触发
/// </summary>
public bool EntranceRadar
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return EntranceRadar;
}
else
{
return false;
}
}
set
{
EntranceRadar = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读取通道定位状态(拍照是否OK)
/// </summary>
public bool ChannelLocationState
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return ChannelLocationState;
}
else
{
return false;
}
}
set
{
ChannelLocationState = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读取plc任务状态电池拆卸中
/// </summary>
public bool BatteryDisassembly
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return BatteryDisassembly;
}
else
{
return false;
}
}
set
{
BatteryDisassembly = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读取plc任务状态电池入库搬运中
/// </summary>
public bool StorageBatteries
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return StorageBatteries;
}
else
{
return false;
}
}
set
{
StorageBatteries = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读取plc任务状态电池出库搬运中
/// </summary>
public bool BatteryDelivery
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return BatteryDelivery;
}
else
{
return false;
}
}
set
{
BatteryDelivery = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读取plc任务状态电池安装中
/// </summary>
public bool BatteryInstallation
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return BatteryInstallation;
}
else
{
return false;
}
}
set
{
BatteryInstallation = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读取plc任务状态电池安装完成
/// </summary>
public bool BatteryInstallationComplete
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return BatteryInstallationComplete;
}
else
{
return false;
}
}
set
{
BatteryInstallationComplete = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 设置出口灯:绿灯(通知车辆可以驶离)
/// </summary>
public bool SetExitLightGreen
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return SetExitLightGreen;
}
else
{
return false;
}
}
set
{
SetExitLightGreen = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 读出口雷达是否感应触发
/// </summary>
public bool ExitRadarSensingTrigger
{
get
{
if ((DateTime.Now - DataValidityTime).Seconds <= 2)
{
return ExitRadarSensingTrigger;
}
else
{
return false;
}
}
set
{
ExitRadarSensingTrigger = value;
DataValidityTime = DateTime.Now;
}
}
/// <summary>
/// 写入口灯绿
/// </summary>
/// <returns></returns>
public bool SendLightGreen()
{
bool bResult = false;
if (Connected)
{
hostToPlc.LightIn.Value = 1000;
bResult = WriteUint16(hostToPlc.LightIn);
}
return bResult;
}
/// <summary>
/// 下发选包数据给plc(入仓位
/// </summary>
/// <param name="loc">1:缓存位舱位号 2-20 电池存储舱位</param>
/// <returns></returns>
public bool SendSelectRuleIn(ushort loc)
{
bool bResult = false;
if (Connected)
{
hostToPlc.EntrySelection.Value = loc;
bResult = WriteUint16(hostToPlc.EntrySelection);
}
return bResult;
}
/// <summary>
/// 下发选包数据给plc(出仓位
/// </summary>
/// <param name="loc">1:缓存位舱位号 2-20 电池存储舱位</param>
/// <returns></returns>
public bool SendSelectRuleOut(ushort loc)
{
bool bResult = false;
if (Connected)
{
hostToPlc.ExitSelection.Value = loc;
bResult = WriteUint16(hostToPlc.ExitSelection);
}
return bResult;
}
/// <summary>
/// 写入口灯:红灯
/// </summary>
/// <returns></returns>
public bool SendLightRed()
{
bool bResult = false;
if (Connected)
{
hostToPlc.LightIn.Value = 1020;
bResult = WriteUint16(hostToPlc.LightIn);
}
return bResult;
}
/// <summary>
/// 下发plc开启换电任务
/// </summary>
/// <returns></returns>
public bool SendTaskType()
{
bool bResult = false;
if (Connected)
{
hostToPlc.TaskType.Value = 1;
bResult = WriteUint16(hostToPlc.TaskType);
}
return bResult;
}
/// <summary>
/// 设置出口灯:绿灯
/// </summary>
/// <returns></returns>
public bool SendLightOutGreen()
{
bool bResult = false;
if (Connected)
{
hostToPlc.LightOut.Value = 1000;
bResult = WriteUint16(hostToPlc.LightOut);
}
return bResult;
}
/// <summary>
/// 设置出口灯:红灯
/// </summary>
/// <returns></returns>
public bool SendLightOutRed()
{
bool bResult = false;
if (Connected)
{
hostToPlc.LightOut.Value = 1020;
bResult = WriteUint16(hostToPlc.LightOut);
}
return bResult;
}
#endregion
#region 有料检测
/// <summary>
/// 有料检测 1-20仓
/// </summary>
public byte MaterialDetec01 { get; set; }
public byte MaterialDetec02 { get; set; }
public byte MaterialDetec03 { get; set; }
public byte MaterialDetec04 { get; set; }
public byte MaterialDetec05 { get; set; }
public byte MaterialDetec06 { get; set; }
public byte MaterialDetec07 { get; set; }
public byte MaterialDetec08 { get; set; }
public byte MaterialDetec09 { get; set; }
public byte MaterialDetec10 { get; set; }
public byte MaterialDetec11 { get; set; }
public byte MaterialDetec12 { get; set; }
public byte MaterialDetec13 { get; set; }
public byte MaterialDetec14 { get; set; }
public byte MaterialDetec15 { get; set; }
public byte MaterialDetec16 { get; set; }
public byte MaterialDetec17 { get; set; }
public byte MaterialDetec18 { get; set; }
public byte MaterialDetec19 { get; set; }
public byte MaterialDetec20 { get; set; }
#endregion 有料检测
/// <summary>
/// 舱位状态 在位状态0-不在位1-在位2-无效
/// </summary>
/// <returns></returns>
public List<byte> ReturnMaterialDetec()
{
List<byte> ret = new List<byte>
{
MaterialDetec01,MaterialDetec02 ,MaterialDetec03 ,MaterialDetec04 ,MaterialDetec05 ,
MaterialDetec06 ,MaterialDetec07 ,MaterialDetec08 ,MaterialDetec09 ,MaterialDetec10 ,
MaterialDetec11 ,MaterialDetec12 ,MaterialDetec13 ,MaterialDetec14 ,MaterialDetec15 ,
MaterialDetec16 ,MaterialDetec17 ,MaterialDetec18 ,MaterialDetec19 ,MaterialDetec20 ,
};
return ret;
}
public PlcInfo(string channelId, int eqmSn)
{
ChannelId = channelId;
EqmSn = eqmSn;
}
public bool WriteUint16(ModbusProperty<UInt16> value)
{
bool bResult = false;
ModbusSession session = SessionMgr.GetModbusSession(ChannelId);
bResult = session.Write<UInt16>(value);
return bResult;
}
public bool Writeint16(ModbusProperty<Int16> value)
{
bool bResult = false;
ModbusSession session = SessionMgr.GetModbusSession(ChannelId);
bResult = session.Write<Int16>(value);
return bResult;
}
}
}

@ -1,73 +1,8 @@
{
"ConnectionStrings": {
"ConfigId": "master",
"DbType": "MySql",
"SqlConnection": //"server=192.168.2.2;Port=3306;Database=huanneng_dev;Uid=root;Pwd=Rszn123;Charset=utf8;",
"server=127.0.0.1;Port=3306;Database=huanneng_dev;Uid=root;Pwd=anyixing2023!@#;Charset=utf8;"
},
"Update": {
"AutoUpdate": "false",
"Version": "1.1.0.1",
"Url": "http://121.4.95.243:8090/Updates/AutoUpdaterStarter.xml"
},
"Redis": {
"Connection": "106.12.36.89:6379,password=123456",
"InstanceName": "local",
"DefaultDB": "8"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"": null,
"Cryptogram": {
"StrongPassword": "false", //
"PasswordStrengthValidation": "(?=^.{6,16}$)(?=.*\\d)(?=.*\\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\\n).*$", // 6-16
"PasswordStrengthValidationMsg": "密码必须包含大小写字母、数字和特殊字符的组合长度在6-16之间", //
"CryptoType": "SM2", // MD5SM2SM4
"PublicKey": "0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312", //
"PrivateKey": "8EDB615B1D48B8BE188FC0F18EC08A41DF50EA731FA28BF409E6552809E3A111" //
},
//Login
"TokenOptions": {
"SecurityKey": "s4104j1401kopposdfjsfj091541111111111",
"Domain": "*",
"Audience": "jwtAudience",
"Issuer": "jwtIssuer"
},
"Upload": {
"Path": "Upload/{yyyy}/{MM}/{dd}", //
"MaxSize": 20480, // KB1024*20
"ContentType": [ "image/jpg", "image/png", "image/jpeg", "image/gif", "image/bmp", "text/plain", "application/pdf", "application/msword", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "video/mp4" ],
"EnableMd5": false // MDF5-
},
//SysLogin
"JWTSettings": {
"ValidateIssuerSigningKey": true, // bool true
"IssuerSigningKey": "3c1cbc3f546eda35168c3aa3cb91780fbe703f0996c6d123ea96dc85c70bbc0a", // string 16
"ValidateIssuer": true, // bool true
"ValidIssuer": "Admin.NET", // string
"ValidateAudience": true, // bool true
"ValidAudience": "Admin.NET", // string
"ValidateLifetime": true, // bool truetrue
//"ExpiredTime": 20, // long 20 13
"ClockSkew": 5, // long 5
"Algorithm": "HS256", // string HS256
"RequireExpirationTime": true // false
},
"SnowId": {
"WorkerId": 1, //
"WorkerIdBitLength": 6, // 6 [1, 19]
"SeqBitLength": 6, // 6 [3, 21]4Id
"WorkerPrefix": "adminnet_" //
},
"HttpContextRequest": {
"Scheme": "http://192.168.2.17:5034"
}
}

@ -1,6 +1,6 @@
{
"Version": 1,
"Hash": "kIfehZk8TWWy62IgCKeVJMphEP8JJ0AGeTvs9NqLTfU=",
"Hash": "PUkZxlgk8KRfiyiYD55Dczq9Q9JYZyET99LUbVltauo=",
"Source": "WebStarter",
"BasePath": "_content/WebStarter",
"Mode": "Default",
@ -10,17 +10,17 @@
{
"Name": "WebStarter\\wwwroot",
"Source": "WebStarter",
"ContentRoot": "D:\\lxw\\work\\pro\\c#\\hn_back_main\\WebStarter\\wwwroot\\",
"ContentRoot": "D:\\RiderProjects\\hn_back_main\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter",
"Pattern": "**"
}
],
"Assets": [
{
"Identity": "D:\\lxw\\work\\pro\\c#\\hn_back_main\\WebStarter\\wwwroot\\20240523\\0.jpg",
"Identity": "D:\\RiderProjects\\hn_back_main\\WebStarter\\wwwroot\\20240523\\0.jpg",
"SourceId": "WebStarter",
"SourceType": "Discovered",
"ContentRoot": "D:\\lxw\\work\\pro\\c#\\hn_back_main\\WebStarter\\wwwroot\\",
"ContentRoot": "D:\\RiderProjects\\hn_back_main\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter",
"RelativePath": "20240523/0.jpg",
"AssetKind": "All",
@ -36,10 +36,10 @@
"OriginalItemSpec": "wwwroot\\20240523\\0.jpg"
},
{
"Identity": "D:\\lxw\\work\\pro\\c#\\hn_back_main\\WebStarter\\wwwroot\\20240524\\0.jpg",
"Identity": "D:\\RiderProjects\\hn_back_main\\WebStarter\\wwwroot\\20240524\\0.jpg",
"SourceId": "WebStarter",
"SourceType": "Discovered",
"ContentRoot": "D:\\lxw\\work\\pro\\c#\\hn_back_main\\WebStarter\\wwwroot\\",
"ContentRoot": "D:\\RiderProjects\\hn_back_main\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter",
"RelativePath": "20240524/0.jpg",
"AssetKind": "All",
@ -55,10 +55,10 @@
"OriginalItemSpec": "wwwroot\\20240524\\0.jpg"
},
{
"Identity": "D:\\lxw\\work\\pro\\c#\\hn_back_main\\WebStarter\\wwwroot\\20240524\\0.png",
"Identity": "D:\\RiderProjects\\hn_back_main\\WebStarter\\wwwroot\\20240524\\0.png",
"SourceId": "WebStarter",
"SourceType": "Discovered",
"ContentRoot": "D:\\lxw\\work\\pro\\c#\\hn_back_main\\WebStarter\\wwwroot\\",
"ContentRoot": "D:\\RiderProjects\\hn_back_main\\WebStarter\\wwwroot\\",
"BasePath": "_content/WebStarter",
"RelativePath": "20240524/0.png",
"AssetKind": "All",

@ -1,19 +1,4 @@
using HslCommunication.ModBus;
using HslCommunication;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HybirdFrameworkDriver.ModbusTcpMaster;
using HybirdFrameworkDriver.TcpServer;
using Newtonsoft.Json.Linq;
using Service.Init.Entity;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace WinFormStarter
{

@ -2,7 +2,6 @@ using Autofac;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using log4net.Config;
using Service;
using SqlSugar;
using SqlSugar.IOC;
@ -59,4 +58,4 @@ internal static class Program
var result = MessageBox.Show("系统发生错误,您需要退出系统吗?", "异常", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) Application.Exit();
}
}
}

Loading…
Cancel
Save