|
|
|
@ -3,6 +3,8 @@ using Admin.Core.Model.Model_New;
|
|
|
|
|
using Aucma.Core.DataCollector.Factory;
|
|
|
|
|
using Aucma.Core.HwPLc;
|
|
|
|
|
using log4net;
|
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -22,7 +24,7 @@ namespace Aucma.Core.DataCollector
|
|
|
|
|
public readonly IRecordDeviceAlarmInfoServices _deviceAlarmInfoServices;
|
|
|
|
|
public readonly IRecordDeviceElectricityServices _deviceElectricityServices;
|
|
|
|
|
|
|
|
|
|
public int AlarmReadTimer = (1000 * 20);
|
|
|
|
|
public int AlarmReadTimer = (1000 * 5);
|
|
|
|
|
public int EleReadTimer = (1000 * 20);
|
|
|
|
|
|
|
|
|
|
public DataCollectorFactory(IBaseDeviceParamServices deviceParamServices, IRecordDeviceAlarmInfoServices deviceAlarmInfoServices, IRecordDeviceElectricityServices deviceElectricityServices)
|
|
|
|
@ -52,23 +54,33 @@ namespace Aucma.Core.DataCollector
|
|
|
|
|
/// <param name="deviceElectricity"></param>
|
|
|
|
|
public void ReadDeviceElectricity(string[] address,IPlc plc,ref Record_DeviceElectricity deviceElectricity)
|
|
|
|
|
{
|
|
|
|
|
var ground = plc.ReadRandomInt16(address);
|
|
|
|
|
var ground = plc.ReadRandomInt32(address);
|
|
|
|
|
if (ground != null)
|
|
|
|
|
{
|
|
|
|
|
if (ground.Length >= 10)
|
|
|
|
|
{
|
|
|
|
|
var info = ParseAndReverseByteArray(ground, 0, address.Length * 2);
|
|
|
|
|
if(info != null)
|
|
|
|
|
{
|
|
|
|
|
if(info.Length >= 10)
|
|
|
|
|
{
|
|
|
|
|
//deviceElectricity.Glys = ground[0];
|
|
|
|
|
deviceElectricity.Va = ground[0];
|
|
|
|
|
deviceElectricity.Vb = ground[1];
|
|
|
|
|
deviceElectricity.Vc = ground[2];
|
|
|
|
|
deviceElectricity.Ia = ground[6];
|
|
|
|
|
deviceElectricity.Ib = ground[7];
|
|
|
|
|
deviceElectricity.Ic = ground[8];
|
|
|
|
|
deviceElectricity.Zxyg = ground[9];
|
|
|
|
|
deviceElectricity.Va = (decimal)info[0]/100;
|
|
|
|
|
deviceElectricity.Vb = (decimal)info[1]/100;
|
|
|
|
|
deviceElectricity.Vc = (decimal)info[2]/100;
|
|
|
|
|
deviceElectricity.Ia = (decimal)info[6]/100;
|
|
|
|
|
deviceElectricity.Ib = (decimal)info[7]/100;
|
|
|
|
|
deviceElectricity.Ic = (decimal)info[8]/100;
|
|
|
|
|
deviceElectricity.Zxyg = (decimal)info[9]/100;
|
|
|
|
|
deviceElectricity.CollectType = 0;
|
|
|
|
|
deviceElectricity.CollectTime = DateTime.Now;
|
|
|
|
|
deviceElectricity.RecordTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
deviceElectricity = null;
|
|
|
|
@ -108,5 +120,33 @@ namespace Aucma.Core.DataCollector
|
|
|
|
|
|
|
|
|
|
paramValue = Convert.ToInt32(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 电表数据解析
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="data"></param>
|
|
|
|
|
/// <param name="startIndex"></param>
|
|
|
|
|
/// <param name="length"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
|
private int[] ParseAndReverseByteArray(byte[] data, int startIndex, int length)
|
|
|
|
|
{
|
|
|
|
|
if (data == null || data.Length < startIndex + length)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Invalid data or startIndex/length parameter.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int[] resultArray = new int[length / 2];
|
|
|
|
|
for (int i = 0; i < resultArray.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
byte[] subset = new byte[2];
|
|
|
|
|
Array.Copy(data, startIndex + (i * 2), subset, 0, 2);
|
|
|
|
|
Array.Reverse(subset);
|
|
|
|
|
string hexString = BitConverter.ToString(subset).Replace("-", "");
|
|
|
|
|
resultArray[i] = Convert.ToInt32(hexString, 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultArray;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|