PLC连接读取

master
CZ 6 months ago
parent a6cda060bb
commit 46caac2f8b

@ -140,4 +140,43 @@ public static class ModbusDecoder
object value = BitUtls.Bytes2Value(bytes, valueType, start, length, scale, round, offset);
field.Value = (T)value;
}
public static T DecodeByT<T>(byte[] bytes, T t) where T : class, new()
{
List<object?> fields = t.GetType().GetProperties()
.Where(it => it.PropertyType.GetGenericTypeDefinition() == typeof(ModbusProperty<>))
.Select(p => p.GetValue(t)).ToList();
int startRegisterNo = Int32.MaxValue;
foreach (object field in fields)
{
if (field != null)
{
IModbusProperty p = (IModbusProperty)field;
if (startRegisterNo > p.GetRegisterNo())
{
startRegisterNo = p.GetRegisterNo();
}
}
}
foreach (object field in fields)
{
switch (field)
{
case ModbusProperty<byte> property:
{
SetPropertyValue(startRegisterNo, property, bytes);
break;
}
case ModbusProperty<float> floatProperty:
{
SetPropertyValue(startRegisterNo, floatProperty, bytes);
break;
}
}
}
return t;
}
}

@ -12,6 +12,7 @@ public class ModbusTcpMaster
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ModbusTcpMaster));
public string connectId { get; set; }
// public string Ip { get; set; } = "127.0.0.1";
public string Ip { get; set; } = "192.168.1.5";
public int Port { get; set; } = 502;
@ -27,7 +28,7 @@ public class ModbusTcpMaster
private bool StopFlag { get; set; } = false;
private ModbusTcpNet ModbusTcpNet;
public ModbusTcpNet ModbusTcpNet;
ILog GetLog()

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkDriver.ModbusTcpMaster
{
/// <summary>
/// PLC地址
/// </summary>
public class PlcDate
{
/// <summary>
/// 写编程使能
/// </summary>
public ModbusProperty<UInt16> ProgrammingEnable { get; set; } = new(40960);
/// <summary>
/// 本机modbus地址
/// </summary>
public ModbusProperty<UInt16> Modbus1Addres { get; set; } = new(40962);
/// <summary>
/// 波特率
/// </summary>
public ModbusProperty<UInt16> BaudRate { get; set; } = new(40964);
/// <summary>
/// 校验位
/// </summary>
public ModbusProperty<UInt16> CheckBit { get; set; } = new(2566);
/// <summary>
/// 秒
/// </summary>
public ModbusProperty<UInt16> Seconds { get; set; } = new(0);
/// <summary>
/// 分
/// </summary>
public ModbusProperty<UInt16> Points { get; set; } = new(2);
/// <summary>
/// 时
/// </summary>
public ModbusProperty<UInt16> When { get; set; } = new(4);
/// <summary>
/// 周
/// </summary>
public ModbusProperty<UInt16> Weeks { get; set; } = new(6);
/// <summary>
/// 日
/// </summary>
public ModbusProperty<UInt16> Day { get; set; } = new(8);
/// <summary>
/// 月
/// </summary>
public ModbusProperty<UInt16> Month { get; set; } = new(10);
/// <summary>
/// 年
/// </summary>
public ModbusProperty<UInt16> Years { get; set; } = new(12);
/// <summary>
/// 本机modbus地址
/// </summary>
public ModbusProperty<UInt16> Modbus1Addres2 { get; set; } = new(14);
/// <summary>
/// 保留
/// </summary>
public ModbusProperty<UInt16> Reserve { get; set; } = new(16);
/// <summary>
/// 电压变比
/// </summary>
public ModbusProperty<UInt16> VoltageRatio { get; set; } = new(18);
/// <summary>
/// 电流变比
/// </summary>
public ModbusProperty<UInt16> CurrentRatio { get; set; } = new(20);
/// <summary>
/// 秒脉冲/无功电能选择
/// </summary>
public ModbusProperty<UInt16> PulsePerSecond { get; set; } = new(42);
/// <summary>
/// 电流接线反向
/// </summary>
public ModbusProperty<UInt16> CurrentReversal { get; set; } = new(48);
/// <summary>
/// 电表清零
/// </summary>
public ModbusProperty<UInt16> MeterReset { get; set; } = new(4576);
}
}

@ -0,0 +1,40 @@
using HybirdFrameworkDriver.ModbusTcpMaster;
using log4net;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkDriver.TcpServer
{
public class ModbusSession
{
private readonly ILog Log = LogManager.GetLogger(typeof(ModbusSession));
public ModbusTcpMaster.ModbusTcpMaster ModbusTcpMaster;
private String IpAddr { get; }
public String Key { get; set; }
public ConcurrentDictionary<String, Object> BusinessMap { get; set; }
public ModbusSession(ModbusTcpMaster.ModbusTcpMaster modbusTcpMaster)
{
this.ModbusTcpMaster = modbusTcpMaster;
this.IpAddr = modbusTcpMaster.Ip;
this.Key = modbusTcpMaster.connectId;
}
public bool Write<T>(ModbusProperty<T> property)
{
return ModbusTcpMaster.WriteValue(property);
}
public byte[]? Read(int registerNo, int length)
{
return ModbusTcpMaster.BatchRead(registerNo, length);
}
}
}

@ -12,6 +12,9 @@ public class SessionMgr
private static readonly ConcurrentDictionary<string, IoSession> Dictionary =
new ConcurrentDictionary<string, IoSession>();
private static readonly ConcurrentDictionary<string, ModbusSession> ModbusDictionary =
new ConcurrentDictionary<string, ModbusSession>();
public static void RegisterSession(string key, IoSession ioSession)
{
ioSession.Key = key;
@ -35,4 +38,57 @@ public class SessionMgr
session.Send(buffer);
}
}
public static void RegisterModbusSession(string key, ModbusSession ioSession)
{
var oldKey = ioSession.Key;
if (oldKey != null)
{
ModbusSession? session;
ModbusDictionary.Remove(oldKey, out session);
}
ioSession.Key = key;
ModbusDictionary.AddOrUpdate(key, ioSession, (k, oldSession) => ioSession);
}
public static void SetAttrModbus(ModbusSession session, String key, Object obj)
{
if (session.BusinessMap == null)
{
session.BusinessMap = new ConcurrentDictionary<string, object>();
}
session.BusinessMap.TryAdd(key, obj);
}
public static Object GetAttrModbus(String key, String mapKey)
{
ModbusDictionary.TryGetValue(key, out ModbusSession? session);
if (session != null)
{
session.BusinessMap.TryGetValue(mapKey, out Object? obj);
if (obj != null)
{
return (int)obj;
}
}
return 0;
}
public static ModbusSession GetModbusSession(string key)
{
if (ModbusDictionary.ContainsKey(key))
{
ModbusSession value;
ModbusDictionary.TryGetValue(key, out value);
return value;
}
return null;
}
}

@ -0,0 +1,59 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkEntity.DbModel
{
/// <summary>
/// 设备连接参数信息字段类
/// </summary>
[SugarTable("t_bs_net_eqm_param_info")]
public partial class BsNetEqmParamInfo
{
/// <summary>
/// 索引
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "f_id")]
public int Id { get; set; }
/// <summary>
/// 设备类型编号
/// </summary>
[SugarColumn(ColumnName = "f_eqm_type_no")]
public int EqmTypeNo { get; set; }
/// <summary>
/// 设备类型名称
/// </summary>
[SugarColumn(ColumnName = "f_eqm_type_name")]
public string EqmTypeName { get; set; }
/// <summary>
/// 设备编码
/// </summary>
[SugarColumn(ColumnName = "f_eqm_code")]
public string EqmCode { get; set; }
/// <summary>
/// 设备序号
/// </summary>
[SugarColumn(ColumnName = "f_eqm_sn")]
public int EqmSn { get; set; }
/// <summary>
/// 连接地址
/// </summary>
[SugarColumn(ColumnName = "f_net_addr")]
public string NetAddr { get; set; }
/// <summary>
/// 连接端口
/// </summary>
[SugarColumn(ColumnName = "f_net_port")]
public string NetPort { get; set; }
/// <summary>
/// 目的地址
/// </summary>
[SugarColumn(ColumnName = "f_dest_addr")]
public string DestAddr { get; set; }
}
}

@ -0,0 +1,39 @@
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkEntity.DbModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkRepository.System
{
[Scope("SingleInstance")]
public class BsNetEqmParamInfoRepository : BaseRepository<BsNetEqmParamInfo>
{
private ISqlSugarClient DbBaseClient;
public BsNetEqmParamInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
DbBaseClient = sqlSugar;
}
public List<BsNetEqmParamInfo> QueryListByFEqmTypeNo(List<int> fEqmTypeNo)
{
return DbBaseClient
.Queryable<BsNetEqmParamInfo>()
.In(t => t.EqmTypeNo, fEqmTypeNo)
.ToList();
}
public IEnumerable<IGrouping<int, BsNetEqmParamInfo>> QueryConnectParams(List<int> types)
{
List<BsNetEqmParamInfo> infos = this.QueryListByFEqmTypeNo(types);
return infos.GroupBy(i => i.EqmTypeNo).ToList();
}
}
}

@ -0,0 +1,165 @@
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkDriver.ModbusTcpMaster;
using HybirdFrameworkDriver.TcpServer;
using HybirdFrameworkEntity.DbModel;
using HybirdFrameworkRepository.System;
using HybirdFrameworkServices.Init.Entity;
using HybirdFrameworkServices.Plc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkServices
{
[Scope("SingleInstance")]
public class EquipmentInit
{
BsNetEqmParamInfoRepository _bsNetEqmParamInfoRepository;
public EquipmentInit(BsNetEqmParamInfoRepository bsNetEqmParamInfoRepository)
{
_bsNetEqmParamInfoRepository = bsNetEqmParamInfoRepository;
}
/// <summary>
/// 连接所有数据
/// </summary>
/// <exception cref="InvalidOperationException"></exception>
public void Connect()
{
BsNetEqmParamInfo bsNetEqmParamInfo = new BsNetEqmParamInfo()
{
EqmTypeNo = 3,
EqmTypeName = "",
EqmCode = "",
EqmSn = 3,
NetAddr = "127.0.0.1",
NetPort = "502",
DestAddr = "1",
};
// //PLC删除
// IEnumerable<IGrouping<int, BsNetEqmParamInfo>> queryConnectParams =;
// _bsNetEqmParamInfoRepository.QueryConnectParams(new List<int>() { 1, 2, 101 });
// int count = 0;
// IEnumerable<IGrouping<int, BsNetEqmParamInfo>> connectParams =
//queryConnectParams as IGrouping<int, BsNetEqmParamInfo>[] ?? queryConnectParams.ToArray();
// foreach (IGrouping<int, BsNetEqmParamInfo> device in connectParams)
// {
// Console.WriteLine(device.Key);
// count = device.Key switch
// {
// //1 => ConnectCharger(device),
// //101 => ConnectCharger(device),
// //2 => ConnectWaterCooler(device),
// 3 => ConnectPlc(device),
// _ =>
// // 处理所有其他情况,可能抛出异常、记录日志或返回默认值
// throw new InvalidOperationException("Unknown device key: " + device.Key),
// };
// }
ConnectPlc(bsNetEqmParamInfo);
}
/// <summary>
/// 连接PLC
/// </summary>
/// <param name="param"></param>
/// <returns></returns>
public int ConnectPlc(/*IGrouping<int, BsNetEqmParamInfo> param*/ BsNetEqmParamInfo p)
{
/*int connectNum = 0;
foreach (var p in param)
{
connectNum++;*/
Thread thread = new Thread(() => ConnectPlcAsync(p));
thread.Start();
/*}*/
return 0;
}
private void ConnectPlcAsync(BsNetEqmParamInfo p)
{
bool connected = false;
ModbusTcpMaster master = null;
//PLC连接
while (!connected)
{
master = new ModbusTcpMaster()
{
Ip = "127.0.0.1",
Port = 102,
};
master.ReadAction = BatchReadPlc;//启动线程一直读
master.Duration = 3000;
master.Duration = 3000;
connected = master.Connect();
if (connected)
{
break;
}
Thread.Sleep(5000);
}
ModbusSession modbusSession = new ModbusSession(master);
SessionMgr.RegisterModbusSession(master.connectId, modbusSession);
SessionMgr.SetAttrModbus(modbusSession, "eqm_sn", p.EqmSn);
PlcInfo waterColdInfo = new PlcInfo(master.connectId, p.EqmSn);
ChargerStaticInfo.PlcInfos.TryAdd(p.EqmSn, waterColdInfo);
}
/**
*
*/
private static void BatchReadPlc(ModbusTcpMaster master)
{
int sn = (int)SessionMgr.GetAttrModbus(master.connectId, "eqm_sn");
ChargerStaticInfo.PlcInfos.TryGetValue(sn, out PlcInfo plcInfo);
if (plcInfo == null)
{
return;
}
byte[]? bytes01 = master.BatchRead(0, 22);
if (bytes01 != null)
{
ModbusDecoder.DecodeByT<PlcReadAndWrite2>(bytes01, plcInfo.PlcReadAndWritten2);
}
byte[]? bytes02 = master.BatchRead(256, 170);
if (bytes02 != null)
{
ModbusDecoder.DecodeByT<PlcReadonly>(bytes02, plcInfo.PlcReadonly);
}
byte[]? bytes03 = master.BatchRead(39424, 108);
if (bytes03 != null)
{
ModbusDecoder.DecodeByT<PlcTurnsRatio>(bytes03, plcInfo.PlcTurnsRatio);
}
byte[]? bytes04 = master.BatchRead(40960, 3);//写编程使能。本机modbus地址。波特率
byte[]? bytes05 = master.BatchRead(2566, 1);//校验位
byte[]? bytes06 = master.BatchRead(42, 1);//秒脉冲/无功电能选择
byte[]? bytes07 = master.BatchRead(48, 1);//电流接线反向
byte[]? bytes08 = master.BatchRead(4576, 1);//电表清零
if (bytes04 != null)
{
ModbusDecoder.DecodeByT<PlcReadAndWrite1>(bytes04, plcInfo.PlcReadAndWritten1);
}
plcInfo.PlcReadAndWritten1.CheckBit = master.ModbusTcpNet.ByteTransform.TransUInt16(bytes05, 0);
plcInfo.PlcReadAndWritten1.PulsePerSecond = master.ModbusTcpNet.ByteTransform.TransUInt16(bytes06, 0);
plcInfo.PlcReadAndWritten1.CurrentReversal = master.ModbusTcpNet.ByteTransform.TransUInt16(bytes07, 0);
plcInfo.PlcReadAndWritten1.MeterReset = master.ModbusTcpNet.ByteTransform.TransUInt16(bytes08, 0);
}
}
}

@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>

@ -0,0 +1,18 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkServices.Init.Entity
{
public class ChargerStaticInfo
{
/// <summary>
/// PLC管理
/// </summary>
public static readonly ConcurrentDictionary<int, PlcInfo> PlcInfos =
new ConcurrentDictionary<int, PlcInfo>();
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkServices.Init.Entity
{
/// <summary>
///PLC连接状态枚举
/// </summary>
public enum ConnectState
{
NOCONNECT = 0,
CONNECTING = 1,
CONNECTED = 2
}
}

@ -0,0 +1,78 @@
using HslCommunication;
using HslCommunication.ModBus;
using HybirdFrameworkDriver.ModbusTcpMaster;
using HybirdFrameworkDriver.TcpServer;
using HybirdFrameworkServices.Plc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkServices.Init.Entity
{
public class PlcInfo
{
#region 字段
/// <summary>
/// ModbusTcp客户端
/// </summary>
//public ModbusTcpNet _client = null;
/// <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.NOCONNECT;
#endregion 字段
public string ChannelId;
public int EqmSn;
public PlcReadAndWrite1 PlcReadAndWritten1 { get; set; }
public PlcReadAndWrite2 PlcReadAndWritten2 { get; set; }
public PlcReadonly PlcReadonly { get; set; }
public PlcTurnsRatio PlcTurnsRatio { get; set; }
public PlcInfo(string channelId, int eqmSn)
{
ChannelId = channelId;
EqmSn = eqmSn;
}
public bool WriteUint16(string addr, ModbusProperty<UInt16> value)
{
bool bResult = false;
ModbusSession session = SessionMgr.GetModbusSession(ChannelId);
bResult = session.Write<UInt16>(value);
return bResult;
}
}
}

@ -0,0 +1,66 @@
using HybirdFrameworkCore.Autofac.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkServices.Plc
{
/// <summary>
/// 可读可写区
/// </summary>
public class PlcReadAndWrite1
{
/// <summary>
/// 写编程使能 写 0x5AA5,打开写使能
/// </summary>
[Property(0, 2, PropertyReadConstant.Byte)]
public ushort ProgrammingEnable { get; set; }
/// <summary>
/// 本机modbus地址
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort Modbus1Addres { get; set; }
/// <summary>
/// 波特率
/// <para>01200</para>
/// <para>12400</para>
/// <para>24800</para>
/// <para>39600</para>
/// <para>419200</para>
/// </summary>
[Property(4, 2, PropertyReadConstant.Byte)]
public ushort BaudRate { get; set; }
/// <summary>
/// 校验位
/// <para>0无</para>
/// <para>1奇</para>
/// <para>2偶</para>
/// </summary>
//[Property(2, 2, PropertyReadConstant.Byte)]
public ushort CheckBit { get; set; }
/// <summary>
/// 秒脉冲/无功电能选择
/// 0x5A02:秒脉冲输出
/// 其他:无功电能输出)
/// </summary>
//[Property(2, 2, PropertyReadConstant.Byte)]
public ushort PulsePerSecond { get; set; }
/// <summary>
/// 电流接线反向
/// <para>0x00:不反接(默认值) </para>
/// <para>0x01:反接</para>
/// </summary>
//[Property(2, 2, PropertyReadConstant.Byte)]
public ushort CurrentReversal { get; set; }
/// <summary>
/// 电表清零
/// 写 0x0000 清零,其他不清
/// </summary>
//[Property(2, 2, PropertyReadConstant.Byte)]
public ushort MeterReset { get; set; }
}
}

@ -0,0 +1,68 @@
using HybirdFrameworkCore.Autofac.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkServices.Plc
{
public class PlcReadAndWrite2
{
/// <summary>
/// 秒
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Seconds { get; set; }
/// <summary>
/// 分
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Points { get; set; }
/// <summary>
/// 时
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte When { get; set; }
/// <summary>
/// 周
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Weeks { get; set; }
/// <summary>
/// 日
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Day { get; set; }
/// <summary>
/// 月
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Month { get; set; }
/// <summary>
/// 年
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Years { get; set; }
/// <summary>
/// 本机modbus地址
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort Modbus1Addres2 { get; set; }
/// <summary>
/// 保留
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort Reserve { get; set; }
/// <summary>
/// 电压变比
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort VoltageRatio { get; set; }
/// <summary>
/// 电流变比
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort CurrentRatio { get; set; }
}
}

@ -1,136 +0,0 @@
using HybirdFrameworkCore.Autofac.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybirdFrameworkServices.Plc
{
/// <summary>
/// 可读可写区
/// </summary>
public class PlcReadAndWritten
{
/// <summary>
/// 写编程使能 写 0x5AA5,打开写使能
/// </summary>
[Property(0, 2, PropertyReadConstant.Byte)]
public ushort ProgrammingEnable { get; set; }
/// <summary>
/// 本机modbus地址
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort Modbus1Addres { get; set; }
/// <summary>
/// 波特率
/// <para>01200</para>
/// <para>12400</para>
/// <para>24800</para>
/// <para>39600</para>
/// <para>419200</para>
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort BaudRate { get; set; }
/// <summary>
/// 校验位
/// <para>0无</para>
/// <para>1奇</para>
/// <para>2偶</para>
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort CheckBit { get; set; }
/// <summary>
/// 秒
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Seconds { get; set; }
/// <summary>
/// 分
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Points { get; set; }
/// <summary>
/// 时
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte When { get; set; }
/// <summary>
/// 周
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Weeks { get; set; }
/// <summary>
/// 日
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Day { get; set; }
/// <summary>
/// 月
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Month { get; set; }
/// <summary>
/// 年
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public byte Years { get; set; }
public string time
{
get
{
return Years + "-" +
Month.ToString().PadLeft(2, '0') + "-" +
Day.ToString().PadLeft(2, '0') + " " +
When.ToString().PadLeft(2, '0') + ":" +
Points.ToString().PadLeft(2, '0') + ":" +
Seconds.ToString().PadLeft(2, '0');
}
set
{
}
}
/// <summary>
/// 本机modbus地址
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort Modbus1Addres2 { get; set; }
/// <summary>
/// 保留
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort Reserve { get; set; }
/// <summary>
/// 电压变比
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort VoltageRatio { get; set; }
/// <summary>
/// 电流变比
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort CurrentRatio { get; set; }
/// <summary>
/// 秒脉冲/无功电能选择
/// 0x5A02:秒脉冲输出
/// 其他:无功电能输出)
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort PulsePerSecond { get; set; }
/// <summary>
/// 电流接线反向
/// <para>0x00:不反接(默认值) </para>
/// <para>0x01:反接</para>
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort CurrentReversal { get; set; }
/// <summary>
/// 电表清零
/// 写 0x0000 清零,其他不清
/// </summary>
[Property(2, 2, PropertyReadConstant.Byte)]
public ushort MeterReset { get; set; }
}
}

@ -1,4 +1,5 @@
using System;
using HybirdFrameworkCore.Autofac.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -14,351 +15,432 @@ namespace HybirdFrameworkServices.Plc
/// <summary>
/// 组合有功总电能
/// </summary>
public float GroupHaveAll { get; set; }
[Property(0, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupHaveAll { get; set; }
/// <summary>
/// 组合有功尖电能
/// </summary>
[Property(4, 4, PropertyReadConstant.Byte, 0.01)]
public float GroupHaveTip { get; set; }
/// <summary>
/// 组合有功峰电能
/// </summary>
public float GroupHavePeak { get; set; }
[Property(8, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupHavePeak { get; set; }
/// <summary>
/// 组合有功平电能
/// </summary>
public float GroupHaveFlat { get; set; }
[Property(12, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupHaveFlat { get; set; }
/// <summary>
/// 组合有功谷电能
/// </summary>
public float GroupHaveValley { get; set; }
[Property(16, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupHaveValley { get; set; }
/// <summary>
/// 正向有功总电能
/// </summary>
public float ForwardHaveAll { get; set; }
[Property(20, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveAll { get; set; }
/// <summary>
/// 正向有功尖电能
/// </summary>
public float ForwardHaveTip { get; set; }
[Property(24, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveTip { get; set; }
/// <summary>
/// 正向有功峰电能
/// </summary>
public float ForwardHavePeak { get; set; }
[Property(28, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHavePeak { get; set; }
/// <summary>
/// 正向有功平电能
/// </summary>
public float ForwardHaveFlat { get; set; }
[Property(32, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveFlat { get; set; }
/// <summary>
/// 正向有功谷电能
/// </summary>
public float ForwardHaveValley { get; set; }
[Property(36, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveValley { get; set; }
/// <summary>
/// 反向有功总电能
/// </summary>
public float ReverseHaveAll { get; set; }
[Property(40, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveAll { get; set; }
/// <summary>
/// 反向有功尖电能
/// </summary>
public float ReverseHaveTip { get; set; }
[Property(44, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveTip { get; set; }
/// <summary>
/// 反向有功峰电能
/// </summary>
public float ReverseHavePeak { get; set; }
[Property(48, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHavePeak { get; set; }
/// <summary>
/// 反向有功平电能
/// </summary>
public float ReverseHaveFlat { get; set; }
[Property(52, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveFlat { get; set; }
/// <summary>
/// 反向有功谷电能
/// </summary>
public float ReverseHaveValley { get; set; }
[Property(56, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveValley { get; set; }
/// <summary>
/// 组合无功1总电能
/// </summary>
[Property(60, 4, PropertyReadConstant.Byte, 0.01)]
public float GroupNoAll1 { get; set; }
/// <summary>
/// 组合无功1尖电能
/// </summary>
public float GroupNoTip1 { get; set; }
[Property(64, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoTip1 { get; set; }
/// <summary>
/// 组合无功1峰电能
/// </summary>
public float GroupNoPeak1 { get; set; }
[Property(68, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoPeak1 { get; set; }
/// <summary>
/// 组合无功1平电能
/// </summary>
public float GroupNoFlat1 { get; set; }
[Property(72, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoFlat1 { get; set; }
/// <summary>
/// 组合无功1谷电能
/// </summary>
public float GroupNoValley1 { get; set; }
[Property(76, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoValley1 { get; set; }
/// <summary>
/// 组合无功2总电能
/// </summary>
public float GroupNoAll2 { get; set; }
[Property(80, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoAll2 { get; set; }
/// <summary>
/// 组合无功2尖电能
/// </summary>
public float GroupNoTip2 { get; set; }
[Property(84, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoTip2 { get; set; }
/// <summary>
/// 组合无功2峰电能
/// </summary>
public float GroupNoPeak2 { get; set; }
[Property(88, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoPeak2 { get; set; }
/// <summary>
/// 组合无功2平电能
/// </summary>
public float GroupNoFlat2 { get; set; }
[Property(92, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoFlat2 { get; set; }
/// <summary>
/// 组合无功2谷电能
/// </summary>
public float GroupNoValley2 { get; set; }
[Property(96, 4, PropertyReadConstant.Byte, 0.01)]
public Int32 GroupNoValley2 { get; set; }
/// <summary>
/// 一象限无功总电能
/// </summary>
public float QuadrantNoAll1 { get; set; }
[Property(100, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoAll1 { get; set; }
/// <summary>
/// 一象限无功尖电能
/// </summary>
public float QuadrantNoTip1 { get; set; }
[Property(104, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoTip1 { get; set; }
/// <summary>
/// 一象限无功峰电能
/// </summary>
public float QuadrantNoPeak1 { get; set; }
[Property(108, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoPeak1 { get; set; }
/// <summary>
/// 一象限无功平电能
/// </summary>
public float QuadrantNoFlat1 { get; set; }
[Property(112, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoFlat1 { get; set; }
/// <summary>
/// 一象限无功谷电能
/// </summary>
public float QuadrantNoValley1 { get; set; }
[Property(116, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoValley1 { get; set; }
/// <summary>
/// 二象限无功总电能
/// </summary>
public float QuadrantNoAll2 { get; set; }
[Property(120, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoAll2 { get; set; }
/// <summary>
/// 二象限无功尖电能
/// </summary>
public float QuadrantNoTip2 { get; set; }
[Property(124, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoTip2 { get; set; }
/// <summary>
/// 二象限无功峰电能
/// </summary>
public float QuadrantNoPeak2 { get; set; }
[Property(128, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoPeak2 { get; set; }
/// <summary>
/// 二象限无功平电能
/// </summary>
public float QuadrantNoFlat2 { get; set; }
[Property(132, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoFlat2 { get; set; }
/// <summary>
/// 二象限无功谷电能
/// </summary>
public float QuadrantNoValley2 { get; set; }
[Property(136, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoValley2 { get; set; }
/// <summary>
/// 三象限无功总电能
/// </summary>
public float QuadrantNoAll3 { get; set; }
[Property(140, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoAll3 { get; set; }
/// <summary>
/// 三象限无功尖电能
/// </summary>
public float QuadrantNoTip3 { get; set; }
[Property(144, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoTip3 { get; set; }
/// <summary>
/// 三象限无功峰电能
/// </summary>
public float QuadrantNoPeak3 { get; set; }
[Property(148, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoPeak3 { get; set; }
/// <summary>
/// 三象限无功平电能
/// </summary>
public float QuadrantNoFlat3 { get; set; }
[Property(152, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoFlat3 { get; set; }
/// <summary>
/// 三象限无功谷电能
/// </summary>
public float QuadrantNoValley3 { get; set; }
[Property(156, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoValley3 { get; set; }
/// <summary>
/// 四象限无功总电能
/// </summary>
public float QuadrantNoAll4 { get; set; }
[Property(160, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoAll4 { get; set; }
/// <summary>
/// 四象限无功尖电能
/// </summary>
public float QuadrantNoTip4 { get; set; }
[Property(164, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoTip4 { get; set; }
/// <summary>
/// 四象限无功峰电能
/// </summary>
public float QuadrantNoPeak4 { get; set; }
[Property(168, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoPeak4 { get; set; }
/// <summary>
/// 四象限无功平电能
/// </summary>
public float QuadrantNoFlat4 { get; set; }
[Property(172, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoFlat4 { get; set; }
/// <summary>
/// 四象限无功谷电能
/// </summary>
public float QuadrantNoValley4 { get; set; }
[Property(176, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 QuadrantNoValley4 { get; set; }
/// <summary>
/// 正向视在总电能
/// </summary>
public float ForwardHaveApparentAll { get; set; }
[Property(180, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveApparentAll { get; set; }
/// <summary>
/// 正向视在尖电能
/// </summary>
public float ForwardHaveApparentTip { get; set; }
[Property(184, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveApparentTip { get; set; }
/// <summary>
/// 正向视在峰电能
/// </summary>
public float ForwardHaveApparentPeak { get; set; }
[Property(188, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveApparentPeak { get; set; }
/// <summary>
/// 正向视在平电能
/// </summary>
public float ForwardHaveApparentFlat { get; set; }
[Property(192, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveApparentFlat { get; set; }
/// <summary>
/// 正向视在谷电能
/// </summary>
public float ForwardHaveApparentValley { get; set; }
[Property(196, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ForwardHaveApparentValley { get; set; }
/// <summary>
/// 反向视在总电能
/// </summary>
public float ReverseHaveApparentAll { get; set; }
[Property(200, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveApparentAll { get; set; }
/// <summary>
/// 反向视在尖电能
/// </summary>
public float ReverseHaveApparentTip { get; set; }
[Property(204, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveApparentTip { get; set; }
/// <summary>
/// 反向视在峰电能
/// </summary>
public float ReverseHaveApparentPeak { get; set; }
[Property(208, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveApparentPeak { get; set; }
/// <summary>
/// 反向视在平电能
/// </summary>
public float ReverseHaveApparentFlat { get; set; }
[Property(212, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveApparentFlat { get; set; }
/// <summary>
/// 反向视在谷电能
/// </summary>
public float ReverseHaveApparentValley { get; set; }
[Property(216, 4, PropertyReadConstant.Byte, 0.01)]
public UInt32 ReverseHaveApparentValley { get; set; }
/// <summary>
/// A 相电压
/// </summary>
public float PhaseVoltageA { get; set; }
[Property(220, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 PhaseVoltageA { get; set; }
/// <summary>
/// B 相电压
/// </summary>
public float PhaseVoltageB { get; set; }
[Property(224, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 PhaseVoltageB { get; set; }
/// <summary>
/// C 相电压
/// </summary>
public float PhaseVoltageC { get; set; }
[Property(228, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 PhaseVoltageC { get; set; }
/// <summary>
/// A 相电流
/// </summary>
public float PhaseElectricityA { get; set; }
[Property(232, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 PhaseElectricityA { get; set; }
/// <summary>
/// B 相电流
/// </summary>
public float PhaseElectricityB { get; set; }
[Property(236, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 PhaseElectricityB { get; set; }
/// <summary>
/// C 相电流
/// </summary>
public float PhaseElectricityC { get; set; }
[Property(240, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 PhaseElectricityC { get; set; }
/// <summary>
/// 有功总功率
/// </summary>
public float TotalActivePower { get; set; }
[Property(244, 4, PropertyReadConstant.Byte, 0.0001)]
public Int32 TotalActivePower { get; set; }
/// <summary>
/// A 相有功总功率
/// </summary>
public float TotalActivePowerA { get; set; }
[Property(248, 4, PropertyReadConstant.Byte, 0.0001)]
public Int32 TotalActivePowerA { get; set; }
/// <summary>
/// B 相有功总功率
/// </summary>
public float TotalActivePowerB { get; set; }
[Property(252, 4, PropertyReadConstant.Byte, 0.0001)]
public Int32 TotalActivePowerB { get; set; }
/// <summary>
/// C 相有功总功率
/// </summary>
public float TotalActivePowerC { get; set; }
[Property(256, 4, PropertyReadConstant.Byte, 0.0001)]
public Int32 TotalActivePowerC { get; set; }
/// <summary>
/// 无功总功率
/// </summary>
public float TotalReactivePower { get; set; }
[Property(260, 4, PropertyReadConstant.Byte, 0.0001)]
public Int32 TotalReactivePower { get; set; }
/// <summary>
/// A 相无功总功率
/// </summary>
public float TotalReactivePowerA { get; set; }
[Property(264, 4, PropertyReadConstant.Byte, 0.0001)]
public Int32 TotalReactivePowerA { get; set; }
/// <summary>
/// B 相无功总功率
/// </summary>
public float TotalReactivePowerB { get; set; }
[Property(268, 4, PropertyReadConstant.Byte, 0.0001)]
public Int32 TotalReactivePowerB { get; set; }
/// <summary>
/// C 相无功总功率
/// </summary>
public float TotalReactivePowerC { get; set; }
[Property(272, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 TotalReactivePowerC { get; set; }
/// <summary>
/// 总视在功率
/// </summary>
public float TotalApparentPower { get; set; }
[Property(276, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 TotalApparentPower { get; set; }
/// <summary>
/// A 相视在功率
/// </summary>
public float TotalApparentPowerA { get; set; }
[Property(280, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 TotalApparentPowerA { get; set; }
/// <summary>
/// B 相视在功率
/// </summary>
public float TotalApparentPowerB { get; set; }
[Property(284, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 TotalApparentPowerB { get; set; }
/// <summary>
/// C 相视在功率
/// </summary>
public float TotalApparentPowerC { get; set; }
[Property(288, 4, PropertyReadConstant.Byte, 0.0001)]
public UInt32 TotalApparentPowerC { get; set; }
/// <summary>
/// 总功率因数
/// </summary>
[Property(292, 2, PropertyReadConstant.Byte, 0.001)]
public short OverallPowerFactor { get; set; }
/// <summary>
/// A 相功率因数
/// </summary>
[Property(294, 2, PropertyReadConstant.Byte, 0.001)]
public short OverallPowerFactorA { get; set; }
/// <summary>
/// B 相功率因数
/// </summary>
[Property(296, 2, PropertyReadConstant.Byte, 0.001)]
public short OverallPowerFactorB { get; set; }
/// <summary>
/// C 相功率因数
/// </summary>
[Property(298, 2, PropertyReadConstant.Byte, 0.001)]
public short OverallPowerFactorC { get; set; }
/// <summary>
/// A 相相角
/// </summary>
[Property(300, 2, PropertyReadConstant.Byte, 0.01)]
public ushort PhaseAngleA { get; set; }
/// <summary>
/// B 相相角
/// </summary>
[Property(302, 2, PropertyReadConstant.Byte, 0.01)]
public ushort PhaseAngleB { get; set; }
/// <summary>
/// C 相相角
/// </summary>
[Property(304, 2, PropertyReadConstant.Byte, 0.01)]
public ushort PhaseAngleC { get; set; }
/// <summary>
/// 电网频率
/// </summary>
[Property(306, 2, PropertyReadConstant.Byte, 0.01)]
public ushort LineFrequency { get; set; }
/// <summary>
/// A 相线电压
/// </summary>
[Property(308, 4, PropertyReadConstant.Byte, 0.0001)]
public float PhaseLineVoltageA { get; set; }
/// <summary>
/// B 相线电压
/// </summary>
[Property(312, 4, PropertyReadConstant.Byte, 0.0001)]
public float PhaseLineVoltageB { get; set; }
/// <summary>
/// C 相线电压
/// </summary>
[Property(316, 4, PropertyReadConstant.Byte, 0.0001)]
public float PhaseLineVoltageC { get; set; }
/// <summary>
/// 三相平均线电压
/// </summary>
[Property(320, 4, PropertyReadConstant.Byte, 0.0001)]
public float ThreePhaseMeanLineVoltage { get; set; }
/// <summary>
/// 三相平均相电压
/// </summary>
[Property(324, 4, PropertyReadConstant.Byte, 0.0001)]
public float ThreePhaseMeanPhaseVoltage { get; set; }
}
}

@ -1,4 +1,5 @@
using System;
using HybirdFrameworkCore.Autofac.Attribute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -14,225 +15,277 @@ namespace HybirdFrameworkServices.Plc
/// <summary>
/// 组合有功总电能
/// </summary>
[Property(0, 4, PropertyReadConstant.Byte)]
public float GroupHaveAll { get; set; }
/// <summary>
/// 组合有功尖电能
/// </summary>
[Property(4, 4, PropertyReadConstant.Byte)]
public float GroupHaveTip { get; set; }
/// <summary>
/// 组合有功峰电能
/// </summary>
[Property(8, 4, PropertyReadConstant.Byte)]
public float GroupHavePeak { get; set; }
/// <summary>
/// 组合有功平电能
/// </summary>
[Property(12, 4, PropertyReadConstant.Byte)]
public float GroupHaveFlat { get; set; }
/// <summary>
/// 组合有功谷电能
/// </summary>
[Property(16, 4, PropertyReadConstant.Byte)]
public float GroupHaveValley { get; set; }
/// <summary>
/// 正向有功总电能
/// </summary>
[Property(20, 4, PropertyReadConstant.Byte)]
public float ForwardHaveAll { get; set; }
/// <summary>
/// 正向有功尖电能
/// </summary>
[Property(24, 4, PropertyReadConstant.Byte)]
public float ForwardHaveTip { get; set; }
/// <summary>
/// 正向有功峰电能
/// </summary>
[Property(28, 4, PropertyReadConstant.Byte)]
public float ForwardHavePeak { get; set; }
/// <summary>
/// 正向有功平电能
/// </summary>
[Property(32, 4, PropertyReadConstant.Byte)]
public float ForwardHaveFlat { get; set; }
/// <summary>
/// 正向有功谷电能
/// </summary>
[Property(36, 4, PropertyReadConstant.Byte)]
public float ForwardHaveValley { get; set; }
/// <summary>
/// 反向有功总电能
/// </summary>
[Property(40, 4, PropertyReadConstant.Byte)]
public float ReverseHaveAll { get; set; }
/// <summary>
/// 反向有功尖电能
/// </summary>
[Property(44, 4, PropertyReadConstant.Byte)]
public float ReverseHaveTip { get; set; }
/// <summary>
/// 反向有功峰电能
/// </summary>
[Property(48, 4, PropertyReadConstant.Byte)]
public float ReverseHavePeak { get; set; }
/// <summary>
/// 反向有功平电能
/// </summary>
[Property(52, 4, PropertyReadConstant.Byte)]
public float ReverseHaveFlat { get; set; }
/// <summary>
/// 反向有功谷电能
/// </summary>
[Property(56, 4, PropertyReadConstant.Byte)]
public float ReverseHaveValley { get; set; }
/// <summary>
/// 组合无功1总电能
/// </summary>
[Property(60, 4, PropertyReadConstant.Byte)]
public float GroupNoAll1 { get; set; }
/// <summary>
/// 组合无功1尖电能
/// </summary>
[Property(64, 4, PropertyReadConstant.Byte)]
public float GroupNoTip1 { get; set; }
/// <summary>
/// 组合无功1峰电能
/// </summary>
[Property(68, 4, PropertyReadConstant.Byte)]
public float GroupNoPeak1 { get; set; }
/// <summary>
/// 组合无功1平电能
/// </summary>
[Property(72, 4, PropertyReadConstant.Byte)]
public float GroupNoFlat1 { get; set; }
/// <summary>
/// 组合无功1谷电能
/// </summary>
[Property(76, 4, PropertyReadConstant.Byte)]
public float GroupNoValley1 { get; set; }
/// <summary>
/// 组合无功2总电能
/// </summary>
[Property(80, 4, PropertyReadConstant.Byte)]
public float GroupNoAll2 { get; set; }
/// <summary>
/// 组合无功2尖电能
/// </summary>
[Property(84, 4, PropertyReadConstant.Byte)]
public float GroupNoTip2 { get; set; }
/// <summary>
/// 组合无功2峰电能
/// </summary>
[Property(88, 4, PropertyReadConstant.Byte)]
public float GroupNoPeak2 { get; set; }
/// <summary>
/// 组合无功2平电能
/// </summary>
[Property(92, 4, PropertyReadConstant.Byte)]
public float GroupNoFlat2 { get; set; }
/// <summary>
/// 组合无功2谷电能
/// </summary>
[Property(96, 4, PropertyReadConstant.Byte)]
public float GroupNoValley2 { get; set; }
/// <summary>
/// 一象限无功总电能
/// </summary>
[Property(100, 4, PropertyReadConstant.Byte)]
public float QuadrantNoAll1 { get; set; }
/// <summary>
/// 一象限无功尖电能
/// </summary>
[Property(104, 4, PropertyReadConstant.Byte)]
public float QuadrantNoTip1 { get; set; }
/// <summary>
/// 一象限无功峰电能
/// </summary>
[Property(108, 4, PropertyReadConstant.Byte)]
public float QuadrantNoPeak1 { get; set; }
/// <summary>
/// 一象限无功平电能
/// </summary>
[Property(112, 4, PropertyReadConstant.Byte)]
public float QuadrantNoFlat1 { get; set; }
/// <summary>
/// 一象限无功谷电能
/// </summary>
[Property(116, 4, PropertyReadConstant.Byte)]
public float QuadrantNoValley1 { get; set; }
/// <summary>
/// 二象限无功总电能
/// </summary>
[Property(120, 4, PropertyReadConstant.Byte)]
public float QuadrantNoAll2 { get; set; }
/// <summary>
/// 二象限无功尖电能
/// </summary>
[Property(124, 4, PropertyReadConstant.Byte)]
public float QuadrantNoTip2 { get; set; }
/// <summary>
/// 二象限无功峰电能
/// </summary>
[Property(128, 4, PropertyReadConstant.Byte)]
public float QuadrantNoPeak2 { get; set; }
/// <summary>
/// 二象限无功平电能
/// </summary>
[Property(132, 4, PropertyReadConstant.Byte)]
public float QuadrantNoFlat2 { get; set; }
/// <summary>
/// 二象限无功谷电能
/// </summary>
[Property(136, 4, PropertyReadConstant.Byte)]
public float QuadrantNoValley2 { get; set; }
/// <summary>
/// 三象限无功总电能
/// </summary>
[Property(140, 4, PropertyReadConstant.Byte)]
public float QuadrantNoAll3 { get; set; }
/// <summary>
/// 三象限无功尖电能
/// </summary>
[Property(144, 4, PropertyReadConstant.Byte)]
public float QuadrantNoTip3 { get; set; }
/// <summary>
/// 三象限无功峰电能
/// </summary>
[Property(148, 4, PropertyReadConstant.Byte)]
public float QuadrantNoPeak3 { get; set; }
/// <summary>
/// 三象限无功平电能
/// </summary>
[Property(152, 4, PropertyReadConstant.Byte)]
public float QuadrantNoFlat3 { get; set; }
/// <summary>
/// 三象限无功谷电能
/// </summary>
[Property(156, 4, PropertyReadConstant.Byte)]
public float QuadrantNoValley3 { get; set; }
/// <summary>
/// 四象限无功总电能
/// </summary>
[Property(160, 4, PropertyReadConstant.Byte)]
public float QuadrantNoAll4 { get; set; }
/// <summary>
/// 四象限无功尖电能
/// </summary>
[Property(164, 4, PropertyReadConstant.Byte)]
public float QuadrantNoTip4 { get; set; }
/// <summary>
/// 四象限无功峰电能
/// </summary>
[Property(168, 4, PropertyReadConstant.Byte)]
public float QuadrantNoPeak4 { get; set; }
/// <summary>
/// 四象限无功平电能
/// </summary>
[Property(172, 4, PropertyReadConstant.Byte)]
public float QuadrantNoFlat4 { get; set; }
/// <summary>
/// 四象限无功谷电能
/// </summary>
[Property(176, 4, PropertyReadConstant.Byte)]
public float QuadrantNoValley4 { get; set; }
/// <summary>
/// 正向视在总电能
/// </summary>
[Property(180, 4, PropertyReadConstant.Byte)]
public float ForwardHaveApparentAll { get; set; }
/// <summary>
/// 正向视在尖电能
/// </summary>
[Property(184, 4, PropertyReadConstant.Byte)]
public float ForwardHaveApparentTip { get; set; }
/// <summary>
/// 正向视在峰电能
/// </summary>
[Property(188, 4, PropertyReadConstant.Byte)]
public float ForwardHaveApparentPeak { get; set; }
/// <summary>
/// 正向视在平电能
/// </summary>
[Property(192, 4, PropertyReadConstant.Byte)]
public float ForwardHaveApparentFlat { get; set; }
/// <summary>
/// 正向视在谷电能
/// </summary>
[Property(196, 4, PropertyReadConstant.Byte)]
public float ForwardHaveApparentValley { get; set; }
/// <summary>
/// 反向视在总电能
/// </summary>
[Property(200, 4, PropertyReadConstant.Byte)]
public float ReverseHaveApparentAll { get; set; }
/// <summary>
/// 反向视在尖电能
/// </summary>
[Property(204, 4, PropertyReadConstant.Byte)]
public float ReverseHaveApparentTip { get; set; }
/// <summary>
/// 反向视在峰电能
/// </summary>
[Property(208, 4, PropertyReadConstant.Byte)]
public float ReverseHaveApparentPeak { get; set; }
/// <summary>
/// 反向视在平电能
/// </summary>
[Property(212, 4, PropertyReadConstant.Byte)]
public float ReverseHaveApparentFlat { get; set; }
/// <summary>
/// 反向视在谷电能
/// </summary>
[Property(216, 4, PropertyReadConstant.Byte)]
public float ReverseHaveApparentValley { get; set; }
}
}

File diff suppressed because it is too large Load Diff

@ -2,7 +2,11 @@
using HslCommunication.Core.Address;
using HslCommunication.ModBus;
using HybirdFrameworkCore.Utils;
using HybirdFrameworkDriver.ModbusTcpMaster;
using HybirdFrameworkDriver.TcpServer;
using HybirdFrameworkServices.Init.Entity;
using HybirdFrameworkServices.Plc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -13,6 +17,7 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static StackExchange.Redis.Role;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
namespace WinFormStarter
@ -50,15 +55,14 @@ namespace WinFormStarter
}
#endregion
PlcReadAndWritten PlcReadAndWritten;
PlcReadonly PlcReadonly;
PlcTurnsRatio PlcTurnsRatio;
PlcDate PlcDate = new PlcDate();
public FrmPLCConnect()
{
InitializeComponent();
}
#region 连接
private void BtnConnect_Click(object sender, EventArgs e)
{
//简单判断
@ -90,203 +94,555 @@ namespace WinFormStarter
LblConState.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "连接失败";
}
}
#endregion
#region 读取
private void BtnCollectionAssignment_Click(object sender, EventArgs e)
{
OperateResult<byte[]> read1 = _client.Read("x=3;100", 164);
OperateResult<byte[]> read2 = _client.Read("x=3;39424", 110);
OperateResult<byte[]> read3 = _client.Read("x=3;40960", 18);
PlcReadAndWritten = ModelConvert.Decode<PlcReadAndWritten>(read1.Content);
PlcReadonly = ModelConvert.Decode<PlcReadonly>(read1.Content);
PlcTurnsRatio = ModelConvert.Decode<PlcTurnsRatio>(read1.Content);
textBox1.Text = PlcReadAndWritten.ProgrammingEnable.ToString();
textBox2.Text = PlcReadAndWritten.Modbus1Addres.ToString();
textBox3.Text = PlcReadAndWritten.BaudRate.ToString();
textBox4.Text = PlcReadAndWritten.CheckBit.ToString();
textBox5.Text = PlcReadAndWritten.Seconds.ToString();
textBox6.Text = PlcReadAndWritten.Points.ToString();
textBox7.Text = PlcReadAndWritten.When.ToString();
textBox8.Text = PlcReadAndWritten.Weeks.ToString();
textBox9.Text = PlcReadAndWritten.Day.ToString();
textBox10.Text = PlcReadAndWritten.Month.ToString();
textBox11.Text = PlcReadAndWritten.Years.ToString();
textBox12.Text = PlcReadAndWritten.Modbus1Addres2.ToString();
textBox13.Text = PlcReadAndWritten.Reserve.ToString();
textBox14.Text = PlcReadAndWritten.VoltageRatio.ToString();
textBox17.Text = PlcReadAndWritten.CurrentRatio.ToString();
textBox18.Text = PlcReadAndWritten.PulsePerSecond.ToString();
textBox19.Text = PlcReadAndWritten.CurrentReversal.ToString();
textBox20.Text = PlcReadAndWritten.MeterReset.ToString();
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo==null)
{
MessageBox.Show("PLC未连接");
return;
}
textBox1.Text = plcInfo.PlcReadAndWritten1.ProgrammingEnable.ToString();
textBox2.Text = plcInfo.PlcReadAndWritten1.Modbus1Addres.ToString();
textBox3.Text = plcInfo.PlcReadAndWritten1.BaudRate.ToString();
textBox4.Text = plcInfo.PlcReadAndWritten1.CheckBit.ToString();
textBox5.Text = plcInfo.PlcReadAndWritten2.Seconds.ToString();
textBox6.Text = plcInfo.PlcReadAndWritten2.Points.ToString();
textBox7.Text = plcInfo.PlcReadAndWritten2.When.ToString();
textBox8.Text = plcInfo.PlcReadAndWritten2.Weeks.ToString();
textBox9.Text = plcInfo.PlcReadAndWritten2.Day.ToString();
textBox10.Text = plcInfo.PlcReadAndWritten2.Month.ToString();
textBox11.Text = plcInfo.PlcReadAndWritten2.Years.ToString();
textBox12.Text = plcInfo.PlcReadAndWritten2.Modbus1Addres2.ToString();
textBox13.Text = plcInfo.PlcReadAndWritten2.Reserve.ToString();
textBox14.Text = plcInfo.PlcReadAndWritten2.VoltageRatio.ToString();
textBox15.Text = plcInfo.PlcReadAndWritten2.CurrentRatio.ToString();
textBox16.Text = plcInfo.PlcReadAndWritten1.PulsePerSecond.ToString();
textBox17.Text = plcInfo.PlcReadAndWritten1.CurrentReversal.ToString();
textBox18.Text = plcInfo.PlcReadAndWritten1.MeterReset.ToString();
string datetime = plcInfo.PlcReadAndWritten2.Years + "-" +
plcInfo.PlcReadAndWritten2.Month + "-" +
plcInfo.PlcReadAndWritten2.Day + " " +
plcInfo.PlcReadAndWritten2.When + ":" +
plcInfo.PlcReadAndWritten2.Points + ":" +
plcInfo.PlcReadAndWritten2.Seconds;
}
#endregion
#region 切换数据
bool now;
private void BtnToggle_Click(object sender, EventArgs e)
{
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
now = !now;
if (now)
{
#region
label31.Text = PlcReadonly.GroupHaveAll.ToString();
label29.Text = PlcReadonly.GroupHaveTip.ToString();
label27.Text = PlcReadonly.GroupHavePeak.ToString();
label25.Text = PlcReadonly.GroupHaveFlat.ToString();
label19.Text = PlcReadonly.GroupHaveValley.ToString();
label40.Text = PlcReadonly.ForwardHaveAll.ToString();
label38.Text = PlcReadonly.ForwardHaveTip.ToString();
label36.Text = PlcReadonly.ForwardHavePeak.ToString();
label34.Text = PlcReadonly.ForwardHaveFlat.ToString();
label32.Text = PlcReadonly.ForwardHaveValley.ToString();
label50.Text = PlcReadonly.ReverseHaveAll.ToString();
label48.Text = PlcReadonly.ReverseHaveTip.ToString();
label46.Text = PlcReadonly.ReverseHavePeak.ToString();
label44.Text = PlcReadonly.ReverseHaveFlat.ToString();
label42.Text = PlcReadonly.ReverseHaveValley.ToString();
label60.Text = PlcReadonly.GroupNoAll1.ToString();
label58.Text = PlcReadonly.GroupNoTip1.ToString();
label56.Text = PlcReadonly.GroupNoPeak1.ToString();
label54.Text = PlcReadonly.GroupNoFlat1.ToString();
label52.Text = PlcReadonly.GroupNoValley1.ToString();
label70.Text = PlcReadonly.GroupNoAll2.ToString();
label68.Text = PlcReadonly.GroupNoTip2.ToString();
label66.Text = PlcReadonly.GroupNoPeak2.ToString();
label64.Text = PlcReadonly.GroupNoFlat2.ToString();
label62.Text = PlcReadonly.GroupNoValley2.ToString();
label80.Text = PlcReadonly.QuadrantNoAll1.ToString();
label78.Text = PlcReadonly.QuadrantNoTip1.ToString();
label76.Text = PlcReadonly.QuadrantNoPeak1.ToString();
label74.Text = PlcReadonly.QuadrantNoFlat1.ToString();
label72.Text = PlcReadonly.QuadrantNoValley1.ToString();
label90.Text = PlcReadonly.QuadrantNoAll2.ToString();
label88.Text = PlcReadonly.QuadrantNoTip2.ToString();
label86.Text = PlcReadonly.QuadrantNoPeak2.ToString();
label84.Text = PlcReadonly.QuadrantNoFlat2.ToString();
label82.Text = PlcReadonly.QuadrantNoValley2.ToString();
label100.Text = PlcReadonly.QuadrantNoAll3.ToString();
label98.Text = PlcReadonly.QuadrantNoTip3.ToString();
label96.Text = PlcReadonly.QuadrantNoPeak3.ToString();
label94.Text = PlcReadonly.QuadrantNoFlat3.ToString();
label92.Text = PlcReadonly.QuadrantNoValley3.ToString();
label110.Text = PlcReadonly.QuadrantNoAll4.ToString();
label108.Text = PlcReadonly.QuadrantNoTip4.ToString();
label106.Text = PlcReadonly.QuadrantNoPeak4.ToString();
label104.Text = PlcReadonly.QuadrantNoFlat4.ToString();
label102.Text = PlcReadonly.QuadrantNoValley4.ToString();
label120.Text = PlcReadonly.ForwardHaveApparentAll.ToString();
label118.Text = PlcReadonly.ForwardHaveApparentTip.ToString();
label116.Text = PlcReadonly.ForwardHaveApparentPeak.ToString();
label114.Text = PlcReadonly.ForwardHaveApparentFlat.ToString();
label112.Text = PlcReadonly.ForwardHaveApparentValley.ToString();
label130.Text = PlcReadonly.ReverseHaveApparentAll.ToString();
label128.Text = PlcReadonly.ReverseHaveApparentTip.ToString();
label126.Text = PlcReadonly.ReverseHaveApparentPeak.ToString();
label124.Text = PlcReadonly.ReverseHaveApparentFlat.ToString();
label122.Text = PlcReadonly.ReverseHaveApparentValley.ToString();
label140.Text = PlcReadonly.PhaseVoltageA.ToString();
label138.Text = PlcReadonly.PhaseVoltageB.ToString();
label136.Text = PlcReadonly.PhaseVoltageC.ToString();
label134.Text = PlcReadonly.PhaseElectricityA.ToString();
label132.Text = PlcReadonly.PhaseElectricityB.ToString();
label172.Text = PlcReadonly.PhaseElectricityC.ToString();
label150.Text = PlcReadonly.TotalActivePower.ToString();
label148.Text = PlcReadonly.TotalActivePowerA.ToString();
label146.Text = PlcReadonly.TotalActivePowerB.ToString();
label144.Text = PlcReadonly.TotalActivePowerC.ToString();
label160.Text = PlcReadonly.TotalReactivePower.ToString();
label158.Text = PlcReadonly.TotalReactivePowerA.ToString();
label156.Text = PlcReadonly.TotalReactivePowerB.ToString();
label144.Text = PlcReadonly.TotalReactivePowerC.ToString();
label170.Text = PlcReadonly.TotalApparentPower.ToString();
label168.Text = PlcReadonly.TotalApparentPowerA.ToString();
label166.Text = PlcReadonly.TotalApparentPowerB.ToString();
label164.Text = PlcReadonly.TotalApparentPowerC.ToString();
label192.Text = PlcReadonly.OverallPowerFactor.ToString();
label190.Text = PlcReadonly.OverallPowerFactorA.ToString();
label188.Text = PlcReadonly.OverallPowerFactorB.ToString();
label184.Text = PlcReadonly.OverallPowerFactorC.ToString();
label174.Text = PlcReadonly.PhaseAngleA.ToString();
label162.Text = PlcReadonly.PhaseAngleB.ToString();
label152.Text = PlcReadonly.PhaseAngleC.ToString();
label142.Text = PlcReadonly.LineFrequency.ToString();
label184.Text = PlcReadonly.PhaseLineVoltageA.ToString();
label182.Text = PlcReadonly.PhaseLineVoltageB.ToString();
label180.Text = PlcReadonly.PhaseLineVoltageC.ToString();
label178.Text = PlcReadonly.ThreePhaseMeanLineVoltage.ToString();
label176.Text = PlcReadonly.ThreePhaseMeanPhaseVoltage.ToString();
label31.Text = plcInfo.PlcReadonly.GroupHaveAll.ToString();
label29.Text = plcInfo.PlcReadonly.GroupHaveTip.ToString();
label27.Text = plcInfo.PlcReadonly.GroupHavePeak.ToString();
label25.Text = plcInfo.PlcReadonly.GroupHaveFlat.ToString();
label19.Text = plcInfo.PlcReadonly.GroupHaveValley.ToString();
label40.Text = plcInfo.PlcReadonly.ForwardHaveAll.ToString();
label38.Text = plcInfo.PlcReadonly.ForwardHaveTip.ToString();
label36.Text = plcInfo.PlcReadonly.ForwardHavePeak.ToString();
label34.Text = plcInfo.PlcReadonly.ForwardHaveFlat.ToString();
label32.Text = plcInfo.PlcReadonly.ForwardHaveValley.ToString();
label50.Text = plcInfo.PlcReadonly.ReverseHaveAll.ToString();
label48.Text = plcInfo.PlcReadonly.ReverseHaveTip.ToString();
label46.Text = plcInfo.PlcReadonly.ReverseHavePeak.ToString();
label44.Text = plcInfo.PlcReadonly.ReverseHaveFlat.ToString();
label42.Text = plcInfo.PlcReadonly.ReverseHaveValley.ToString();
label60.Text = plcInfo.PlcReadonly.GroupNoAll1.ToString();
label58.Text = plcInfo.PlcReadonly.GroupNoTip1.ToString();
label56.Text = plcInfo.PlcReadonly.GroupNoPeak1.ToString();
label54.Text = plcInfo.PlcReadonly.GroupNoFlat1.ToString();
label52.Text = plcInfo.PlcReadonly.GroupNoValley1.ToString();
label70.Text = plcInfo.PlcReadonly.GroupNoAll2.ToString();
label68.Text = plcInfo.PlcReadonly.GroupNoTip2.ToString();
label66.Text = plcInfo.PlcReadonly.GroupNoPeak2.ToString();
label64.Text = plcInfo.PlcReadonly.GroupNoFlat2.ToString();
label62.Text = plcInfo.PlcReadonly.GroupNoValley2.ToString();
label80.Text = plcInfo.PlcReadonly.QuadrantNoAll1.ToString();
label78.Text = plcInfo.PlcReadonly.QuadrantNoTip1.ToString();
label76.Text = plcInfo.PlcReadonly.QuadrantNoPeak1.ToString();
label74.Text = plcInfo.PlcReadonly.QuadrantNoFlat1.ToString();
label72.Text = plcInfo.PlcReadonly.QuadrantNoValley1.ToString();
label90.Text = plcInfo.PlcReadonly.QuadrantNoAll2.ToString();
label88.Text = plcInfo.PlcReadonly.QuadrantNoTip2.ToString();
label86.Text = plcInfo.PlcReadonly.QuadrantNoPeak2.ToString();
label84.Text = plcInfo.PlcReadonly.QuadrantNoFlat2.ToString();
label82.Text = plcInfo.PlcReadonly.QuadrantNoValley2.ToString();
label100.Text = plcInfo.PlcReadonly.QuadrantNoAll3.ToString();
label98.Text = plcInfo.PlcReadonly.QuadrantNoTip3.ToString();
label96.Text = plcInfo.PlcReadonly.QuadrantNoPeak3.ToString();
label94.Text = plcInfo.PlcReadonly.QuadrantNoFlat3.ToString();
label92.Text = plcInfo.PlcReadonly.QuadrantNoValley3.ToString();
label110.Text = plcInfo.PlcReadonly.QuadrantNoAll4.ToString();
label108.Text = plcInfo.PlcReadonly.QuadrantNoTip4.ToString();
label106.Text = plcInfo.PlcReadonly.QuadrantNoPeak4.ToString();
label104.Text = plcInfo.PlcReadonly.QuadrantNoFlat4.ToString();
label102.Text = plcInfo.PlcReadonly.QuadrantNoValley4.ToString();
label120.Text = plcInfo.PlcReadonly.ForwardHaveApparentAll.ToString();
label118.Text = plcInfo.PlcReadonly.ForwardHaveApparentTip.ToString();
label116.Text = plcInfo.PlcReadonly.ForwardHaveApparentPeak.ToString();
label114.Text = plcInfo.PlcReadonly.ForwardHaveApparentFlat.ToString();
label112.Text = plcInfo.PlcReadonly.ForwardHaveApparentValley.ToString();
label130.Text = plcInfo.PlcReadonly.ReverseHaveApparentAll.ToString();
label128.Text = plcInfo.PlcReadonly.ReverseHaveApparentTip.ToString();
label126.Text = plcInfo.PlcReadonly.ReverseHaveApparentPeak.ToString();
label124.Text = plcInfo.PlcReadonly.ReverseHaveApparentFlat.ToString();
label122.Text = plcInfo.PlcReadonly.ReverseHaveApparentValley.ToString();
label140.Text = plcInfo.PlcReadonly.PhaseVoltageA.ToString();
label138.Text = plcInfo.PlcReadonly.PhaseVoltageB.ToString();
label136.Text = plcInfo.PlcReadonly.PhaseVoltageC.ToString();
label134.Text = plcInfo.PlcReadonly.PhaseElectricityA.ToString();
label132.Text = plcInfo.PlcReadonly.PhaseElectricityB.ToString();
label172.Text = plcInfo.PlcReadonly.PhaseElectricityC.ToString();
label150.Text = plcInfo.PlcReadonly.TotalActivePower.ToString();
label148.Text = plcInfo.PlcReadonly.TotalActivePowerA.ToString();
label146.Text = plcInfo.PlcReadonly.TotalActivePowerB.ToString();
label144.Text = plcInfo.PlcReadonly.TotalActivePowerC.ToString();
label160.Text = plcInfo.PlcReadonly.TotalReactivePower.ToString();
label158.Text = plcInfo.PlcReadonly.TotalReactivePowerA.ToString();
label156.Text = plcInfo.PlcReadonly.TotalReactivePowerB.ToString();
label144.Text = plcInfo.PlcReadonly.TotalReactivePowerC.ToString();
label170.Text = plcInfo.PlcReadonly.TotalApparentPower.ToString();
label168.Text = plcInfo.PlcReadonly.TotalApparentPowerA.ToString();
label166.Text = plcInfo.PlcReadonly.TotalApparentPowerB.ToString();
label164.Text = plcInfo.PlcReadonly.TotalApparentPowerC.ToString();
label192.Text = plcInfo.PlcReadonly.OverallPowerFactor.ToString();
label190.Text = plcInfo.PlcReadonly.OverallPowerFactorA.ToString();
label188.Text = plcInfo.PlcReadonly.OverallPowerFactorB.ToString();
label184.Text = plcInfo.PlcReadonly.OverallPowerFactorC.ToString();
label174.Text = plcInfo.PlcReadonly.PhaseAngleA.ToString();
label162.Text = plcInfo.PlcReadonly.PhaseAngleB.ToString();
label152.Text = plcInfo.PlcReadonly.PhaseAngleC.ToString();
label142.Text = plcInfo.PlcReadonly.LineFrequency.ToString();
label184.Text = plcInfo.PlcReadonly.PhaseLineVoltageA.ToString();
label182.Text = plcInfo.PlcReadonly.PhaseLineVoltageB.ToString();
label180.Text = plcInfo.PlcReadonly.PhaseLineVoltageC.ToString();
label178.Text = plcInfo.PlcReadonly.ThreePhaseMeanLineVoltage.ToString();
label176.Text = plcInfo.PlcReadonly.ThreePhaseMeanPhaseVoltage.ToString();
#endregion
}
if (now)
{
#region
label31.Text = PlcTurnsRatio.GroupHaveAll.ToString();
label29.Text = PlcTurnsRatio.GroupHaveTip.ToString();
label27.Text = PlcTurnsRatio.GroupHavePeak.ToString();
label25.Text = PlcTurnsRatio.GroupHaveFlat.ToString();
label19.Text = PlcTurnsRatio.GroupHaveValley.ToString();
label40.Text = PlcTurnsRatio.ForwardHaveAll.ToString();
label38.Text = PlcTurnsRatio.ForwardHaveTip.ToString();
label36.Text = PlcTurnsRatio.ForwardHavePeak.ToString();
label34.Text = PlcTurnsRatio.ForwardHaveFlat.ToString();
label32.Text = PlcTurnsRatio.ForwardHaveValley.ToString();
label50.Text = PlcTurnsRatio.ReverseHaveAll.ToString();
label48.Text = PlcTurnsRatio.ReverseHaveTip.ToString();
label46.Text = PlcTurnsRatio.ReverseHavePeak.ToString();
label44.Text = PlcTurnsRatio.ReverseHaveFlat.ToString();
label42.Text = PlcTurnsRatio.ReverseHaveValley.ToString();
label60.Text = PlcTurnsRatio.GroupNoAll1.ToString();
label58.Text = PlcTurnsRatio.GroupNoTip1.ToString();
label56.Text = PlcTurnsRatio.GroupNoPeak1.ToString();
label54.Text = PlcTurnsRatio.GroupNoFlat1.ToString();
label52.Text = PlcTurnsRatio.GroupNoValley1.ToString();
label70.Text = PlcTurnsRatio.GroupNoAll2.ToString();
label68.Text = PlcTurnsRatio.GroupNoTip2.ToString();
label66.Text = PlcTurnsRatio.GroupNoPeak2.ToString();
label64.Text = PlcTurnsRatio.GroupNoFlat2.ToString();
label62.Text = PlcTurnsRatio.GroupNoValley2.ToString();
label80.Text = PlcTurnsRatio.QuadrantNoAll1.ToString();
label78.Text = PlcTurnsRatio.QuadrantNoTip1.ToString();
label76.Text = PlcTurnsRatio.QuadrantNoPeak1.ToString();
label74.Text = PlcTurnsRatio.QuadrantNoFlat1.ToString();
label72.Text = PlcTurnsRatio.QuadrantNoValley1.ToString();
label90.Text = PlcTurnsRatio.QuadrantNoAll2.ToString();
label88.Text = PlcTurnsRatio.QuadrantNoTip2.ToString();
label86.Text = PlcTurnsRatio.QuadrantNoPeak2.ToString();
label84.Text = PlcTurnsRatio.QuadrantNoFlat2.ToString();
label82.Text = PlcTurnsRatio.QuadrantNoValley2.ToString();
label100.Text = PlcTurnsRatio.QuadrantNoAll3.ToString();
label98.Text = PlcTurnsRatio.QuadrantNoTip3.ToString();
label96.Text = PlcTurnsRatio.QuadrantNoPeak3.ToString();
label94.Text = PlcTurnsRatio.QuadrantNoFlat3.ToString();
label92.Text = PlcTurnsRatio.QuadrantNoValley3.ToString();
label110.Text = PlcTurnsRatio.QuadrantNoAll4.ToString();
label108.Text = PlcTurnsRatio.QuadrantNoTip4.ToString();
label106.Text = PlcTurnsRatio.QuadrantNoPeak4.ToString();
label104.Text = PlcTurnsRatio.QuadrantNoFlat4.ToString();
label102.Text = PlcTurnsRatio.QuadrantNoValley4.ToString();
label120.Text = PlcTurnsRatio.ForwardHaveApparentAll.ToString();
label118.Text = PlcTurnsRatio.ForwardHaveApparentTip.ToString();
label116.Text = PlcTurnsRatio.ForwardHaveApparentPeak.ToString();
label114.Text = PlcTurnsRatio.ForwardHaveApparentFlat.ToString();
label112.Text = PlcTurnsRatio.ForwardHaveApparentValley.ToString();
label130.Text = PlcTurnsRatio.ReverseHaveApparentAll.ToString();
label128.Text = PlcTurnsRatio.ReverseHaveApparentTip.ToString();
label126.Text = PlcTurnsRatio.ReverseHaveApparentPeak.ToString();
label124.Text = PlcTurnsRatio.ReverseHaveApparentFlat.ToString();
label122.Text = PlcTurnsRatio.ReverseHaveApparentValley.ToString();
label31.Text = plcInfo.PlcTurnsRatio.GroupHaveAll.ToString();
label29.Text = plcInfo.PlcTurnsRatio.GroupHaveTip.ToString();
label27.Text = plcInfo.PlcTurnsRatio.GroupHavePeak.ToString();
label25.Text = plcInfo.PlcTurnsRatio.GroupHaveFlat.ToString();
label19.Text = plcInfo.PlcTurnsRatio.GroupHaveValley.ToString();
label40.Text = plcInfo.PlcTurnsRatio.ForwardHaveAll.ToString();
label38.Text = plcInfo.PlcTurnsRatio.ForwardHaveTip.ToString();
label36.Text = plcInfo.PlcTurnsRatio.ForwardHavePeak.ToString();
label34.Text = plcInfo.PlcTurnsRatio.ForwardHaveFlat.ToString();
label32.Text = plcInfo.PlcTurnsRatio.ForwardHaveValley.ToString();
label50.Text = plcInfo.PlcTurnsRatio.ReverseHaveAll.ToString();
label48.Text = plcInfo.PlcTurnsRatio.ReverseHaveTip.ToString();
label46.Text = plcInfo.PlcTurnsRatio.ReverseHavePeak.ToString();
label44.Text = plcInfo.PlcTurnsRatio.ReverseHaveFlat.ToString();
label42.Text = plcInfo.PlcTurnsRatio.ReverseHaveValley.ToString();
label60.Text = plcInfo.PlcTurnsRatio.GroupNoAll1.ToString();
label58.Text = plcInfo.PlcTurnsRatio.GroupNoTip1.ToString();
label56.Text = plcInfo.PlcTurnsRatio.GroupNoPeak1.ToString();
label54.Text = plcInfo.PlcTurnsRatio.GroupNoFlat1.ToString();
label52.Text = plcInfo.PlcTurnsRatio.GroupNoValley1.ToString();
label70.Text = plcInfo.PlcTurnsRatio.GroupNoAll2.ToString();
label68.Text = plcInfo.PlcTurnsRatio.GroupNoTip2.ToString();
label66.Text = plcInfo.PlcTurnsRatio.GroupNoPeak2.ToString();
label64.Text = plcInfo.PlcTurnsRatio.GroupNoFlat2.ToString();
label62.Text = plcInfo.PlcTurnsRatio.GroupNoValley2.ToString();
label80.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll1.ToString();
label78.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip1.ToString();
label76.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak1.ToString();
label74.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat1.ToString();
label72.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley1.ToString();
label90.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll2.ToString();
label88.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip2.ToString();
label86.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak2.ToString();
label84.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat2.ToString();
label82.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley2.ToString();
label100.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll3.ToString();
label98.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip3.ToString();
label96.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak3.ToString();
label94.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat3.ToString();
label92.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley3.ToString();
label110.Text = plcInfo.PlcTurnsRatio.QuadrantNoAll4.ToString();
label108.Text = plcInfo.PlcTurnsRatio.QuadrantNoTip4.ToString();
label106.Text = plcInfo.PlcTurnsRatio.QuadrantNoPeak4.ToString();
label104.Text = plcInfo.PlcTurnsRatio.QuadrantNoFlat4.ToString();
label102.Text = plcInfo.PlcTurnsRatio.QuadrantNoValley4.ToString();
label120.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentAll.ToString();
label118.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentTip.ToString();
label116.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentPeak.ToString();
label114.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentFlat.ToString();
label112.Text = plcInfo.PlcTurnsRatio.ForwardHaveApparentValley.ToString();
label130.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentAll.ToString();
label128.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentTip.ToString();
label126.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentPeak.ToString();
label124.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentFlat.ToString();
label122.Text = plcInfo.PlcTurnsRatio.ReverseHaveApparentValley.ToString();
#endregion
}
}
//TODO::没有数据写入,稍后添加
#endregion
#region 方法
#endregion 写入方法
private void BtnWrite01_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox1.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if(plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult=session.Write<UInt16>(PlcDate.ProgrammingEnable);
}
private void BtnWrite02_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox2.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Modbus1Addres);
}
private void BtnWrite03_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox3.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.BaudRate);
}
private void BtnWrite04_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox4.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.CheckBit);
}
private void BtnWrite05_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox5.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Seconds);
}
private void BtnWrite06_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox6.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Points);
}
private void BtnWrite07_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox7.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.When);
}
private void BtnWrite08_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox8.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Weeks);
}
private void BtnWrite09_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox9.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Day);
}
private void BtnWrite10_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox10.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Month);
}
private void BtnWrite11_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox11.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Years);
}
private void BtnWrite12_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox12.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Modbus1Addres2);
}
private void BtnWrite13_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox13.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.Reserve);
}
private void BtnWrite14_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox14.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.VoltageRatio);
}
private void BtnWrite15_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox15.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.CurrentRatio);
}
private void BtnWrite16_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox16.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.PulsePerSecond);
}
private void BtnWrite17_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox15.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.CurrentReversal);
}
private void BtnWrite18_Click(object sender, EventArgs e)
{
bool bConvert = int.TryParse(this.textBox16.Text, out int iValue);
if (!bConvert)
{
MessageBox.Show("请输入有效值");
return;
}
ChargerStaticInfo.PlcInfos.TryGetValue(1, out PlcInfo plcInfo);
if (plcInfo == null)
{
MessageBox.Show("PLC未连接");
return;
}
ModbusSession session = SessionMgr.GetModbusSession(plcInfo.ChannelId);
bool bResult = session.Write<UInt16>(PlcDate.MeterReset);
}
#region 进制数据转换
#endregion
}
}

@ -1,6 +1,7 @@
using Autofac;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Configuration;
using HybirdFrameworkServices;
using log4net.Config;
using SqlSugar;
using SqlSugar.IOC;
@ -50,7 +51,10 @@ static class Program
// 构建容器
Container = builder.Build();
AppInfo.Container = Container.BeginLifetimeScope("root");
EquipmentInit equipmentInit = AppInfo.Container.Resolve<EquipmentInit>();
equipmentInit.Connect();
Application.Run(AppInfo.Container.ResolveNamed<Form>("Form2"));
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs ex)

@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>

@ -0,0 +1,21 @@

保持型x=4:30000
输入型x=3:40000
线圈:
线圈寄存器:
离散输入寄存器:
寄存器:
输入寄存器
保持寄存器:
功能码 描述 说明 MOUBUS地址 异常功能码(+ 0×80)
1 读取输出线圈 位操作 00001 ~ 09999 0×81
2 读取输入线圈 位操作 10001 ~ 19999 0×82
3 读取输出寄存器 字操作 40001 ~ 49999 0×83
4 读取输入寄存器 字操作 30001 ~ 39999 0×84
5 写入单个输出线圈 位操作 00001 ~ 09999 0×85
6 写入单个输出寄存器 字操作 40001 ~ 49999 0×86
OF 写入多个输出线圈 位搡作 00001 ~ 09999 Ox8F
10 写入多个输出寄存器 字操作 40001 ~ 49999 0×90
Loading…
Cancel
Save