Exemplo n.º 1
0
        private void simpleButton14_Click(object sender, EventArgs e)
        {
            WaitDialogForm wdf = new WaitDialogForm("命令执行中,请稍候......");

            try
            {
                Gloab.AllData.Normal = NormalInstruction.ReadNormal(Gloab.AllData.Address, Gloab.Config, CommandCallback);
                UpdateNormal();
                Gloab.AllData.NormalList = Gloab.AllData.Normal.ConvertToNormalList();
                if (ChangeNormalEvent != null)
                {
                    ChangeNormalEvent(null, null);
                }
                Callback("读取通用参数成功");
            }
            catch (CommandException ex)
            {
                Callback("读取通用参数失败");
                XtraMessageBox.Show(ex.Message);
            }
            catch (Exception exp)
            {
                Callback("读取通用参数失败");
                log.Error(exp);
            }
            finally
            {
                wdf.Close();
            }
        }
Exemplo n.º 2
0
        public static void SaveModel <T>(T all, ModelType modelType)
        {
            SaveFileDialog mTempSaveDialog = new SaveFileDialog();
            string         directoryName   = GetDirectoryName(modelType);

            mTempSaveDialog.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + directoryName;
            if (!System.IO.Directory.Exists(mTempSaveDialog.InitialDirectory))
            {
                System.IO.Directory.CreateDirectory(mTempSaveDialog.InitialDirectory);//不存在就创建目录
            }
            mTempSaveDialog.Filter           = "Model files (*xml)|*.xml";
            mTempSaveDialog.RestoreDirectory = true;
            mTempSaveDialog.FileName         = directoryName;

            if (DialogResult.OK == mTempSaveDialog.ShowDialog() && null != mTempSaveDialog.FileName.Trim())
            {
                XmlSerializerProvider xml = new XmlSerializerProvider();
                try
                {
                    xml.Serialize <T>(mTempSaveDialog.FileName, all);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            }
        }
Exemplo n.º 3
0
 public static bool Open(string portName, int baudRate)
 {
     try
     {
         serialport.PortName = portName;         //串口号
         serialport.BaudRate = baudRate;         //波特率
         //serialport.DataReceived += new SerialDataReceivedEventHandler(serialport_DataReceived);
         if (!serialport.IsOpen)
         {
             serialport.Open();
         }
         return(true);
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return(false);
     }
 }
Exemplo n.º 4
0
 static void sampleTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e, object param)
 {
     try
     {
         List <object>   list    = param as List <object>;
         byte            address = (byte)list[0];
         int             gasId   = (int)list[1];
         EnumChromaLevel level   = (EnumChromaLevel)list[2];
         Action <EnumChromaLevel, GasEntity> callback = list[3] as Action <EnumChromaLevel, GasEntity>;
         Action <string> commandCallback = list[4] as Action <string>;
         GasEntity       gas             = ReadCurrent(gasId, address, null, commandCallback);
         callback(level, gas);
     }
     //catch (CommandException exp)
     //{
     //    throw exp;
     //}
     catch (Exception ex)
     {
         log.Error(ex);
     }
 }
Exemplo n.º 5
0
        private void simpleButton11_Click(object sender, EventArgs e)
        {
            WaitDialogForm wdf = new WaitDialogForm("命令执行中,请稍候......");

            try
            {
                Gloab.AllData.GasList[Gloab.AllData.GasList.FindIndex(c => c.GasID == GasID)] = GasInstruction.ReadGas(GasID, Gloab.AllData.Address, Gloab.Config, CommandCallback);
                Gas = Gloab.AllData.GasList.Find(c => c.GasID == GasID);
                SetGasToControl();
                Callback(string.Format("读取气体{0}成功", GasID));
                if (ChangeGasEvent != null)
                {
                    ChangeGasEvent(null, null);
                }
            }
            catch (CommandException ex)
            {
                Callback(string.Format("读取气体{0}失败", GasID));

                XtraMessageBox.Show(ex.Message);
            }
            catch (Exception ecp)
            {
                Callback(string.Format("读取气体{0}失败", GasID));
                log.Error(ecp);
            }
            finally
            {
                wdf.Close();
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                this.Invoke(new Action(() =>
                {
                    //int index = comboBoxEdit5.SelectedIndex;
                    //comboBoxEdit5.Properties.Items.Clear();
                    //foreach (string port in System.IO.Ports.SerialPort.GetPortNames())
                    //{
                    //    comboBoxEdit5.Properties.Items.Add(port);
                    //}

                    //if (comboBoxEdit5.Properties.Items.Count == 0)
                    //{
                    //    comboBoxEdit5.SelectedIndex = -1;
                    //}
                    //else if (index < 0 && comboBoxEdit5.Properties.Items.Count > 0)
                    //{
                    //    comboBoxEdit5.SelectedIndex = 0;
                    //}
                    //else if (index > comboBoxEdit5.Properties.Items.Count)
                    //{
                    //    comboBoxEdit5.SelectedIndex = comboBoxEdit5.Properties.Items.Count-1;
                    //}

                    dateEdit2.EditValue = DateTime.Now;
                    dateEdit1.EditValue = DateTime.Now;
                }));
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }