public static void writeConfig(string filename, configModel model) { XmlSerializer serializer = new XmlSerializer(typeof(configModel)); Stream fs = new FileStream(filename, FileMode.Create); XmlWriter writer = new XmlTextWriter(fs, Encoding.Unicode); serializer.Serialize(writer, model); writer.Close(); }
public static configModel readConfig(string filename) { XmlSerializer ser = new XmlSerializer(typeof(configModel)); configModel model = new configModel(); using (XmlReader reader = XmlReader.Create(filename)) { model = (configModel)ser.Deserialize(reader); } return(model); }
public MainForm(Eth32 dev) { //set up UI control attributes (auto-generated) InitializeComponent(); this.dev = dev; //setup for jog button handler thread, triggering event jogEvent = new ManualResetEvent(false); this.buttonThread = new Thread(buttonThreadHandler); this.buttonThread.Start(); //try to read config file - open config dialog if not found string configFile = Application.StartupPath + "\\dishConfig.xml"; if (File.Exists(configFile)) { settings = configFileHandler.readConfig(configFile); appConfigured = true; }//if config exists else { settings = new configModel(); Config cfgDialog = new Config(dev, this.settings); if (cfgDialog.ShowDialog() == DialogResult.OK) { configFileHandler.writeConfig(configFile, cfgDialog.settings); MessageBox.Show("Saved"); appConfigured = true; } }//no config found state = DishState.Unknown; //set up presets, set up various Motion control objects, logger but only if config exists and is valid. if (appConfigured) { //get presets array Presets = settings.getPresetList(); foreach (presets p in Presets) { if (!String.IsNullOrEmpty(p.Text)) { presetSelector.Items.Add(p.Text); } } presetSelector.SelectedIndex = 0; RollingLogger.setupRollingLogger(settings.positionFileLog, settings.maxPosLogSizeBytes, settings.maxPosLogFiles); }//if config exists }
public testDrive(Eth32 dev, configModel settings, MainForm main) { this.dev = dev; this.settings = settings; this.form = main; this.azPos = this.form.azReadPosition(); this.elPos = this.form.elReadPosition(); this.form.setAz(0.0); this.form.setEl(0.0); InitializeComponent(); this.azimuth.Text = String.Format("{0:0.00}", this.azPos); this.elevation.Text = String.Format("{0:0.00}", this.elPos); timer = new System.Windows.Forms.Timer(); timer.Interval = 100; timer.Enabled = true; timer.Tick += new EventHandler(timer1_Tick); }
public Encoder(Eth32 dev, configModel config, bool isAz = true) { this.coding = config.coding; this.outputPort = config.outputPort; this.device = dev; if (isAz) { this.RevsPerRot = config.AzimuthRevsPerRot; this.EncoderBits = config.AzimuthEncoderBits; this.StartBit = config.AzimuthStartBit; this.OffsetDeg = config.AzimuthOffsetDeg; } else { this.RevsPerRot = config.ElevationRevsPerRot; this.EncoderBits = config.ElevationEncoderBits; this.StartBit = config.ElevationStartBit; this.OffsetDeg = config.ElevationOffsetDeg; } string resultString = Regex.Match(this.outputPort, @"\d+").Value; Int32.TryParse(resultString, out outputPortNum); }
public Config(Eth32 dev, configModel settings) { InitializeComponent(); this.dev = dev; this.settings = settings; if (settings.AzimuthEncoderBits != 0) { this.latitude.Text = GeoAngle.FromDouble(settings.latitude).ToString("NS"); this.longitude.Text = GeoAngle.FromDouble(settings.longitude).ToString("WE"); this.altitude.Text = settings.altitude.ToString(); this.alpha.Text = settings.alpha.ToString(); this.AzRevsPerRot.Text = settings.AzimuthRevsPerRot.ToString(); this.encBitsAz.Text = settings.AzimuthEncoderBits.ToString(); this.AzStartBit.Text = settings.AzimuthStartBit.ToString(); this.AzOffset.Text = settings.AzimuthOffsetDeg.ToString(); this.ElRevsPerRot.Text = settings.ElevationRevsPerRot.ToString(); this.encBitsEl.Text = settings.ElevationEncoderBits.ToString(); this.ElStartBit.Text = settings.ElevationStartBit.ToString(); this.ElOffset.Text = settings.ElevationOffsetDeg.ToString(); this.encoder_coding.SelectedItem = settings.coding.ToString(); this.cmbETH32.Items.Add(settings.eth32Address); this.cmbETH32.SelectedItem = settings.eth32Address; this.outputPort.SelectedItem = settings.outputPort; this.jogIncrement.Text = settings.jogIncrement.ToString(); this.driveEnableBit.Text = settings.driveEnablebit.ToString(); this.azCBactiveHi.Checked = settings.azActiveHi; this.azCW_CCW.Checked = settings.azDriveType == driveType.CCW; this.azEnbDir.Checked = settings.azDriveType == driveType.DirEnable; this.azBoth.Checked = settings.azDriveType == driveType.Both; if (settings.azDriveType == driveType.CCW) { azCB1.Text = "CW"; azCB2.Text = "CCW"; azCB3.Text = ""; azEnBit.Enabled = false; } else if (settings.azDriveType == driveType.DirEnable) { azCB1.Text = "Dir"; azCB2.Text = "Enable"; azCB3.Text = ""; azEnBit.Enabled = false; } else { azCB1.Text = "CW"; azCB2.Text = "CCW"; azCB3.Text = "Enable"; azEnBit.Enabled = true; } this.azCWbit.Text = settings.azCWbit.ToString(); this.azCCWbit.Text = settings.azCCWbit.ToString(); this.azEnBit.Text = settings.azEnable.ToString(); this.azPWMch.Text = settings.azPWMchan.ToString(); this.azKd.Text = settings.azKd.ToString(); this.azKi.Text = settings.azKi.ToString(); this.azKp.Text = settings.azKp.ToString(); this.Gain.Text = settings.azG.ToString(); this.azMax.Text = settings.azMax.ToString(); this.azMin.Text = settings.azMin.ToString(); this.azOutMax.Text = settings.azOutMax.ToString(); this.azOutMin.Text = settings.azOutMin.ToString(); this.azPark.Text = settings.azPark.ToString(); this.SouthParkPosAz.Text = settings.azSouthPark.ToString(); this.elCBactiveHi.Checked = settings.elActiveHi; this.elCW_CCW.Checked = settings.elDriveType == driveType.CCW; this.elEnbDir.Checked = settings.elDriveType == driveType.DirEnable; this.elBoth.Checked = settings.elDriveType == driveType.Both; if (settings.azDriveType == driveType.CCW) { elCB1.Text = "CW"; elCB2.Text = "CCW"; elCB3.Text = ""; elEnBit.Enabled = false; } else if (settings.azDriveType == driveType.DirEnable) { elCB1.Text = "Dir"; elCB2.Text = "Enable"; elCB3.Text = ""; elEnBit.Enabled = false; } else { elCB1.Text = "CW"; elCB2.Text = "CCW"; elCB3.Text = "Enable"; elEnBit.Enabled = true; } this.elCWbit.Text = settings.elCWbit.ToString(); this.elCCWbit.Text = settings.elCCWbit.ToString(); this.elEnBit.Text = settings.elEnable.ToString(); this.elPWMch.Text = settings.elPWMchan.ToString(); this.elKd.Text = settings.elKd.ToString(); this.elKi.Text = settings.elKi.ToString(); this.elKp.Text = settings.elKp.ToString(); this.elMax.Text = settings.elMax.ToString(); this.elMin.Text = settings.elMin.ToString(); this.elOutMax.Text = settings.elOutMax.ToString(); this.elOutMin.Text = settings.elOutMin.ToString(); this.elPark.Text = settings.elPark.ToString(); this.SouthParkPosEl.Text = settings.elSouthPark.ToString(); this.PosLogFile.Text = settings.positionFileLog; this.maxPosLogSize.Text = settings.maxPosLogSizeBytes.ToString(); this.MaxFiles.Text = settings.maxPosLogFiles.ToString(); this.PS1Name.Text = settings.Preset1Name; this.PS1Az.Text = settings.Preset1Az.ToString(); this.PS1El.Text = settings.Preset1El.ToString(); this.PS2Name.Text = settings.Preset2Name; this.PS2Az.Text = settings.Preset2Az.ToString(); this.PS2El.Text = settings.Preset2El.ToString(); this.PS3Name.Text = settings.Preset3Name; this.PS3Az.Text = settings.Preset3Az.ToString(); this.PS3El.Text = settings.Preset3El.ToString(); this.PS4Name.Text = settings.Preset4Name; this.PS4Az.Text = settings.Preset4Az.ToString(); this.PS4El.Text = settings.Preset4El.ToString(); this.PS5Name.Text = settings.Preset5Name; this.PS5Az.Text = settings.Preset5Az.ToString(); this.PS5El.Text = settings.Preset5El.ToString(); } }