Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }
Example #3
0
 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));
 }
Example #4
0
 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);
 }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
        }