You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.1 KiB

5 months ago
using Autofac;
5 months ago
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Service.Charger.Server;
using Service.Sound.SoundClient;
5 months ago
namespace Service.Charger.Client;
/// <summary>
/// 示例程序
/// </summary>
[Scope]
public static class ClientMgr
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ClientMgr));
5 months ago
public static PlcClient? PlcClient { get; set; }
5 months ago
5 months ago
5 months ago
//TODO 连接、鉴权,开始充电,结束充电,设置尖峰平谷,读取尖峰平谷,发送功率调节指令,发送辅助源控制指令,下发掉线停止充电,
public static void InitClient()
{
5 months ago
Task.Run(ConnClient);
5 months ago
}
private static void ConnClient()
{
EquipNetInfo netInfo = new EquipNetInfo()
{
1 month ago
//NetAddr = "127.0.0.1",
5 months ago
NetAddr = "192.168.3.20",
NetPort = "2000",
1 month ago
//NetPort = "10000",
5 months ago
Code = PlcConst.ChargeEqpCode,
DestAddr = "132,208,208,224"
};
Log.Info($"begin to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
5 months ago
PlcClient = AppInfo.Container.Resolve<PlcClient>();
2 months ago
Log.Info($"plc client Id={PlcClient.GetHashCode()}");
5 months ago
PlcClient.AutoReconnect = true;
PlcClient.Sn = PlcConst.ChargeEqpCode;
PlcClient.ConnectedEventHandler += (sender, b) =>
5 months ago
{
5 months ago
PlcClient.SessionAttr(netInfo.Code, netInfo.DestAddr);
5 months ago
//鉴权
// client.SendAuth();
};
//ip
2 months ago
PlcClient.InitBootstrap(netInfo.NetAddr, int.Parse(netInfo.NetPort), 30, 0, 0);
5 months ago
/*Task.Run(() =>
{*/
try
{
5 months ago
PlcClient.Connect();
PlcClient.SessionAttr(netInfo.Code, netInfo.DestAddr);
2 months ago
PlcConst.EquipAlarmDefines = PlcClient.GetAlarmDeinneList();
5 months ago
Log.Info($"succeed to connect {netInfo.Code} {netInfo.NetAddr}:{netInfo.NetPort}");
}
catch (Exception ex)
{
5 months ago
Log.Error($"conn plc error ={ex.StackTrace}");
5 months ago
}
//});
}
}