Beispiel #1
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));
 }
Beispiel #2
0
        public static void WriteAll(AllEntity all, CommonConfig config, Action <string> callback, Action <string> commandCallback)
        {
            try
            {
                WriteRealTime(all.Address, all.EquipmentDataTime, commandCallback);
                callback("写入时间成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("写入时间失败");
            }

            try
            {
                WriteOutDate(all.Address, all.OutDate, commandCallback);
                callback("写入出厂日期成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("写入出厂日期失败");
            }

            try
            {
                NormalInstruction.WriteGasCount((short)all.GasList.Count, all.Address, config, commandCallback);
                callback("写入气体个数成功");

                foreach (var gas in all.GasList)
                {
                    try
                    {
                        GasInstruction.WriteGas(gas, all.Address, commandCallback);
                        callback(string.Format("写入气体{0}成功", gas.GasID));
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                        callback(string.Format("写入气体{0}失败", gas.GasID));
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("写入气体个数失败");
            }

            try
            {
                NormalInstruction.WriteWeatherCount((short)all.WeatherList.Count, all.Address, config, commandCallback);
                WeatherInstruction.WriteWeather(all.WeatherList, all.Address, commandCallback);
                callback("写入气象参数成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("写入气象参数失败");
            }

            try
            {
                NormalInstruction.WriteNormal(all.Normal, all.Address, commandCallback);
                callback("写入通用参数成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("写入通用参数失败");
            }

            try
            {
                SerialInstruction.WriteSerialParam(all.Serial, all.Address, commandCallback);
                callback("写入串口参数成功");
            }
            catch (Exception ex)
            {
                log.Error(ex);
                callback("写入串口参数失败");
            }
        }
Beispiel #3
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);
        }