<commit_before>using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Runtime.Remoting.Lifetime;
using System.Windows.Forms;
using NationalInstruments;
using NationalInstruments.DAQmx;
using NationalInstruments.UI;
using NationalInstruments.UI.WindowsForms;
using NationalInstruments.VisaNS;

using DAQ.HAL;
using DAQ.Environment;

namespace EDMHardwareControl
{
    /// <summary>
    /// This is the interface to the edm specific hardware.
    /// 
    /// Everything is just bundled into a single
    /// class. The methods/properties are grouped: the first set change the state of the hardware, these
    /// usually act immediately, but sometimes you need to call an update method. Read the code to find out
    /// which are which. The second set of methods read out the state of the hardware. These invariably need
    /// to be brought up to date with an update method before use.
    /// </summary>
    public class Controller : MarshalByRefObject
    {
        #region Constants
        private const double greenSynthOffAmplitude = -130.0;
        private const double redSynthOffFrequency = 36.0;
        private const int eDischargeTime = 5000;
        private const int eBleedTime = 1000;
        private const int eWaitTime = 500;
        private const int eChargeTime = 5000;
        // E field monitor scale factors - what you need to multiply the monitor voltage by
        // to get the plate voltage
        public double CPlusMonitorScale { get { return 10000; } }
        public double CMinusMonitorScale { get { return 10000; } }
        // E field controller mode
        /*private enum EFieldMode { TTL, GPIB };
        private EFieldMode eFieldMode = EFieldMode.TTL;*/
        //Current Leakage Monitor calibration 
        //Convention for monitor to plate mapping:
        //north -> monitor1
        //south -> monitor2
        private static double northSlope = 200;
        private static double southSlope = 200;
        private static double northOffset = 0;
        private static double southOffset = 0;
        private static double currentMonitorMeasurementTime = 0.01;



        #endregion

        #region Setup

        // hardware
        HP8657ASynth greenSynth = (HP8657ASynth)Environs.Hardware.GPIBInstruments["green"];
        Synth redSynth = (Synth)Environs.Hardware.GPIBInstruments["red"];
        ICS4861A voltageController = (ICS4861A)Environs.Hardware.GPIBInstruments["4861"];
        HP34401A bCurrentMeter = (HP34401A)Environs.Hardware.GPIBInstruments["bCurrentMeter"];
        Agilent53131A rfCounter = (Agilent53131A)Environs.Hardware.GPIBInstruments["rfCounter"];
        HP438A rfPower = (HP438A)Environs.Hardware.GPIBInstruments["rfPower"];
        Hashtable digitalTasks = new Hashtable();
        LeakageMonitor northLeakageMonitor =
            new LeakageMonitor((CounterChannel)Environs.Hardware.CounterChannels["northLeakage"], northSlope, northOffset, currentMonitorMeasurementTime);
        LeakageMonitor southLeakageMonitor =
            new LeakageMonitor((CounterChannel)Environs.Hardware.CounterChannels["southLeakage"], southSlope, southOffset, currentMonitorMeasurementTime);
        BrilliantLaser yag = (BrilliantLaser)Environs.Hardware.YAG;
        Task bBoxAnalogOutputTask;
        Task steppingBBiasAnalogOutputTask;
        Task flPZTVAnalogOutputTask;
        Task rf1AttenuatorOutputTask;
        Task rf2AttenuatorOutputTask;
        Task rf1FMOutputTask;
        Task rf2FMOutputTask;
        Task probeMonitorInputTask;
        Task pumpMonitorInputTask;
        Task cPlusOutputTask;
        Task cMinusOutputTask;
        Task cPlusMonitorInputTask;
        Task cMinusMonitorInputTask;
        //Task rfPowerMonitorInputTask;
        Task phaseScramblerVoltageOutputTask;
        Task miniFlux1MonitorInputTask;
        Task miniFlux2MonitorInputTask;
        Task miniFlux3MonitorInputTask;
        Task piMonitorTask;

        AxMG17MotorLib.AxMG17Motor motorController1;
        AxMG17MotorLib.AxMG17Motor motorController2;

        ControlWindow window;

        // without this method, any remote connections to this object will time out after
        // five minutes of inactivity.
        // It just overrides the lifetime lease system completely.
        public override Object InitializeLifetimeService()
        {
            return null;
        }


        public void Start()
        {
            // make the digital tasks
            //CreateDigitalTask("notEOnOff");
            //CreateDigitalTask("eOnOff");
            CreateDigitalTask("ePol");
            CreateDigitalTask("notEPol");
            CreateDigitalTask("eBleed");
            CreateDigitalTask("rfSwitch");
            CreateDigitalTask("fmSelect");
            CreateDigitalTask("attenuatorSelect");
            CreateDigitalTask("scramblerEnable");
            CreateDigitalTask("b");
            CreateDigitalTask("notDB");
            CreateDigitalTask("piFlip");
            CreateDigitalTask("piFlipEnable");
            CreateDigitalTask("notPIFlipEnable");
            CreateDigitalTask("pumpShutter");
            CreateDigitalTask("probeShutter");
            CreateDigitalTask("argonShutter");
            CreateDigitalTask("targetStepper");

            // initialise the current leakage monitors
            northLeakageMonitor.Initialize();
            southLeakageMonitor.Initialize();


            // analog outputs
            bBoxAnalogOutputTask = CreateAnalogOutputTask("b");
            steppingBBiasAnalogOutputTask = CreateAnalogOutputTask("steppingBBias");
            flPZTVAnalogOutputTask = CreateAnalogOutputTask("flPZT");
            rf1AttenuatorOutputTask = CreateAnalogOutputTask("rf1Attenuator");
            rf2AttenuatorOutputTask = CreateAnalogOutputTask("rf2Attenuator");
            rf1FMOutputTask = CreateAnalogOutputTask("rf1FM");
            rf2FMOutputTask = CreateAnalogOutputTask("rf2FM");
            cPlusOutputTask = CreateAnalogOutputTask("cPlus");
            cMinusOutputTask = CreateAnalogOutputTask("cMinus");
            phaseScramblerVoltageOutputTask = CreateAnalogOutputTask("phaseScramblerVoltage");

            // analog inputs
            probeMonitorInputTask = CreateAnalogInputTask("probePD", 0, 5);
            pumpMonitorInputTask = CreateAnalogInputTask("pumpPD", 0, 5);
            cPlusMonitorInputTask = CreateAnalogInputTask("cPlusMonitor");
            cMinusMonitorInputTask = CreateAnalogInputTask("cMinusMonitor");
            //rfPowerMonitorInputTask = CreateAnalogInputTask("rfPower");
            miniFlux1MonitorInputTask = CreateAnalogInputTask("miniFlux1");
            miniFlux2MonitorInputTask = CreateAnalogInputTask("miniFlux2");
            miniFlux3MonitorInputTask = CreateAnalogInputTask("miniFlux3");
            piMonitorTask = CreateAnalogInputTask("piMonitor");

            // make the control window
            window = new ControlWindow();
            window.controller = this;

            // initialise the motor controllers - this needs to be done
            // after the window is made because the ActiveX object needs
            // to live in the window.
            motorController1 = window.motorController1;
            motorController1.StartCtrl();
            motorController2 = window.motorController2;
            motorController2.StartCtrl();


            Application.Run(window);
        }

        // this method runs immediately after the GUI sets up
        internal void WindowLoaded()<commit_msg>Set default polarisation rotator values in EDMHardwareControl/Controller.cs to their maximums.<commit_after>using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Runtime.Remoting.Lifetime;
using System.Windows.Forms;
using NationalInstruments;
using NationalInstruments.DAQmx;
using NationalInstruments.UI;
using NationalInstruments.UI.WindowsForms;
using NationalInstruments.VisaNS;

using DAQ.HAL;
using DAQ.Environment;

namespace EDMHardwareControl
{
    /// <summary>
    /// This is the interface to the edm specific hardware.
    /// 
    /// Everything is just bundled into a single
    /// class. The methods/properties are grouped: the first set change the state of the hardware, these
    /// usually act immediately, but sometimes you need to call an update method. Read the code to find out
    /// which are which. The second set of methods read out the state of the hardware. These invariably need
    /// to be brought up to date with an update method before use.
    /// </summary>
    public class Controller : MarshalByRefObject
    {
        #region Constants
        private const double greenSynthOffAmplitude = -130.0;
        private const double redSynthOffFrequency = 36.0;
        private const int eDischargeTime = 5000;
        private const int eBleedTime = 1000;
        private const int eWaitTime = 500;
        private const int eChargeTime = 5000;
        // E field monitor scale factors - what you need to multiply the monitor voltage by
        // to get the plate voltage
        public double CPlusMonitorScale { get { return 10000; } }
        public double CMinusMonitorScale { get { return 10000; } }
        // E field controller mode
        /*private enum EFieldMode { TTL, GPIB };
        private EFieldMode eFieldMode = EFieldMode.TTL;*/
        //Current Leakage Monitor calibration 
        //Convention for monitor to plate mapping:
        //north -> monitor1
        //south -> monitor2
        private static double northSlope = 200;
        private static double southSlope = 200;
        private static double northOffset = 0;
        private static double southOffset = 0;
        private static double currentMonitorMeasurementTime = 0.01;



        #endregion

        #region Setup

        // hardware
        HP8657ASynth greenSynth = (HP8657ASynth)Environs.Hardware.GPIBInstruments["green"];
        Synth redSynth = (Synth)Environs.Hardware.GPIBInstruments["red"];
        ICS4861A voltageController = (ICS4861A)Environs.Hardware.GPIBInstruments["4861"];
        HP34401A bCurrentMeter = (HP34401A)Environs.Hardware.GPIBInstruments["bCurrentMeter"];
        Agilent53131A rfCounter = (Agilent53131A)Environs.Hardware.GPIBInstruments["rfCounter"];
        HP438A rfPower = (HP438A)Environs.Hardware.GPIBInstruments["rfPower"];
        Hashtable digitalTasks = new Hashtable();
        LeakageMonitor northLeakageMonitor =
            new LeakageMonitor((CounterChannel)Environs.Hardware.CounterChannels["northLeakage"], northSlope, northOffset, currentMonitorMeasurementTime);
        LeakageMonitor southLeakageMonitor =
            new LeakageMonitor((CounterChannel)Environs.Hardware.CounterChannels["southLeakage"], southSlope, southOffset, currentMonitorMeasurementTime);
        BrilliantLaser yag = (BrilliantLaser)Environs.Hardware.YAG;
        Task bBoxAnalogOutputTask;
        Task steppingBBiasAnalogOutputTask;
        Task flPZTVAnalogOutputTask;
        Task rf1AttenuatorOutputTask;
        Task rf2AttenuatorOutputTask;
        Task rf1FMOutputTask;
        Task rf2FMOutputTask;
        Task probeMonitorInputTask;
        Task pumpMonitorInputTask;
        Task cPlusOutputTask;
        Task cMinusOutputTask;
        Task cPlusMonitorInputTask;
        Task cMinusMonitorInputTask;
        //Task rfPowerMonitorInputTask;
        Task phaseScramblerVoltageOutputTask;
        Task miniFlux1MonitorInputTask;
        Task miniFlux2MonitorInputTask;
        Task miniFlux3MonitorInputTask;
        Task piMonitorTask;

        AxMG17MotorLib.AxMG17Motor motorController1;
        AxMG17MotorLib.AxMG17Motor motorController2;

        ControlWindow window;

        // without this method, any remote connections to this object will time out after
        // five minutes of inactivity.
        // It just overrides the lifetime lease system completely.
        public override Object InitializeLifetimeService()
        {
            return null;
        }


        public void Start()
        {
            // make the digital tasks
            //CreateDigitalTask("notEOnOff");
            //CreateDigitalTask("eOnOff");
            CreateDigitalTask("ePol");
            CreateDigitalTask("notEPol");
            CreateDigitalTask("eBleed");
            CreateDigitalTask("rfSwitch");
            CreateDigitalTask("fmSelect");
            CreateDigitalTask("attenuatorSelect");
            CreateDigitalTask("scramblerEnable");
            CreateDigitalTask("b");
            CreateDigitalTask("notDB");
            CreateDigitalTask("piFlip");
            CreateDigitalTask("piFlipEnable");
            CreateDigitalTask("notPIFlipEnable");
            CreateDigitalTask("pumpShutter");
            CreateDigitalTask("probeShutter");
            CreateDigitalTask("argonShutter");
            CreateDigitalTask("targetStepper");

            // initialise the current leakage monitors
            northLeakageMonitor.Initialize();
            southLeakageMonitor.Initialize();


            // analog outputs
            bBoxAnalogOutputTask = CreateAnalogOutputTask("b");
            steppingBBiasAnalogOutputTask = CreateAnalogOutputTask("steppingBBias");
            flPZTVAnalogOutputTask = CreateAnalogOutputTask("flPZT");
            rf1AttenuatorOutputTask = CreateAnalogOutputTask("rf1Attenuator");
            rf2AttenuatorOutputTask = CreateAnalogOutputTask("rf2Attenuator");
            rf1FMOutputTask = CreateAnalogOutputTask("rf1FM");
            rf2FMOutputTask = CreateAnalogOutputTask("rf2FM");
            cPlusOutputTask = CreateAnalogOutputTask("cPlus");
            cMinusOutputTask = CreateAnalogOutputTask("cMinus");
            phaseScramblerVoltageOutputTask = CreateAnalogOutputTask("phaseScramblerVoltage");

            // analog inputs
            probeMonitorInputTask = CreateAnalogInputTask("probePD", 0, 5);
            pumpMonitorInputTask = CreateAnalogInputTask("pumpPD", 0, 5);
            cPlusMonitorInputTask = CreateAnalogInputTask("cPlusMonitor");
            cMinusMonitorInputTask = CreateAnalogInputTask("cMinusMonitor");
            //rfPowerMonitorInputTask = CreateAnalogInputTask("rfPower");
            miniFlux1MonitorInputTask = CreateAnalogInputTask("miniFlux1");
            miniFlux2MonitorInputTask = CreateAnalogInputTask("miniFlux2");
            miniFlux3MonitorInputTask = CreateAnalogInputTask("miniFlux3");
            piMonitorTask = CreateAnalogInputTask("piMonitor");

            // make the control window
            window = new ControlWindow();
            window.controller = this;

            // initialise the motor controllers - this needs to be done
            // after the window is made because the ActiveX object needs
            // to live in the window.
            motorController1 = window.motorController1;
            motorController1.StartCtrl();
            motorController2 = window.motorController2;
            motorController2.StartCtrl();
            // set the velocity and acceleration to maximum.
            motorController1.SetVelParams(0, 0, 10, 14);
            motorController2.SetVelParams(0, 0, 10, 14);

            Application.Run(window);
        }

        // this method runs immediately after the GUI sets up
        internal void WindowLoaded()
{'fraction_non_alphanumeric': 0.07481200591297642, 'fraction_numerical': 0.017867472202583713, 'mean_word_length': 2.781287970838396, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246876', 'n_tokens_mistral': 4310, 'n_tokens_neox': 3983, 'n_words': 987}