public virtual int SetSystemConfiguration2(GlobalsatDeviceConfiguration devConfig, IJobMonitor jobMonitor) { int result = -1; //No need to check if device is connected if (this.Open()) { try { GlobalsatPacket packet = PacketFactory.SetSystemConfiguration2(devConfig.SystemConfigDataRaw); GlobalsatPacket response = (GlobalsatPacket)this.SendPacket(packet); //No info in the response result = 0; } catch (Exception e) { jobMonitor.ErrorText = Properties.Resources.Device_GetInfo_Error + e; } finally { this.Close(); } } if (!this.DataRecieved) { NoCommunicationError(jobMonitor); } return(result); }
private void ButtonImportDeviceConfig_Click(object sender, EventArgs e) { labelStatus.Text = ""; System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();; openFileDialog1.Filter = "Configuration Files (*.cfg)|*.cfg"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { GlobalsatDeviceConfiguration importedDeviceConfig = null; try { importedDeviceConfig = GlobalsatDeviceConfiguration.Load(openFileDialog1.FileName); } catch (Exception) { importedDeviceConfig = null; } if (importedDeviceConfig == null || importedDeviceConfig.SystemConfigDataRaw == null) { MessageDialog.Show(Properties.Resources.UI_Settings_ImportConfig_InvalidConfiguration, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } JobMonitor jobMonitor = new JobMonitor(); try { GlobalsatProtocol device2 = this.fitnessDevice.Device(); if (device2 != null) { GlobalsatDeviceConfiguration currentDeviceConfig = device2.GetSystemConfiguration2(jobMonitor); if (importedDeviceConfig != null && currentDeviceConfig != null && importedDeviceConfig.DeviceName == currentDeviceConfig.DeviceName && importedDeviceConfig.SystemConfigDataRaw.Length == currentDeviceConfig.SystemConfigDataRaw.Length) { device2.SetSystemConfiguration2(importedDeviceConfig, jobMonitor); labelStatus.Text = CommonResources.Text.Devices.ImportJob_Status_ImportComplete; } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error + "Received " + importedDeviceConfig.SystemConfigDataRaw.Length + " bytes "; //MessageDialog.Show(Properties.Resources.UI_Settings_ImportConfig_InvalidConfiguration, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error; } } catch (Exception ex) { jobMonitor.ErrorText += ex.Message; } if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { MessageDialog.Show(jobMonitor.ErrorText, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static GlobalsatDeviceConfiguration Load(string filename) { XmlSerializer serializer = new XmlSerializer(typeof(GlobalsatDeviceConfiguration)); TextReader reader = new StreamReader(filename); GlobalsatDeviceConfiguration configData = (GlobalsatDeviceConfiguration)serializer.Deserialize(reader); reader.Close(); return(configData); }
private void ButtonExportDeviceConfig_Click(object sender, EventArgs e) { labelStatus.Text = ""; try { GlobalsatProtocol device2 = this.fitnessDevice.Device(); GlobalsatDeviceConfiguration currentDeviceConfig = null; JobMonitor jobMonitor = new JobMonitor(); if (device2 != null) { currentDeviceConfig = device2.GetSystemConfiguration2(jobMonitor); } if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { MessageDialog.Show(jobMonitor.ErrorText, Properties.Resources.UI_Settings_ExportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currentDeviceConfig != null) { System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog() { Filter = "Configuration Files (*.cfg)|*.cfg", FileName = currentDeviceConfig.DeviceName }; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { currentDeviceConfig.Save(saveFileDialog1.FileName); labelStatus.Text = CommonResources.Text.MessageExportComplete; //MessageDialog.Show(CommonResources.Text.MessageExportComplete, Properties.Resources.UI_Settings_ExportConfigButton_Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error; } } catch (Exception ex) { MessageDialog.Show(ex.Message, Properties.Resources.UI_Settings_ExportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//Not used as a separate protocol now //public virtual GlobalsatPacket.GlobalsatSystemInformation GetSystemConfiguration(IJobMonitor jobMonitor) //{ // this.Open(); // try // { // GlobalsatPacket packet = PacketFactory.GetSystemConfiguration(); // GlobalsatPacket response = (GlobalsatPacket)this.SendPacket(packet); // GlobalsatPacket.GlobalsatSystemConfiguration systemInfo = response.ResponseGetSystemConfiguration(); // return systemInfo; // } // catch(Exception e) // { // throw new Exception(Properties.Resources.Device_GetInfo_Error+e); // } // finally // { // this.Close(); // } //} public virtual GlobalsatDeviceConfiguration GetSystemConfiguration2(IJobMonitor jobMonitor) { //No need to check if device is connected GlobalsatDeviceConfiguration devConfig = new GlobalsatDeviceConfiguration(); if (this.Open()) { try { GlobalsatPacket packet = PacketFactory.GetSystemConfiguration(); GlobalsatPacket response = (GlobalsatPacket)this.SendPacket(packet); GlobalsatSystemConfiguration systemInfo = response.ResponseGetSystemConfiguration(); devConfig.DeviceName = systemInfo.DeviceName; packet = PacketFactory.GetSystemConfiguration2(); response = (GlobalsatPacket)this.SendPacket(packet); devConfig.SystemConfigDataRaw = response.PacketData; } catch (Exception e) { devConfig = null; jobMonitor.ErrorText = Properties.Resources.Device_GetInfo_Error + e; } finally { this.Close(); } } if (!this.DataRecieved) { NoCommunicationError(jobMonitor); } return(devConfig); }