コード例 #1
0
ファイル: WeatherInstruction.cs プロジェクト: damoOnly/WAD
        public static void WriteWeather(List <WeatherEntity> list, byte address, Action <string> callback)
        {
            for (int i = 0; i < list.Count; i++)
            {
                WeatherEntity weather = list[i];
                List <byte>   content = new List <byte>();
                content.AddRange(BitConverter.GetBytes(weather.WeatherName.Value).Reverse());
                content.AddRange(BitConverter.GetBytes(weather.WeatherUnit.Value).Reverse());
                content.AddRange(BitConverter.GetBytes(weather.WeatherPoint.Value).Reverse());
                byte[] byteTemp = BitConverter.GetBytes(weather.Rang);
                Array.Reverse(byteTemp, 0, 2);
                Array.Reverse(byteTemp, 2, 2);
                content.AddRange(byteTemp);
                byte[] byteFactor = new byte[12];
                byteTemp = ASCIIEncoding.ASCII.GetBytes(weather.WeatherFactor);
                for (int j = 0; j < byteTemp.Length; j++)
                {
                    byteFactor[j * 2 + 1] = byteTemp[j];
                }
                content.AddRange(byteFactor);
                byteTemp = BitConverter.GetBytes(weather.WeatherCompensation);
                Array.Reverse(byteTemp, 0, 2);
                Array.Reverse(byteTemp, 2, 2);
                content.AddRange(byteTemp);

                byte[] sendb = Command.GetWiteSendByte(address, (byte)(0x10 + weather.WeatherID), 0x10, content.ToArray());
                callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
                PLAASerialPort.Write(sendb);
            }
        }
コード例 #2
0
ファイル: NormalInstruction.cs プロジェクト: damoOnly/WAD
        public static void WriteNormal(NormalParamEntity normal, byte address, Action <string> callback)
        {
            List <byte> content = new List <byte>();

            content.AddRange(BitConverter.GetBytes(normal.HotTimeSpan).Reverse());
            byte[] byteTemp = BitConverter.GetBytes(normal.DataStorageInterval);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            content.AddRange(BitConverter.GetBytes(normal.CurveTimeSpan).Reverse());
            content.Add(0x00);
            content.AddRange(BitConverter.GetBytes(normal.IfSoundAlert));
            content.AddRange(BitConverter.GetBytes(normal.AlertDelay).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayModelA1.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayModelA2.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayModel1.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayMatchChannel1).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayInterval1).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayActionTimeSpan1).Reverse());

            content.AddRange(BitConverter.GetBytes(normal.RelayModel2.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayMatchChannel2).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayInterval2).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayActionTimeSpan2).Reverse());

            content.AddRange(BitConverter.GetBytes(normal.RelayModel3.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayMatchChannel3).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayInterval3).Reverse());
            content.AddRange(BitConverter.GetBytes(normal.RelayActionTimeSpan3).Reverse());

            byte[] sendb = Command.GetWiteSendByte(address, 0x00, 0x22, content.ToArray());
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            PLAASerialPort.Write(sendb);
        }
コード例 #3
0
ファイル: NormalInstruction.cs プロジェクト: damoOnly/WAD
 public static List <WeatherEntity> WriteWeatherCount(short count, byte address, CommonConfig config, Action <string> callback)
 {
     byte[] sendb = Command.GetWiteSendByte(address, 0x00, 0x21, BitConverter.GetBytes(count).Reverse().ToArray());
     callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
     PLAASerialPort.Write(sendb);
     return(WeatherInstruction.ReadWeather(address, config, callback));
 }
コード例 #4
0
ファイル: NormalInstruction.cs プロジェクト: damoOnly/WAD
        public static NormalParamEntity ReadNormal(byte address, CommonConfig config, Action <string> callback)
        {
            byte[] sendb = Command.GetReadSendByte(address, 0x00, 0x20, 22);
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            byte[] rbytes = PLAASerialPort.Read(sendb);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));
            NormalParamEntity normal = new NormalParamEntity();

            Array.Reverse(rbytes, 3, 2);
            normal.GasCount = BitConverter.ToInt16(rbytes, 3);
            Array.Reverse(rbytes, 5, 2);
            normal.WeatherCount = BitConverter.ToInt16(rbytes, 5);
            Array.Reverse(rbytes, 7, 2);
            normal.HotTimeSpan = BitConverter.ToUInt16(rbytes, 7);
            Array.Reverse(rbytes, 9, 2);
            Array.Reverse(rbytes, 11, 2);
            normal.DataStorageInterval = BitConverter.ToInt32(rbytes, 9);
            Array.Reverse(rbytes, 13, 2);
            normal.CurveTimeSpan = BitConverter.ToUInt16(rbytes, 13);
            normal.IfSoundAlert  = BitConverter.ToBoolean(rbytes, 16);
            Array.Reverse(rbytes, 17, 2);
            normal.AlertDelay = BitConverter.ToUInt16(rbytes, 17);
            Array.Reverse(rbytes, 19, 2);
            normal.RelayModelA1.Value = BitConverter.ToInt16(rbytes, 19);
            normal.RelayModelA1.Name  = config.RelayModelA.FirstOrDefault(c => c.Value == normal.RelayModelA1.Value).Key;
            Array.Reverse(rbytes, 21, 2);
            normal.RelayModelA2.Value = BitConverter.ToInt16(rbytes, 21);
            normal.RelayModelA2.Name  = config.RelayModelA.FirstOrDefault(c => c.Value == normal.RelayModelA2.Value).Key;
            Array.Reverse(rbytes, 23, 2);
            normal.RelayModel1.Value = BitConverter.ToInt16(rbytes, 23);
            normal.RelayModel1.Name  = config.RelayModel.FirstOrDefault(c => c.Value == normal.RelayModel1.Value).Key;
            Array.Reverse(rbytes, 25, 2);
            normal.RelayMatchChannel1 = BitConverter.ToInt16(rbytes, 25);
            Array.Reverse(rbytes, 27, 2);
            normal.RelayInterval1 = BitConverter.ToUInt16(rbytes, 27);
            Array.Reverse(rbytes, 29, 2);
            normal.RelayActionTimeSpan1 = BitConverter.ToUInt16(rbytes, 29);

            Array.Reverse(rbytes, 31, 2);
            normal.RelayModel2.Value = BitConverter.ToInt16(rbytes, 31);
            normal.RelayModel2.Name  = config.RelayModel.FirstOrDefault(c => c.Value == normal.RelayModel2.Value).Key;
            Array.Reverse(rbytes, 33, 2);
            normal.RelayMatchChannel2 = BitConverter.ToInt16(rbytes, 33);
            Array.Reverse(rbytes, 35, 2);
            normal.RelayInterval2 = BitConverter.ToUInt16(rbytes, 35);
            Array.Reverse(rbytes, 37, 2);
            normal.RelayActionTimeSpan2 = BitConverter.ToUInt16(rbytes, 37);

            Array.Reverse(rbytes, 39, 2);
            normal.RelayModel3.Value = BitConverter.ToInt16(rbytes, 39);
            normal.RelayModel3.Name  = config.RelayModel.FirstOrDefault(c => c.Value == normal.RelayModel3.Value).Key;
            Array.Reverse(rbytes, 41, 2);
            normal.RelayMatchChannel3 = BitConverter.ToInt16(rbytes, 41);
            Array.Reverse(rbytes, 43, 2);
            normal.RelayInterval3 = BitConverter.ToUInt16(rbytes, 43);
            Array.Reverse(rbytes, 45, 2);
            normal.RelayActionTimeSpan3 = BitConverter.ToUInt16(rbytes, 45);
            return(normal);
        }
コード例 #5
0
ファイル: AllInstruction.cs プロジェクト: damoOnly/WAD
 public static void WriteAddress(byte oldAddress, byte newAddress, Action <string> callBack)
 {
     byte[] content = new byte[2];
     content[0] = 0x00;
     content[1] = newAddress;
     byte[] sendb = Command.GetWiteSendByte(oldAddress, 0x00, 0x10, content);
     callBack(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
     PLAASerialPort.Write(sendb);
 }
コード例 #6
0
ファイル: WeatherInstruction.cs プロジェクト: damoOnly/WAD
        public static List <WeatherEntity> ReadWeather(byte address, CommonConfig config, Action <string> callback)
        {
            byte[] sendb1 = Command.GetReadSendByte(address, 0x00, 0x21, 1);
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb1)));

            byte[] rbytes1 = PLAASerialPort.Read(sendb1);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes1)));

            byte count = rbytes1[4];
            List <WeatherEntity> list = new List <WeatherEntity>();

            for (byte i = 0; i < count; i++)
            {
                //Thread.Sleep(CommandUnits.CommandDelay);
                byte   high  = (byte)(0x10 + i);
                byte[] sendb = Command.GetReadSendByte(address, high, 0x10, 19);
                callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
                byte[] rbytes = PLAASerialPort.Read(sendb);
                callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));
                WeatherEntity weather = new WeatherEntity();
                weather.WeatherID = i;
                Array.Reverse(rbytes, 3, 2);
                weather.WeatherName.Value = BitConverter.ToInt16(rbytes, 3);
                weather.WeatherName.Name  = config.WeatherName.FirstOrDefault(c => c.Value == weather.WeatherName.Value).Key;
                Array.Reverse(rbytes, 5, 2);
                weather.WeatherUnit.Value = BitConverter.ToInt16(rbytes, 5);
                weather.WeatherUnit.Name  = config.WeatherUnit.FirstOrDefault(c => c.Value == weather.WeatherUnit.Value).Key;
                Array.Reverse(rbytes, 7, 2);
                weather.WeatherPoint.Value = BitConverter.ToInt16(rbytes, 7);
                weather.WeatherPoint.Name  = config.Point.FirstOrDefault(c => c.Value == weather.WeatherPoint.Value).Key;
                Array.Reverse(rbytes, 9, 2);
                Array.Reverse(rbytes, 11, 2);
                weather.Rang = BitConverter.ToSingle(rbytes, 9);
                List <byte> byteTemp = new List <byte>();
                for (int j = 13; j < 13 + 12;)
                {
                    if (rbytes[j + 1] != 0x00)
                    {
                        byteTemp.Add(rbytes[j + 1]);
                    }
                    j += 2;
                }
                weather.WeatherFactor = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());
                Array.Reverse(rbytes, 25, 2);
                Array.Reverse(rbytes, 27, 2);
                weather.WeatherCompensation = BitConverter.ToSingle(rbytes, 25);
                Array.Reverse(rbytes, 29, 2);
                Array.Reverse(rbytes, 31, 2);
                weather.CurrentWeather           = BitConverter.ToSingle(rbytes, 29);
                weather.WeatherAlertStatus.Value = rbytes[34];
                weather.WeatherAlertStatus.Name  = config.AlertStatus.FirstOrDefault(c => c.Value == rbytes[34]).Key;
                list.Add(weather);
            }
            return(list);
        }
コード例 #7
0
ファイル: AllInstruction.cs プロジェクト: damoOnly/WAD
        public static DateTime ReadOutDate(byte address, Action <string> callBack)
        {
            byte[] sendb = Command.GetReadSendByte(address, 0x00, 0x96, 3);
            callBack(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            byte[] rbytes = PLAASerialPort.Read(sendb);
            callBack(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));

            DateTime dt = new DateTime(2000 + rbytes[4], rbytes[6], rbytes[8]);

            return(dt);
        }
コード例 #8
0
ファイル: NormalInstruction.cs プロジェクト: damoOnly/WAD
        public static List <GasEntity> WriteGasCount(short count, byte address, CommonConfig config, Action <string> callback)
        {
            byte[] sendb = Command.GetWiteSendByte(address, 0x00, 0x20, BitConverter.GetBytes(count).Reverse().ToArray());
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            PLAASerialPort.Write(sendb);
            List <GasEntity> list = new List <GasEntity>();

            for (short i = 1; i <= count; i++)
            {
                GasEntity gas = GasInstruction.ReadGas(i, address, config, callback);
                list.Add(gas);
            }
            return(list);
        }
コード例 #9
0
ファイル: AllInstruction.cs プロジェクト: damoOnly/WAD
        public static void WriteOutDate(byte address, DateTime dt, Action <string> callBack)
        {
            byte[] content = new byte[6];
            content[0] = 0x00;
            content[1] = (byte)(dt.Year - 2000);
            content[2] = 0x00;
            content[3] = (byte)dt.Month;
            content[4] = 0x00;
            content[5] = (byte)dt.Day;

            byte[] sendb = Command.GetWiteSendByte(address, 0x00, 0x96, content);
            callBack(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            PLAASerialPort.Write(sendb);
        }
コード例 #10
0
        public static void Write(byte[] wdata)
        {
            CheckSerialPort();
            CommandUnits.IsCommandding = true;

            serialport.Write(wdata, 0, wdata.Length);

            TryReadBytes(wdata[0], 8);
            Thread.Sleep(CommandUnits.CommandDelay);
            CommandUnits.IsCommandding = false;

            string str = "T   " + CommandUnits.ByteToHexStr(wdata);

            Console.WriteLine(str);
        }
コード例 #11
0
        public static void WriteCurrent(int gasId, byte address, GasEntity gas, Action <string> callback)
        {
            List <byte> content = new List <byte>();

            content.AddRange(BitConverter.GetBytes(gas.CurrentAD));
            content.AddRange(BitConverter.GetBytes(gas.CurrentChroma));
            content.Reverse(0, 2);
            content.Reverse(2, 2);
            content.Reverse(4, 2);
            content.Reverse(5, 2);
            content.Add(0);
            content.Add((byte)gas.AlertStatus.Value);
            byte[] sendb = Command.GetWiteSendByte(address, (byte)gas.GasID, 0x50, content.ToArray());
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            PLAASerialPort.Write(sendb);
        }
コード例 #12
0
        public static List <GasEntity> ReadGasList(byte address, CommonConfig config, Action <string> callback)
        {
            List <GasEntity> list = new List <GasEntity>();

            byte[] sendb1 = Command.GetReadSendByte(address, 0x00, 0x20, 1);
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb1)));
            byte[] rbytes1 = PLAASerialPort.Read(sendb1);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes1)));
            byte count = rbytes1[4];

            for (byte i = 1; i <= count; i++)
            {
                list.Add(ReadGas(i, address, config, callback));
            }
            return(list);
        }
コード例 #13
0
        public static void WriteChromaAndAD(GasEntity gas, EnumChromaLevel level, byte address, Action <string> callback)
        {
            byte        low     = 0x2a;
            List <byte> content = new List <byte>();

            switch (level)
            {
            case EnumChromaLevel.Zero:
                low = 0x2a;
                content.AddRange(BitConverter.GetBytes(gas.ZeroAD));
                content.AddRange(BitConverter.GetBytes(gas.ZeroChroma));
                break;

            case EnumChromaLevel.One:
                low = 0x2e;
                content.AddRange(BitConverter.GetBytes(gas.OneAD));
                content.AddRange(BitConverter.GetBytes(gas.OneChroma));
                break;

            case EnumChromaLevel.Two:
                low = 0x32;
                content.AddRange(BitConverter.GetBytes(gas.TwoAD));
                content.AddRange(BitConverter.GetBytes(gas.TwoChroma));
                break;

            case EnumChromaLevel.Three:
                low = 0x36;
                content.AddRange(BitConverter.GetBytes(gas.ThreeAD));
                content.AddRange(BitConverter.GetBytes(gas.ThreeChroma));
                break;

            default:
                break;
            }
            content.Reverse(0, 2);
            content.Reverse(2, 2);
            content.Reverse(4, 2);
            content.Reverse(6, 2);
            byte[] sendb = Command.GetWiteSendByte(address, (byte)gas.GasID, low, content.ToArray());
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));

            PLAASerialPort.Write(sendb);
        }
コード例 #14
0
        public static GasEntity ReadCurrent(int gasId, byte address, CommonConfig config, Action <string> callback)
        {
            byte[] sendb = Command.GetReadSendByte(address, (byte)gasId, 0x50, 5);
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            byte[] rbytes = PLAASerialPort.Read(sendb);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));
            Array.Reverse(rbytes, 3, 2);
            Array.Reverse(rbytes, 5, 2);
            Array.Reverse(rbytes, 7, 2);
            Array.Reverse(rbytes, 9, 2);
            GasEntity gas = new GasEntity();

            gas.CurrentAD     = BitConverter.ToInt32(rbytes, 3);
            gas.CurrentChroma = BitConverter.ToSingle(rbytes, 7);
            if (config != null)
            {
                gas.AlertStatus.Value = rbytes[12];
                gas.AlertStatus.Name  = config.AlertStatus.FirstOrDefault(c => c.Value == gas.AlertStatus.Value).Key;
            }

            return(gas);
        }
コード例 #15
0
        public static byte[] Read(byte[] pdata)
        {
            CheckSerialPort();
            CommandUnits.IsCommandding = true;

            serialport.Write(pdata, 0, pdata.Length);
            string strw = "T   " + CommandUnits.ByteToHexStr(pdata);

            Console.WriteLine(strw);

            byte[] FB = new byte[2];
            Array.Copy(pdata, 4, FB, 0, 2);
            Array.Reverse(FB);
            int backCount = BitConverter.ToInt16(FB, 0) * 2;

            byte[] rbytes = TryReadBytes(pdata[0], backCount + 5);
            Thread.Sleep(CommandUnits.CommandDelay);
            CommandUnits.IsCommandding = false;

            string str = "R   " + CommandUnits.ByteToHexStr(rbytes);

            Console.WriteLine(str);
            return(rbytes);
        }
コード例 #16
0
        public static void WriteSerialParam(SerialEntity serial, byte address, Action <string> callback)
        {
            List <byte> content = new List <byte>();

            content.AddRange(BitConverter.GetBytes(serial.SerialOneBaudRate.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(serial.SerialOnePortModel.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(serial.SerialOneAddress).Reverse());
            byte[] byteTemp = BitConverter.GetBytes(serial.SerialOneInterval);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byte[] byteMN = new byte[48];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOneMN);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                byteMN[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(byteMN);

            byte[] byteST = new byte[4];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOneST);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                byteST[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(byteST);

            byte[] byteCN = new byte[8];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOneCN);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                byteCN[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(byteCN);

            byte[] bytePW = new byte[12];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOnePW);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                bytePW[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(bytePW);

            content.AddRange(BitConverter.GetBytes(serial.SerialTwoBaudRate.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(serial.SerialTwoPortModel.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(serial.SerialTwoAddress).Reverse());
            byteTemp = BitConverter.GetBytes(serial.SerialTwoInterval);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);

            byte[] byteMN2 = new byte[48];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoMN);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                byteMN2[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(byteMN2);

            byte[] byteST2 = new byte[4];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoST);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                byteST2[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(byteST2);

            byte[] byteCN2 = new byte[8];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoCN);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                byteCN2[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(byteCN2);

            byte[] bytePW2 = new byte[12];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoPW);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                bytePW2[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(bytePW2);

            byte[] sendb = Command.GetWiteSendByte(address, 0x00, 0x36, content.ToArray());
            callback(string.Format("T: {0}", CommandUnits.ByteToHexStr(sendb)));
            PLAASerialPort.Write(sendb);
        }
コード例 #17
0
        public static GasEntity ReadChromaAndAD(int gasId, EnumChromaLevel level, byte address, Action <string> callback)
        {
            byte low = 0x2a;

            switch (level)
            {
            case EnumChromaLevel.Zero:
                low = 0x2a;
                break;

            case EnumChromaLevel.One:
                low = 0x2e;
                break;

            case EnumChromaLevel.Two:
                low = 0x32;
                break;

            case EnumChromaLevel.Three:
                low = 0x36;
                break;

            default:
                break;
            }
            byte[] sendb = Command.GetReadSendByte(address, (byte)gasId, low, 4);
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            byte[] rbytes = PLAASerialPort.Read(sendb);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));

            Array.Reverse(rbytes, 3, 2);
            Array.Reverse(rbytes, 5, 2);
            Array.Reverse(rbytes, 7, 2);
            Array.Reverse(rbytes, 9, 2);

            GasEntity gas = new GasEntity();

            switch (level)
            {
            case EnumChromaLevel.Zero:
                gas.ZeroAD     = BitConverter.ToInt32(rbytes, 3);
                gas.ZeroChroma = BitConverter.ToSingle(rbytes, 7);
                break;

            case EnumChromaLevel.One:
                gas.OneAD     = BitConverter.ToInt32(rbytes, 3);
                gas.OneChroma = BitConverter.ToSingle(rbytes, 7);
                break;

            case EnumChromaLevel.Two:
                gas.TwoAD     = BitConverter.ToInt32(rbytes, 3);
                gas.TwoChroma = BitConverter.ToSingle(rbytes, 7);
                break;

            case EnumChromaLevel.Three:
                gas.ThreeAD     = BitConverter.ToInt32(rbytes, 3);
                gas.ThreeChroma = BitConverter.ToSingle(rbytes, 7);
                break;

            default:
                break;
            }
            return(gas);
        }
コード例 #18
0
        public static GasEntity ReadGas(int gasId, byte address, CommonConfig config, Action <string> callback)
        {
            byte[] sendb = Command.GetReadSendByte(address, (byte)gasId, 0x10, 42);
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            byte[] rbytes = PLAASerialPort.Read(sendb);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));
            GasEntity gas = new GasEntity();

            gas.GasID = gasId;
            Array.Reverse(rbytes, 3, 2);
            gas.GasName.Value = BitConverter.ToInt16(rbytes, 3);
            gas.GasName.Name  = config.GasName.FirstOrDefault(c => c.Value == gas.GasName.Value).Key;
            Array.Reverse(rbytes, 5, 2);
            gas.GasUnit.Value = BitConverter.ToInt16(rbytes, 5);
            gas.GasUnit.Name  = config.GasUnit.FirstOrDefault(c => c.Value == gas.GasUnit.Value).Key;
            Array.Reverse(rbytes, 7, 2);
            gas.GasPoint.Value = BitConverter.ToInt16(rbytes, 7);
            gas.GasPoint.Name  = config.Point.FirstOrDefault(c => c.Value == gas.GasPoint.Value).Key;
            Array.Reverse(rbytes, 9, 2);
            Array.Reverse(rbytes, 11, 2);
            gas.GasRang = BitConverter.ToSingle(rbytes, 9);
            List <byte> byteTemp = new List <byte>();

            for (int i = 13; i < 13 + 12;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            // to do test
            gas.Factor     = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());
            gas.IfGasAlarm = BitConverter.ToBoolean(rbytes, 26);
            Array.Reverse(rbytes, 27, 2);
            gas.AlertModel.Value = BitConverter.ToInt16(rbytes, 27);
            gas.AlertModel.Name  = config.AlertModel.FirstOrDefault(c => c.Value == gas.AlertModel.Value).Key;
            Array.Reverse(rbytes, 29, 2);
            Array.Reverse(rbytes, 31, 2);
            gas.GasA1 = BitConverter.ToSingle(rbytes, 29);
            Array.Reverse(rbytes, 33, 2);
            Array.Reverse(rbytes, 35, 2);
            gas.GasA2 = BitConverter.ToSingle(rbytes, 33);
            Array.Reverse(rbytes, 45, 2);
            Array.Reverse(rbytes, 47, 2);
            gas.Compensation = BitConverter.ToSingle(rbytes, 45);
            Array.Reverse(rbytes, 49, 2);
            Array.Reverse(rbytes, 51, 2);
            gas.Show     = BitConverter.ToSingle(rbytes, 49);
            gas.CheckNum = (byte)(rbytes[54] < 2 ? 2 : (rbytes[54] > 4 ? 4 : rbytes[54]));
            gas.IfTwo    = gas.CheckNum >= 3;
            gas.IfThree  = gas.CheckNum >= 4;
            Array.Reverse(rbytes, 55, 2);
            Array.Reverse(rbytes, 57, 2);
            gas.ZeroAD = BitConverter.ToInt32(rbytes, 55);
            Array.Reverse(rbytes, 59, 2);
            Array.Reverse(rbytes, 61, 2);
            gas.ZeroChroma = BitConverter.ToSingle(rbytes, 59);
            Array.Reverse(rbytes, 63, 2);
            Array.Reverse(rbytes, 65, 2);
            gas.OneAD = BitConverter.ToInt32(rbytes, 63);
            Array.Reverse(rbytes, 67, 2);
            Array.Reverse(rbytes, 69, 2);
            gas.OneChroma = BitConverter.ToSingle(rbytes, 67);
            Array.Reverse(rbytes, 71, 2);
            Array.Reverse(rbytes, 73, 2);
            gas.TwoAD = BitConverter.ToInt32(rbytes, 71);
            Array.Reverse(rbytes, 75, 2);
            Array.Reverse(rbytes, 77, 2);
            gas.TwoChroma = BitConverter.ToSingle(rbytes, 75);
            Array.Reverse(rbytes, 79, 2);
            Array.Reverse(rbytes, 81, 2);
            gas.ThreeAD = BitConverter.ToInt32(rbytes, 79);
            Array.Reverse(rbytes, 83, 2);
            Array.Reverse(rbytes, 85, 2);
            gas.ThreeChroma = BitConverter.ToSingle(rbytes, 83);

            GasEntity current = ReadCurrent(gasId, address, config, callback);

            gas.CurrentAD     = current.CurrentAD;
            gas.CurrentChroma = current.CurrentChroma;
            gas.AlertStatus   = current.AlertStatus;

            return(gas);
        }
コード例 #19
0
        public static void WriteGas(GasEntity gas, byte address, Action <string> callback)
        {
            List <byte> content = new List <byte>();

            content.AddRange(BitConverter.GetBytes(gas.GasName.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(gas.GasUnit.Value).Reverse());
            content.AddRange(BitConverter.GetBytes(gas.GasPoint.Value).Reverse());
            byte[] byteTemp = BitConverter.GetBytes(gas.GasRang);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byte[] byteFactor = new byte[12];
            byteTemp = ASCIIEncoding.ASCII.GetBytes(gas.Factor);
            for (int i = 0; i < byteTemp.Length; i++)
            {
                byteFactor[i * 2 + 1] = byteTemp[i];
            }
            content.AddRange(byteFactor);
            content.Add(0);
            content.AddRange(BitConverter.GetBytes(gas.IfGasAlarm));
            content.AddRange(BitConverter.GetBytes(gas.AlertModel.Value).Reverse());
            byteTemp = BitConverter.GetBytes(gas.GasA1);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.GasA2);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            content.AddRange(new byte[8]);
            byteTemp = BitConverter.GetBytes(gas.Compensation);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.Show);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            if (gas.IfThree)
            {
                gas.CheckNum = 0x04;
            }
            else if (gas.IfTwo)
            {
                gas.CheckNum = 0x03;
            }
            else
            {
                gas.CheckNum = 0x02;
            }
            content.AddRange(new byte[2] {
                0x00, gas.CheckNum
            });
            byteTemp = BitConverter.GetBytes(gas.ZeroAD);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.ZeroChroma);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.OneAD);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.OneChroma);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.TwoAD);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.TwoChroma);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.ThreeAD);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            byteTemp = BitConverter.GetBytes(gas.ThreeChroma);
            Array.Reverse(byteTemp, 0, 2);
            Array.Reverse(byteTemp, 2, 2);
            content.AddRange(byteTemp);
            //content.AddRange(new byte[22]);
            //byteTemp = BitConverter.GetBytes(gas.CurrentAD);
            //Array.Reverse(byteTemp, 0, 2);
            //Array.Reverse(byteTemp, 2, 2);
            //content.AddRange(byteTemp);
            //byteTemp = BitConverter.GetBytes(gas.CurrentChroma);
            //Array.Reverse(byteTemp, 0, 2);
            //Array.Reverse(byteTemp, 2, 2);
            //content.AddRange(byteTemp);
            //content.AddRange(BitConverter.GetBytes(gas.AlertStatus.Value).Reverse());

            byte[] sendb = Command.GetWiteSendByte(address, (byte)gas.GasID, 0x10, content.ToArray());
            callback(string.Format("W: {0}", CommandUnits.ByteToHexStr(sendb)));
            PLAASerialPort.Write(sendb);

            //WriteCurrent(gas.GasID, address, gas);
        }
コード例 #20
0
        public static SerialEntity ReadSerialParam(byte address, CommonConfig config, Action <string> callback)
        {
            byte[] sendb = Command.GetReadSendByte(address, 0x00, 0x36, 82);
            callback(string.Format("T: {0}", CommandUnits.ByteToHexStr(sendb)));
            byte[] rbytes = PLAASerialPort.Read(sendb);
            callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes)));
            SerialEntity serial = new SerialEntity();

            Array.Reverse(rbytes, 3, 2);
            serial.SerialOneBaudRate.Value = BitConverter.ToInt16(rbytes, 3);
            serial.SerialOneBaudRate.Name  = config.BaudRate.FirstOrDefault(c => c.Value == serial.SerialOneBaudRate.Value).Key;
            Array.Reverse(rbytes, 5, 2);
            serial.SerialOnePortModel.Value = BitConverter.ToInt16(rbytes, 5);
            serial.SerialOnePortModel.Name  = config.SerialPortModel.FirstOrDefault(c => c.Value == serial.SerialOnePortModel.Value).Key;
            Array.Reverse(rbytes, 7, 2);
            serial.SerialOneAddress = BitConverter.ToInt16(rbytes, 7);
            Array.Reverse(rbytes, 9, 2);
            Array.Reverse(rbytes, 11, 2);
            serial.SerialOneInterval = BitConverter.ToInt32(rbytes, 9);
            List <byte> byteTemp = new List <byte>();

            for (int i = 13; i < 13 + 48;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }

            serial.SerialOneMN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            byteTemp = new List <byte>();
            for (int i = 61; i < 61 + 4;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            serial.SerialOneST = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            byteTemp = new List <byte>();
            for (int i = 65; i < 65 + 8;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            serial.SerialOneCN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            byteTemp = new List <byte>();
            for (int i = 73; i < 73 + 12;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            serial.SerialOnePW = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            Array.Reverse(rbytes, 85, 2);
            serial.SerialTwoBaudRate.Value = BitConverter.ToInt16(rbytes, 85);
            serial.SerialTwoBaudRate.Name  = config.BaudRate.FirstOrDefault(c => c.Value == serial.SerialTwoBaudRate.Value).Key;
            Array.Reverse(rbytes, 87, 2);
            serial.SerialTwoPortModel.Value = BitConverter.ToInt16(rbytes, 87);
            serial.SerialTwoPortModel.Name  = config.SerialPortModel.FirstOrDefault(c => c.Value == serial.SerialTwoPortModel.Value).Key;
            Array.Reverse(rbytes, 89, 2);
            serial.SerialTwoAddress = BitConverter.ToInt16(rbytes, 89);
            Array.Reverse(rbytes, 91, 2);
            Array.Reverse(rbytes, 93, 2);
            serial.SerialTwoInterval = BitConverter.ToInt32(rbytes, 91);

            byteTemp = new List <byte>();
            for (int i = 95; i < 95 + 48;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            serial.SerialTwoMN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            byteTemp = new List <byte>();
            for (int i = 143; i < 143 + 4;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            serial.SerialTwoST = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            byteTemp = new List <byte>();
            for (int i = 147; i < 147 + 8;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            serial.SerialTwoCN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            byteTemp = new List <byte>();
            for (int i = 155; i < 155 + 12;)
            {
                if (rbytes[i + 1] != 0x00)
                {
                    byteTemp.Add(rbytes[i + 1]);
                }
                i += 2;
            }
            serial.SerialTwoPW = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray());

            return(serial);
        }