예제 #1
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);
        }
예제 #2
0
        public static AllEntity ReadAll(byte address, CommonConfig config, Action <string> callback, Action <string> commandCallback)
        {
            AllEntity all = new AllEntity();

            try
            {
                all.Normal = NormalInstruction.ReadNormal(address, config, commandCallback);
                callback("读取通用参数成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("读取通用参数失败");
            }

            for (int i = 1; i <= all.Normal.GasCount; i++)
            {
                try
                {
                    all.GasList.Add(GasInstruction.ReadGas(i, address, config, commandCallback));
                    callback(string.Format("读取气体{0}成功", i));
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    callback(string.Format("读取气体{0}失败", i));
                }
            }

            try
            {
                all.WeatherList = WeatherInstruction.ReadWeather(address, config, commandCallback);
                callback("读取气象成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("读取气象失败");
            }

            try
            {
                all.Serial = SerialInstruction.ReadSerialParam(address, config, commandCallback);
                callback("读取串口参数成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("读取串口参数失败");
            }

            try
            {
                all.EquipmentDataTime = ReadRealTime(address, commandCallback);
                callback("读取时间成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("读取时间失败");
            }

            try
            {
                all.OutDate = ReadOutDate(address, commandCallback);
                callback("读取出厂日期成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("读取出厂日期失败");
            }

            return(all);
        }