private void applyAnalogs(hardwareState state) { List <string> toRemove = new List <string>(); //In case of errors, keep track of things to delete from the list of changes. foreach (KeyValuePair <string, double> pairs in state.analogs) { try { if (calibrations.ContainsKey(pairs.Key)) { SetAnalogOutput(pairs.Key, pairs.Value, true); } else { SetAnalogOutput(pairs.Key, pairs.Value); } controlWindow.WriteToConsole("Set channel '" + pairs.Key.ToString() + "' to " + pairs.Value.ToString()); } catch (CalibrationException) { controlWindow.WriteToConsole("Failed to set channel '" + pairs.Key.ToString() + "' to new value"); toRemove.Add(pairs.Key); } } foreach (string s in toRemove) //Remove those from the list of changes, as nothing was done to the Hardware. { state.analogs.Remove(s); } }
private void setUIAnalogs(hardwareState state) { foreach (KeyValuePair <string, double> pairs in state.analogs) { controlWindow.SetAnalog(pairs.Key, (double)pairs.Value); } }
private void setUIDigitals(hardwareState state) { foreach (KeyValuePair <string, bool> pairs in state.digitals) { controlWindow.SetDigital(pairs.Key, (bool)pairs.Value); } }
private void applyDigitals(hardwareState state) { foreach (KeyValuePair <string, bool> pairs in state.digitals) { SetDigitalLine(pairs.Key, pairs.Value); controlWindow.WriteToConsole("Set channel '" + pairs.Key.ToString() + "' to " + pairs.Value.ToString()); } }
private hardwareState readValuesOnUI() { hardwareState state = new hardwareState(); state.analogs = readUIAnalogs(stateRecord.analogs.Keys); state.digitals = readUIDigitals(stateRecord.digitals.Keys); return(state); }
public void UpdateHardware() { hardwareState uiState = readValuesOnUI(); hardwareState changes = getDiscrepancies(stateRecord, uiState); applyToHardware(changes); updateStateRecord(changes); }
private void updateStateRecord(hardwareState changes) { foreach (KeyValuePair <string, double> pairs in changes.analogs) { stateRecord.analogs[pairs.Key] = changes.analogs[pairs.Key]; } foreach (KeyValuePair <string, bool> pairs in changes.digitals) { stateRecord.digitals[pairs.Key] = changes.digitals[pairs.Key]; } }
//Load parameters when opening the controller public void LoadParametersWithDialog() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "shc parameters|*.bin"; dialog.Title = "Load parameters"; dialog.InitialDirectory = profilesPath; dialog.ShowDialog(); if (dialog.FileName != "") { stateRecord = loadParameters(dialog.FileName); } setValuesDisplayedOnUI(stateRecord); }
public void Start() { // make the digital analogTasks. The function "CreateDigitalTask" is defined later //e.g CreateDigitalTask("notEOnOff"); // CreateDigitalTask("eOnOff"); //This is to keep track of the various things which the HC controls. analogTasks = new Dictionary <string, Task>(); stateRecord = new hardwareState(); stateRecord.analogs = new Dictionary <string, double>(); stateRecord.digitals = new Dictionary <string, bool>(); tstage = new Parker404XR("ASRL1::INSTR", profilesPath + "TranslationStageInitFile.txt"); CreateDigitalTask("aom0enable"); CreateDigitalTask("aom1enable"); CreateDigitalTask("aom2enable"); CreateDigitalTask("aom3enable"); CreateDigitalTask("shutterenable"); // make the analog output analogTasks. The function "CreateAnalogOutputTask" is defined later //e.g. bBoxAnalogOutputTask = CreateAnalogOutputTask("b"); // steppingBBiasAnalogOutputTask = CreateAnalogOutputTask("steppingBBias"); CreateAnalogOutputTask("aom0amplitude"); CreateAnalogOutputTask("aom0frequency"); CreateAnalogOutputTask("aom1amplitude"); CreateAnalogOutputTask("aom1frequency"); CreateAnalogOutputTask("aom2amplitude"); CreateAnalogOutputTask("aom2frequency"); CreateAnalogOutputTask("aom3amplitude"); CreateAnalogOutputTask("aom3frequency"); CreateAnalogOutputTask("coil0current"); CreateAnalogOutputTask("coil1current"); CreateAnalogInputTask("laserLockErrorSignal", -10, 10); CreateAnalogInputTask("chamber1Pressure"); CreateAnalogInputTask("chamber2Pressure"); // make the control controlWindow controlWindow = new ControlWindow(); controlWindow.controller = this; HCState = SHCUIControlState.OFF; Application.Run(controlWindow); }
// this method runs immediately after the GUI sets up internal void ControllerLoaded() { hardwareState loadedState = new hardwareState(); loadedState = loadParameters(profilesPath + "StoppedParameters.bin"); foreach (KeyValuePair <string, double> pair in loadedState.analogs) { stateRecord.analogs[pair.Key] = pair.Value; } foreach (KeyValuePair <string, bool> pair in loadedState.digitals) { stateRecord.digitals[pair.Key] = pair.Value; } setValuesDisplayedOnUI(stateRecord); ApplyRecordedStateToHardware(); }
private void StoreParameters(String dataStoreFilePath) { stateRecord = readValuesOnUI(); BinaryFormatter s = new BinaryFormatter(); FileStream fs = new FileStream(dataStoreFilePath, FileMode.Create); try { //s.Serialize(fs, dataStore); s.Serialize(fs, stateRecord); } catch (Exception) { Console.Out.WriteLine("Saving failed"); } finally { fs.Close(); controlWindow.WriteToConsole("Saved parameters to " + dataStoreFilePath); } }
private hardwareState loadParameters(String dataStoreFilePath) { // deserialize BinaryFormatter s = new BinaryFormatter(); FileStream fs; hardwareState state = new hardwareState(); fs = new FileStream(dataStoreFilePath, FileMode.Open); try { state = (hardwareState)s.Deserialize(fs); } catch (Exception e) { MessageBox.Show(e.Message); } finally { fs.Close(); controlWindow.WriteToConsole("Loaded parameters from " + dataStoreFilePath); } return(state); }
private hardwareState getDiscrepancies(hardwareState oldState, hardwareState newState) { hardwareState state = new hardwareState(); state.analogs = new Dictionary <string, double>(); state.digitals = new Dictionary <string, bool>(); foreach (KeyValuePair <string, double> pairs in oldState.analogs) { if (oldState.analogs[pairs.Key] != newState.analogs[pairs.Key]) { state.analogs[pairs.Key] = newState.analogs[pairs.Key]; } } foreach (KeyValuePair <string, bool> pairs in oldState.digitals) { if (oldState.digitals[pairs.Key] != newState.digitals[pairs.Key]) { state.digitals[pairs.Key] = newState.digitals[pairs.Key]; } } return(state); }
private void applyToHardware(hardwareState state) { if (state.analogs.Count != 0 || state.digitals.Count != 0) { if (HCState == SHCUIControlState.OFF) { HCState = SHCUIControlState.LOCAL; controlWindow.UpdateUIState(HCState); applyAnalogs(state); applyDigitals(state); HCState = SHCUIControlState.OFF; controlWindow.UpdateUIState(HCState); controlWindow.WriteToConsole("Update finished!"); } } else { controlWindow.WriteToConsole("The values on the UI are identical to those on the controller's records. Hardware must be up to date."); } }
private void setValuesDisplayedOnUI(hardwareState state) { setUIAnalogs(state); setUIDigitals(state); }
private void updateStateRecord(hardwareState changes) { foreach (KeyValuePair<string, double> pairs in changes.analogs) { stateRecord.analogs[pairs.Key] = changes.analogs[pairs.Key]; } foreach (KeyValuePair<string, bool> pairs in changes.digitals) { stateRecord.digitals[pairs.Key] = changes.digitals[pairs.Key]; } }
private void applyAnalogs(hardwareState state) { List<string> toRemove = new List<string>(); //In case of errors, keep track of things to delete from the list of changes. foreach (KeyValuePair<string, double> pairs in state.analogs) { try { if (calibrations.ContainsKey(pairs.Key)) { SetAnalogOutput(pairs.Key, pairs.Value, true); } else { SetAnalogOutput(pairs.Key, pairs.Value); } controlWindow.WriteToConsole("Set channel '" + pairs.Key.ToString() + "' to " + pairs.Value.ToString()); } catch (CalibrationException) { controlWindow.WriteToConsole("Failed to set channel '"+ pairs.Key.ToString() + "' to new value"); toRemove.Add(pairs.Key); } } foreach (string s in toRemove) //Remove those from the list of changes, as nothing was done to the Hardware. { state.analogs.Remove(s); } }
private void setUIAnalogs(hardwareState state) { foreach (KeyValuePair<string, double> pairs in state.analogs) { controlWindow.SetAnalog(pairs.Key, (double)pairs.Value); } }
public void Start() { // make the digital analogTasks. The function "CreateDigitalTask" is defined later //e.g CreateDigitalTask("notEOnOff"); // CreateDigitalTask("eOnOff"); //This is to keep track of the various things which the HC controls. analogTasks = new Dictionary<string, Task>(); stateRecord = new hardwareState(); stateRecord.analogs = new Dictionary<string, double>(); stateRecord.digitals = new Dictionary<string, bool>(); tstage = new Parker404XR("ASRL1::INSTR", profilesPath + "TranslationStageInitFile.txt"); CreateDigitalTask("aom0enable"); CreateDigitalTask("aom1enable"); CreateDigitalTask("aom2enable"); CreateDigitalTask("aom3enable"); CreateDigitalTask("shutterenable"); // make the analog output analogTasks. The function "CreateAnalogOutputTask" is defined later //e.g. bBoxAnalogOutputTask = CreateAnalogOutputTask("b"); // steppingBBiasAnalogOutputTask = CreateAnalogOutputTask("steppingBBias"); CreateAnalogOutputTask("aom0amplitude"); CreateAnalogOutputTask("aom0frequency"); CreateAnalogOutputTask("aom1amplitude"); CreateAnalogOutputTask("aom1frequency"); CreateAnalogOutputTask("aom2amplitude"); CreateAnalogOutputTask("aom2frequency"); CreateAnalogOutputTask("aom3amplitude"); CreateAnalogOutputTask("aom3frequency"); CreateAnalogOutputTask("coil0current"); CreateAnalogOutputTask("coil1current"); CreateAnalogInputTask("laserLockErrorSignal", -10, 10); CreateAnalogInputTask("chamber1Pressure"); CreateAnalogInputTask("chamber2Pressure"); // make the control controlWindow controlWindow = new ControlWindow(); controlWindow.controller = this; HCState = SHCUIControlState.OFF; Application.Run(controlWindow); }
private hardwareState readValuesOnUI() { hardwareState state = new hardwareState(); state.analogs = readUIAnalogs(stateRecord.analogs.Keys); state.digitals = readUIDigitals(stateRecord.digitals.Keys); return state; }
private hardwareState getDiscrepancies(hardwareState oldState, hardwareState newState) { hardwareState state = new hardwareState(); state.analogs = new Dictionary<string, double>(); state.digitals = new Dictionary<string, bool>(); foreach(KeyValuePair<string, double> pairs in oldState.analogs) { if (oldState.analogs[pairs.Key] != newState.analogs[pairs.Key]) { state.analogs[pairs.Key] = newState.analogs[pairs.Key]; } } foreach (KeyValuePair<string, bool> pairs in oldState.digitals) { if (oldState.digitals[pairs.Key] != newState.digitals[pairs.Key]) { state.digitals[pairs.Key] = newState.digitals[pairs.Key]; } } return state; }
private void applyDigitals(hardwareState state) { foreach (KeyValuePair<string, bool> pairs in state.digitals) { SetDigitalLine(pairs.Key, pairs.Value); controlWindow.WriteToConsole("Set channel '" + pairs.Key.ToString() + "' to " + pairs.Value.ToString()); } }
private void setUIDigitals(hardwareState state) { foreach (KeyValuePair<string, bool> pairs in state.digitals) { controlWindow.SetDigital(pairs.Key, (bool)pairs.Value); } }
//Load parameters when opening the controller public void LoadParametersWithDialog() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "shc parameters|*.bin"; dialog.Title = "Load parameters"; dialog.InitialDirectory = profilesPath; dialog.ShowDialog(); if (dialog.FileName != "") stateRecord = loadParameters(dialog.FileName); setValuesDisplayedOnUI(stateRecord); }
private hardwareState loadParameters(String dataStoreFilePath) { // deserialize BinaryFormatter s = new BinaryFormatter(); FileStream fs; hardwareState state = new hardwareState(); fs = new FileStream(dataStoreFilePath, FileMode.Open); try { state = (hardwareState)s.Deserialize(fs); } catch (Exception e) { MessageBox.Show(e.Message); } finally { fs.Close(); controlWindow.WriteToConsole("Loaded parameters from " + dataStoreFilePath); } return state; }
// this method runs immediately after the GUI sets up internal void ControllerLoaded() { hardwareState loadedState = new hardwareState(); loadedState = loadParameters(profilesPath + "StoppedParameters.bin"); foreach (KeyValuePair<string, double> pair in loadedState.analogs) { stateRecord.analogs[pair.Key] = pair.Value; } foreach (KeyValuePair<string, bool> pair in loadedState.digitals) { stateRecord.digitals[pair.Key] = pair.Value; } setValuesDisplayedOnUI(stateRecord); ApplyRecordedStateToHardware(); }