电表电能读取方法优化

master
LiuKP 7 months ago
parent 174242fc87
commit d1a0198ca0

@ -506,19 +506,39 @@ namespace Module.EMeter.ModbusTcp
{
while (_is_read)
{
var operateResult = _client.Read("x=3;0", 150);
if (_net_connected && operateResult.IsSuccess)
//var operateResult = _client.Read("x=3;0", 150);
//if (_net_connected && operateResult.IsSuccess)
//{
// var PT = _client.ByteTransform.TransInt16(operateResult.Content, 6);
// var CT = _client.ByteTransform.TransInt16(operateResult.Content, 8);
// //_total_active_power = _client.ByteTransform.TransUInt16(_client.Read("x=3;45", 150).Content, 4);
// //_total_active_energy = _client.ByteTransform.TransSingle(_client.Read("x=3;45", 150).Content, 56) / 1000f;
// var transInt16 = (new decimal(_client.ByteTransform.TransUInt16(operateResult.Content, 126))*65536+_client.ByteTransform.TransUInt16(operateResult.Content, 128)/ new decimal(1000f))*new decimal(PT) *new decimal(CT);
// _show_energy = (float)transInt16;
// MEMeterParamResult paramRlt = new MEMeterParamResult()
// {
// F_EqmCode = _eqm_code,
// F_ShowEnergy=_show_energy,
// F_TotalActivePower = _total_active_power,
// F_TotalActiveEnergy = Convert.ToUInt32(_total_active_energy)
// };
// _emeter_param_result = paramRlt;
// new ElecMeterValToRedis().StoredMeterParamResult(_eqm_code, paramRlt);
//}
var operateResult1 = _client.Read("x=3;0", 10);
var operateResult2 = _client.Read("x=3;63", 10);
if (_net_connected && operateResult1.IsSuccess && operateResult2.IsSuccess)
{
var PT = _client.ByteTransform.TransInt16(operateResult.Content, 6);
var CT = _client.ByteTransform.TransInt16(operateResult.Content, 8);
var PT = _client.ByteTransform.TransInt16(operateResult1.Content, 6);
var CT = _client.ByteTransform.TransInt16(operateResult1.Content, 8);
//_total_active_power = _client.ByteTransform.TransUInt16(_client.Read("x=3;45", 150).Content, 4);
//_total_active_energy = _client.ByteTransform.TransSingle(_client.Read("x=3;45", 150).Content, 56) / 1000f;
var transInt16 = (new decimal(_client.ByteTransform.TransUInt16(operateResult.Content, 126))*65536+_client.ByteTransform.TransUInt16(operateResult.Content, 128)/ new decimal(1000f))*new decimal(PT) *new decimal(CT);
var transInt16 = (new decimal(_client.ByteTransform.TransUInt16(operateResult2.Content, 0)) * 65536 + _client.ByteTransform.TransUInt16(operateResult2.Content, 2) / new decimal(1000f)) * new decimal(PT) * new decimal(CT);
_show_energy = (float)transInt16;
MEMeterParamResult paramRlt = new MEMeterParamResult()
{
F_EqmCode = _eqm_code,
F_ShowEnergy=_show_energy,
F_ShowEnergy = _show_energy,
F_TotalActivePower = _total_active_power,
F_TotalActiveEnergy = Convert.ToUInt32(_total_active_energy)
};

@ -76,10 +76,10 @@ namespace Module.EMeter.ModbusTcp
CmnElecMeterBaseInfo.EBC01.Connect();
}
Thread.Sleep(200);
// if (!CmnElecMeterBaseInfo.EBC02.F_NetConnected)
// {
// CmnElecMeterBaseInfo.EBC02.Connect();
// }
if (!CmnElecMeterBaseInfo.EBC02.F_NetConnected)
{
CmnElecMeterBaseInfo.EBC02.Connect();
}
Thread.Sleep(200);
if (!CmnElecMeterBaseInfo.EBC03.F_NetConnected)
{

Loading…
Cancel
Save