Пример #1
0
        /// <summary>
        /// Возвращяет таблицу калибровки
        /// </summary>
        /// <param name="eprom">EPROM устройства из которого необходимо извлеч данные</param>
        /// <param name="CalibrationParameterName">Имя калибровочного параметра</param>
        /// <returns>Таблица калибровки</returns>
        public LastError GetCalibrationTable(Eprom eprom, CalibrationTableHandle calibrationHandle)
        {
            int[] Indices = { 0x0400, 0x0430, 0x0460, 0x0490, 0x04C0, 0x04F0, 0x0520, 0x0550 };
            foreach (int index in Indices)
            {
                if (eprom.GetByte(index) == calibrationHandle.Name)
                {
                    byte size = eprom.GetByte(index + 3);
                    CalibrationTable table = new CalibrationTable(calibrationHandle.Name, size);

                    int offset = index + 4;         // смещение по которому начинаются калибровочные значения
                    if ((size % 4) != 0) return LastError.Error;

                    for (int i = 0; i < size / 4; i++)
                    {
                        byte[] physical = new byte[2];
                        byte[] calibrated = new byte[2];

                        physical[1] = eprom.GetByte(offset++);
                        physical[0] = eprom.GetByte(offset++);

                        calibrated[1] = eprom.GetByte(offset++);
                        calibrated[0] = eprom.GetByte(offset++);

                        Parameter param = new Parameter();

                        param.Physical = (ushort)BitConverter.ToInt16(physical, 0);
                        param.Calibrated = (ushort)BitConverter.ToInt16(calibrated, 0);

                        table.Parameters.Add(param);
                    }
                    calibrationHandle.CalibrationTable = table;
                    return LastError.Success;
                }
            }
            return LastError.Error;
        }
Пример #2
0
        // ----- Загрузка --------
        /// <summary>
        /// Загрузка конфигурации из файла
        /// </summary>
        /// <param name="settingsFilePath">URI файла конфигурации</param>
        /// <returns></returns>
        public static Settings Load(string settingsFilePath)
        {
            XmlTextReader reader = null;
            Settings settings = new Settings();

            try
            {
                Parameter parameter = null;
                reader = new XmlTextReader(settingsFilePath);

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:

                            parameter = new Parameter(reader.Name);
                            while (reader.MoveToNextAttribute())
                            {
                                Property property = new Property(reader.Name, reader.Value);
                                parameter.Insert(property);
                            }
                            break;

                        case XmlNodeType.Text:

                            if (parameter != null)
                                parameter.Value = reader.Value;

                            break;

                        case XmlNodeType.EndElement:

                            if (settings != null)
                            {
                                if (parameter != null)
                                {
                                    settings.Insert(parameter);
                                    parameter = null;
                                }
                            }
                            break;
                    }
                }
                settings.SettingsFilePath = settingsFilePath;
                return settings;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
            }
            finally
            {
                if (reader != null) reader.Close();
            }
        }
Пример #3
0
        private void settings_Click(object sender, EventArgs e)
        {
            Options opt = new Options();

            opt.textBoxHost.Text = host;
            opt.textBoxPort.Text = port.ToString();
            opt.checkBoxAutostart.Checked = autoconnect;

            opt.numericUpDownDownTime.Value = DownTime;
            opt.numericUpDownMaxPacketsCount.Value = MaxPacketsCount;
            opt.numericUpDownSpeedSyrvey.Value = SpeedSurvey;
            opt.numericUpDownWaitTimeForWorking.Value = WaitTimeForWorking;

            if (opt.ShowDialog(this) == DialogResult.OK)
            {
                host = opt.textBoxHost.Text;
                port = Convert.ToInt32(opt.textBoxPort.Text);
                autoconnect = opt.checkBoxAutostart.Checked;

                DownTime = (int)opt.numericUpDownDownTime.Value;
                MaxPacketsCount = (int)opt.numericUpDownMaxPacketsCount.Value;
                SpeedSurvey = (int)opt.numericUpDownSpeedSyrvey.Value;
                WaitTimeForWorking = (int)opt.numericUpDownWaitTimeForWorking.Value;

                Settings sett = Settings.CreateNewSettings();

                Parameter _host = new Parameter("host");
                Parameter _port = new Parameter("port");

                Parameter _autoconnect = new Parameter("autoconnect");
                Parameter _SpeedSurvey = new Parameter("SpeedSurvey");

                Parameter _DownTime = new Parameter("DownTime");
                Parameter _MaxPacketsCount = new Parameter("MaxPacketsCount");
                Parameter _WaitTimeForWorking = new Parameter("WaitTimeForWorking");

                _host.Value = host;
                _port.Value = port.ToString();
                _autoconnect.Value = autoconnect.ToString();

                _DownTime.Value = DownTime.ToString();
                _SpeedSurvey.Value = SpeedSurvey.ToString();
                _MaxPacketsCount.Value = MaxPacketsCount.ToString();
                _WaitTimeForWorking.Value = WaitTimeForWorking.ToString();

                sett.Insert(_host);
                sett.Insert(_port);
                sett.Insert(_autoconnect);

                sett.Insert(_DownTime);
                sett.Insert(_SpeedSurvey);
                sett.Insert(_MaxPacketsCount);
                sett.Insert(_WaitTimeForWorking);

                sett.Save("config.xml", SaveOptions.CreateNewXml);
            }
        }
Пример #4
0
 // ---- Управление параметрами -----
 /// <summary>
 /// Добавить параметр
 /// </summary>
 /// <param name="parameter">Добавляемый параметр</param>
 public void Insert(Parameter parameter)
 {
     parameters.Add(parameter);
 }
Пример #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            notifyIcon.Icon = Properties.Resources.disconnect;
            string set_file = "config.xml";
            if (System.IO.File.Exists(set_file))
            {
                Settings setts = Settings.Load(set_file);
                foreach (Parameter parameter in setts.Parameters)
                {
                    switch (parameter.Name)
                    {
                        case "host":

                            host = parameter.Value;
                            break;

                        case "port":

                            port = Convert.ToInt32(parameter.Value);
                            break;

                        case "autoconnect":

                            autoconnect = Convert.ToBoolean(parameter.Value);
                            break;

                        case "SpeedSurvey":

                            SpeedSurvey = Convert.ToInt32(parameter.Value);
                            break;

                        case "DownTime":

                            DownTime = Convert.ToInt32(parameter.Value);
                            break;

                        case "MaxPacketsCount":

                            MaxPacketsCount = Convert.ToInt32(parameter.Value);
                            break;

                        case "WaitTimeForWorking":

                            WaitTimeForWorking = Convert.ToInt32(parameter.Value);
                            break;
                    }
                }
            }
            else
            {
                Settings sett = Settings.CreateNewSettings();

                Parameter _host = new Parameter("host");
                Parameter _port = new Parameter("port");
                Parameter _autoconnect = new Parameter("autoconnect");
                Parameter _SpeedSurvey = new Parameter("SpeedSurvey");
                Parameter _DownTime = new Parameter("DownTime");
                Parameter _MaxPacketsCount = new Parameter("MaxPacketsCount");
                Parameter _WaitTimeForWorking = new Parameter("WaitTimeForWorking");

                _host.Value = host;
                _port.Value = port.ToString();
                _autoconnect.Value = autoconnect.ToString();

                _DownTime.Value = DownTime.ToString();
                _SpeedSurvey.Value = SpeedSurvey.ToString();
                _MaxPacketsCount.Value = MaxPacketsCount.ToString();
                _WaitTimeForWorking.Value = WaitTimeForWorking.ToString();

                sett.Insert(_host);
                sett.Insert(_port);
                sett.Insert(_autoconnect);
                sett.Insert(_DownTime);
                sett.Insert(_SpeedSurvey);
                sett.Insert(_MaxPacketsCount);
                sett.Insert(_WaitTimeForWorking);

                sett.Save(set_file, SaveOptions.CreateNewXml);
            }

            // ------- загрузка плагинов -----

            m = Manager.GetManager(this);

            m.DownTime = DownTime;
            m.MaxPacketsCount = MaxPacketsCount;
            m.SpeedSurvey = SpeedSurvey;
            m.WaitTimeForWorking = WaitTimeForWorking;

            m.PluginUnload += new Message(m_PluginUnload);
            m.Load(Application.StartupPath);
        }