Example #1
0
        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);
            }
        }
Example #2
0
 private void setUIAnalogs(hardwareState state)
 {
     foreach (KeyValuePair <string, double> pairs in state.analogs)
     {
         controlWindow.SetAnalog(pairs.Key, (double)pairs.Value);
     }
 }
Example #3
0
 private void setUIDigitals(hardwareState state)
 {
     foreach (KeyValuePair <string, bool> pairs in state.digitals)
     {
         controlWindow.SetDigital(pairs.Key, (bool)pairs.Value);
     }
 }
Example #4
0
 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());
     }
 }
Example #5
0
        private hardwareState readValuesOnUI()
        {
            hardwareState state = new hardwareState();

            state.analogs  = readUIAnalogs(stateRecord.analogs.Keys);
            state.digitals = readUIDigitals(stateRecord.digitals.Keys);
            return(state);
        }
Example #6
0
        public void UpdateHardware()
        {
            hardwareState uiState = readValuesOnUI();

            hardwareState changes = getDiscrepancies(stateRecord, uiState);

            applyToHardware(changes);

            updateStateRecord(changes);
        }
Example #7
0
 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];
     }
 }
Example #8
0
        //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);
        }
Example #9
0
        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);
        }
Example #10
0
        // 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();
        }
Example #11
0
        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);
            }
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }
Example #14
0
        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.");
            }
        }
Example #15
0
 private void setValuesDisplayedOnUI(hardwareState state)
 {
     setUIAnalogs(state);
     setUIDigitals(state);
 }
Example #16
0
 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);
     }
 }
Example #17
0
 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];
     }
 }
Example #18
0
        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);
            }
        }
Example #19
0
 private void setUIAnalogs(hardwareState state)
 {
     foreach (KeyValuePair<string, double> pairs in state.analogs)
     {
         controlWindow.SetAnalog(pairs.Key, (double)pairs.Value);
     }
 }
Example #20
0
        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);
        }
Example #21
0
 private hardwareState readValuesOnUI()
 {
     hardwareState state = new hardwareState();
     state.analogs = readUIAnalogs(stateRecord.analogs.Keys);
     state.digitals = readUIDigitals(stateRecord.digitals.Keys);
     return state;
 }
Example #22
0
 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;
 }
Example #23
0
        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.");
            }
        }
Example #24
0
 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());
     }
 }
Example #25
0
 private void setUIDigitals(hardwareState state)
 {
     foreach (KeyValuePair<string, bool> pairs in state.digitals)
     {
         controlWindow.SetDigital(pairs.Key, (bool)pairs.Value);
     }
 }
Example #26
0
 private void setValuesDisplayedOnUI(hardwareState state)
 {
     setUIAnalogs(state);
     setUIDigitals(state);
 }
Example #27
0
 //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);
 }
Example #28
0
 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;
 }
Example #29
0
 // 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();
 }