using ivf_tl_Entity.GlobalEnums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ivf_tl_Entity.ComEntitys { public class Analysiser { /// /// 解析E方 /// /// /// public static int ParseEEPROMPulse(byte[] arg) { if (!arg.Any()) return -1; byte[] temp = { arg[4], arg[5], arg[6], arg[7] }; if (!BitConverter.IsLittleEndian) Array.Reverse(temp); return BitConverter.ToInt32(temp, 0); } /// /// 握手指令解析 /// /// /// public static int ParseShakeHandsCommand(byte[] arg) { if (arg.Any()) return Convert.ToInt32(arg[2]); return -1; } /// /// 舱门状态 /// /// /// public static State ParseDoorStatus(byte[] arg) { if (!arg.Any()) return State.未知; return arg[4] == 0x01 ? State.打开 : State.关闭; } /// /// 温度解析 /// /// /// public static decimal ParseTemperatureCommand(byte[] arg) { if (!arg.Any()) return -1m; byte[] temp = { arg[5], arg[4] }; if (!BitConverter.IsLittleEndian) Array.Reverse(temp); int num = BitConverter.ToInt16(temp); var result = Math.Round(num / 100.00m, 2, MidpointRounding.AwayFromZero); return result; } /// /// 气压解析 /// /// /// public static decimal ParsePressureCommand(byte[] arg) { if (!arg.Any()) return -1m; byte[] temp = { arg[5], arg[4] }; if (!BitConverter.IsLittleEndian) Array.Reverse(temp); int num = BitConverter.ToInt16(temp); return (decimal)num; } /// /// 仪器温度1解析 /// /// /// public static decimal ParseTLTemperature1Command(byte[] arg) { if (!arg.Any()) return -1m; byte[] temp = { arg[7], arg[6] }; if (!BitConverter.IsLittleEndian) Array.Reverse(temp); int num = BitConverter.ToInt16(temp); return Math.Round(num / 100.00m, 2, MidpointRounding.AwayFromZero); } /// /// 仪器温度2解析 /// /// /// public static decimal ParseTLTemperature2Command(byte[] arg) { if (!arg.Any()) return -1m; byte[] temp = { arg[9], arg[8] }; if (!BitConverter.IsLittleEndian) Array.Reverse(temp); int num = BitConverter.ToInt16(temp); return Math.Round(num / 100.00m, 2, MidpointRounding.AwayFromZero); } /// /// 当前电机位置解析 /// /// /// public static int ParseCurrentMotor(byte[] arg) { if (!arg.Any()) return -1; byte[] temp = { arg[7], arg[6], arg[5], arg[4] }; if (!BitConverter.IsLittleEndian) Array.Reverse(temp); return BitConverter.ToInt32(temp, 0); } } }