diff --git a/Module.Ups.ModBusTcp/Common/BitsConvertUtils.cs b/Module.Ups.ModBusTcp/Common/BitsConvertUtils.cs index bafd97a..fb25c99 100644 --- a/Module.Ups.ModBusTcp/Common/BitsConvertUtils.cs +++ b/Module.Ups.ModBusTcp/Common/BitsConvertUtils.cs @@ -58,5 +58,12 @@ namespace Module.UpsEqm.ModBusTcp } return strResult; } + + + + public static bool GetBitValue(byte value, byte bit) + { + return (value & (byte)Math.Pow(2, bit)) > 0 ? true : false; + } } } diff --git a/Module.Ups.ModBusTcp/Common/CmnUpsBaseInfo.cs b/Module.Ups.ModBusTcp/Common/CmnUpsBaseInfo.cs index 10d7082..22301e7 100644 --- a/Module.Ups.ModBusTcp/Common/CmnUpsBaseInfo.cs +++ b/Module.Ups.ModBusTcp/Common/CmnUpsBaseInfo.cs @@ -1,4 +1,5 @@ -using System; +using Module.UpsEqm.ModBusTcp.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -17,5 +18,6 @@ namespace Module.UpsEqm.ModBusTcp /// public static UpsModbusTool UPS01 = new UpsModbusTool("172.0.50.102", 502, 6, "U001"); #endregion 基础字段 + public static UpsPageShowInfo upsPageShowInfo = new UpsPageShowInfo(); } } diff --git a/Module.Ups.ModBusTcp/Manager/UpsModbusTool.cs b/Module.Ups.ModBusTcp/Manager/UpsModbusTool.cs index 9cead7e..286c3a1 100644 --- a/Module.Ups.ModBusTcp/Manager/UpsModbusTool.cs +++ b/Module.Ups.ModBusTcp/Manager/UpsModbusTool.cs @@ -439,6 +439,9 @@ namespace Module.UpsEqm.ModBusTcp _ups_param_value.F_UpsID = _client.ByteTransform.TransUInt16(results, 30); _ups_param_value.F_ProtocolNumber = _client.ByteTransform.TransUInt16(results, 32); _ups_param_value.F_UpsVersion = _client.ByteTransform.TransUInt16(results, 34); + + CmnUpsBaseInfo.upsPageShowInfo.upsType = _ups_param_value.F_UpsName; + CmnUpsBaseInfo.upsPageShowInfo.upsVersion = _ups_param_value.F_UpsVersion; } //状态信息 @@ -459,6 +462,47 @@ namespace Module.UpsEqm.ModBusTcp _ups_param_value.F_UpsSystemModal = state_results[2]; } + //前端页面信息展示 + OperateResult upsStateInfoResult = _client.Read("x=3;96", 60); + if (upsStateInfoResult.IsSuccess) + { + byte[] config_results = upsStateInfoResult.Content; + //96 + CmnUpsBaseInfo.upsPageShowInfo.inputVolt = _client.ByteTransform.TransUInt16(config_results, 0); + //105 + CmnUpsBaseInfo.upsPageShowInfo.outputVolt = _client.ByteTransform.TransUInt16(config_results, 18); + //122 + CmnUpsBaseInfo.upsPageShowInfo.outPutLoadPct = _client.ByteTransform.TransUInt16(config_results, 52); + //103 + CmnUpsBaseInfo.upsPageShowInfo.inputFreq = _client.ByteTransform.TransUInt16(config_results, 14); + //124 + CmnUpsBaseInfo.upsPageShowInfo.batteryVolt = _client.ByteTransform.TransUInt16(config_results, 56); + //125 + CmnUpsBaseInfo.upsPageShowInfo.temp = _client.ByteTransform.TransUInt16(config_results, 58); + //111 + CmnUpsBaseInfo.upsPageShowInfo.tatedCurrent = _client.ByteTransform.TransUInt16(config_results, 30); + //123 + CmnUpsBaseInfo.upsPageShowInfo.batteryTotalVolt = _client.ByteTransform.TransUInt16(config_results, 54); + //134 + CmnUpsBaseInfo.upsPageShowInfo.frequency = _client.ByteTransform.TransUInt16(config_results, 76); + + } + //前端页面信息展示 + OperateResult upsInfoResult = _client.Read("x=3;30", 30); + if (upsInfoResult.IsSuccess) + { + byte[] state_results = upsInfoResult.Content; + //BitsConvertUtils + CmnUpsBaseInfo.upsPageShowInfo.mainsPowerFail = BitsConvertUtils.GetBitValue(state_results[41], 1); + CmnUpsBaseInfo.upsPageShowInfo.lowBatteryVolt = BitsConvertUtils.GetBitValue(state_results[41], 4); + CmnUpsBaseInfo.upsPageShowInfo.bypassVoltageStableModel = BitsConvertUtils.GetBitValue(state_results[1], 5); + CmnUpsBaseInfo.upsPageShowInfo.upsFault = BitsConvertUtils.GetBitValue(state_results[35], 4); + CmnUpsBaseInfo.upsPageShowInfo.systemTesting = BitsConvertUtils.GetBitValue(state_results[1], 9); + CmnUpsBaseInfo.upsPageShowInfo.remoteSystemShutdown = BitsConvertUtils.GetBitValue(state_results[1], 1); + CmnUpsBaseInfo.upsPageShowInfo.alarmSounOn = BitsConvertUtils.GetBitValue(state_results[1], 0); + + } + //配置数据 OperateResult configResult = _client.Read("x=3;160", 16); @@ -477,6 +521,8 @@ namespace Module.UpsEqm.ModBusTcp _ups_param_value.F_BatCellNumber = _client.ByteTransform.TransUInt16(config_results, 18); _ups_param_value.F_BatCellSeries = _client.ByteTransform.TransUInt16(config_results, 20); + + CmnUpsBaseInfo.upsPageShowInfo.ratedVolt = _ups_param_value.F_MainVoltage; } //故障信息 diff --git a/Module.Ups.ModBusTcp/Models/UpsPageShowInfo.cs b/Module.Ups.ModBusTcp/Models/UpsPageShowInfo.cs new file mode 100644 index 0000000..43dbe75 --- /dev/null +++ b/Module.Ups.ModBusTcp/Models/UpsPageShowInfo.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Module.UpsEqm.ModBusTcp.Models +{ + public class UpsPageShowInfo + { + /// + /// 更新时间 + /// + public string update { get; set; } + /// + /// UPS版本号: + /// + public ushort upsVersion { get; set; } + /// + /// UPS类型 + /// + public string upsType { get; set; } + /// + /// 输出电压R 0.1v + /// + public ushort outputVolt { get; set; } + /// + /// 输入电压R 0.1v + /// + public ushort inputVolt { get; set; } + /// + /// 输入频率 0.1HZ + /// + public ushort inputFreq { get; set; } + /// + /// O/P load负载百分比 16% + /// + public ushort outPutLoadPct { get; set; } + /// + /// 电池电压 + /// + public ushort batteryVolt { get; set; } + /// + /// 温度 + /// + public ushort temp { get; set; } + /// + /// 额定电源电压 + /// + public ushort ratedVolt { get; set; } + /// + /// 额定电流R + /// + public ushort tatedCurrent { get; set; } + /// + /// 电池单元格电压 + /// + public ushort batteryTotalVolt { get; set; } + /// + /// 输出频率 + /// + public ushort frequency { get; set; } + /// + /// 市电异常:旁路干线故障 + /// + public bool mainsPowerFail { get; set; } = false; + /// + /// 旁路/稳压模式 + /// + public bool bypassVoltageStableModel { get; set; } = false; + /// + /// 电池电压低 + /// + public bool lowBatteryVolt { get; set; } = false; + /// + /// UPS模块全故障 + /// + public bool upsFault { get; set; } = false; + /// + /// 电池自检中 + /// + public bool systemTesting { get; set; } = false; + /// + /// 关机模式 + /// + public bool remoteSystemShutdown { get; set; } = false; + /// + /// 电池模式下是否有蜂鸣器告警 + /// + public bool alarmSounOn { get; set; }=false; + } +} diff --git a/Monitor.EqmMgr.WebApi/Controllers/UpsEqmParamController.cs b/Monitor.EqmMgr.WebApi/Controllers/UpsEqmParamController.cs index e134b14..f4e7c01 100644 --- a/Monitor.EqmMgr.WebApi/Controllers/UpsEqmParamController.cs +++ b/Monitor.EqmMgr.WebApi/Controllers/UpsEqmParamController.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Mvc; +using Module.EMeter.ModbusTcp; using Module.UpsEqm.ModBusTcp; +using Module.UpsEqm.ModBusTcp.Models; namespace Monitor.EqmMgr.WebApi.Controllers { @@ -34,5 +36,40 @@ namespace Monitor.EqmMgr.WebApi.Controllers new UpsEqmManger().UpsNetReConnectThread(); } + /// + /// UPS前端页面展示信息类 + /// + /// + [HttpGet] + [Route("/api/[controller]/upsInfoShow")] + public UpsPageShowInfo UpsInfoShow() + { + CmnUpsBaseInfo.upsPageShowInfo.update = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); + return CmnUpsBaseInfo.upsPageShowInfo; + } + + + /// + /// UPS、电表连接状态展示 + /// + /// + [HttpGet] + [Route("/api/[controller]/eqipConnState")] + public List EqipConnState() + { + List list = new List + { + CmnUpsBaseInfo.UPS01.F_NetConnected, + CmnElecMeterBaseInfo.EBC01.F_NetConnected, + CmnElecMeterBaseInfo.EBC02.F_NetConnected, + CmnElecMeterBaseInfo.EBC03.F_NetConnected, + CmnElecMeterBaseInfo.EBC04.F_NetConnected, + CmnElecMeterBaseInfo.EBC05.F_NetConnected, + CmnElecMeterBaseInfo.EBC06.F_NetConnected, + CmnElecMeterBaseInfo.EBC07.F_NetConnected, + }; + return list; + } + } }