增加报警信息代码
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using JY.Inspection.Entity;
|
||||
using JY.DAL;
|
||||
using JY.Inspection.Entity;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -47,6 +50,53 @@ namespace JY.Inspection.Common
|
||||
return listAlarmStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 欧姆龙NX系列Ethernet/IP通讯时将报警地址值转成报警List {直接读取标签地址/无需高低位互换}
|
||||
/// </summary>
|
||||
/// <param name="plcAddrSuffix">PLC地址值,如100</param>
|
||||
/// <param name="byteData">PLC读取出来的值</param>
|
||||
/// <param name="plcAddrPrefix">PLC地址类型,默认值R</param>
|
||||
/// <returns></returns>
|
||||
public static List<AlarmStatus> OmronEIPByte2Status(List<byte> byteData, char plcAddrPrefix = 'D')
|
||||
{
|
||||
var listAlarmStatus = new List<AlarmStatus>();
|
||||
// byte[]转为二进制字符串表示
|
||||
string strResult = "";
|
||||
byte[] revBytes = SWAPbyte(byteData.ToArray()); //字节高低位互换
|
||||
for (int i = 0; i < revBytes.Length; i++)
|
||||
{
|
||||
string strTemp = System.Convert.ToString(revBytes[i], 2);
|
||||
strTemp = strTemp.PadLeft(8, '0').StrReverse();
|
||||
strResult += strTemp;
|
||||
}
|
||||
|
||||
int groupIndex = -1;
|
||||
for (int i = 0; i < strResult.Length; i++)
|
||||
{
|
||||
var plcByte = i % 160;
|
||||
|
||||
//如果是16的倍数地址+1
|
||||
if (groupIndex == -1 || (plcByte % 160 == 0 && i != 0))
|
||||
{
|
||||
groupIndex += 1;
|
||||
}
|
||||
|
||||
int address = ConstValue.GetAddressByIndex(groupIndex);
|
||||
|
||||
//将地址和状态添加到结果集
|
||||
listAlarmStatus.Add(new AlarmStatus()
|
||||
{
|
||||
PLCAdress = $"{plcAddrPrefix}{address}.{plcByte.ToString()}",
|
||||
Status = strResult[i] == '1'
|
||||
});
|
||||
|
||||
//if (strResult[i] == '1')
|
||||
// Console.WriteLine($"{plcAddrPrefix}{plcAddrSuffix}.{plcByte.ToString("X")}:{strResult[i]}");
|
||||
}
|
||||
|
||||
return listAlarmStatus;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 欧姆龙NX系列Ethernet/IP通讯时将报警地址值转成报警List {直接读取标签地址/无需高低位互换}
|
||||
@@ -55,7 +105,7 @@ namespace JY.Inspection.Common
|
||||
/// <param name="byteData">PLC读取出来的值</param>
|
||||
/// <param name="plcAddrPrefix">PLC地址类型,默认值R</param>
|
||||
/// <returns></returns>
|
||||
public static List<AlarmStatus> OmronEIPByte2Status(int plcAddrSuffix, List<byte> byteData, char plcAddrPrefix = 'W')
|
||||
public static List<AlarmStatus> OmronEIPByte2Status(int plcAddrSuffix, List<byte> byteData, char plcAddrPrefix = 'D')
|
||||
{
|
||||
var listAlarmStatus = new List<AlarmStatus>();
|
||||
// byte[]转为二进制字符串表示
|
||||
|
||||
Reference in New Issue
Block a user