/**
         * Returns true if the new value requested is different from the previous value
         * Return false if not
         * */
        private bool newValue(int chn, double value, PSUIOValues field)
        {
            bool retval = false;

            switch (field)
            {
            case PSUIOValues.SetCurrent:
                if (previousCurrent[chn] != value)
                {
                    retval = true;
                    previousCurrent[chn] = value;
                }
                break;

            case PSUIOValues.SetVoltage:
                if (previousVoltage[chn] != value)
                {
                    retval = true;
                    previousVoltage[chn] = value;
                }
                break;

            default:
                break;
            }

            return(retval);
        }
Esempio n. 2
0
        /**
         * Interpret the command and return the proper string
         * represenation for the PSU
         * */
        private string getCmd(PSUIOValues val)
        {
            string cmd = "";

            switch (val)
            {
            case PSUIOValues.CurrentSet:
            case PSUIOValues.SetCurrent:


                cmd = "ISET";
                break;

            case PSUIOValues.VoltageSet:
            case PSUIOValues.SetVoltage:
                cmd = "VSET";
                break;

            case PSUIOValues.CurrentOut:
                cmd = "IOUT";
                break;

            case PSUIOValues.VoltageOut:
                cmd = "VOUT";
                break;

            default:
                break;
            }
            return(cmd);
        }
        /**
         * Set a value (e.g. current)
         * */
        private void setValue(int chn, double value, PSUIOValues field)
        {
            if (validateChannel(chn))  //&& newValue(chn,value,field))
            {
                string command = getCmd(field, chn, value);

                sendCommand(command);
            }
        }
Esempio n. 4
0
        /**
         * Set a value (e.g. current)
         * */
        private void setValue(int chn, double value, PSUIOValues field)
        {
            if (validateChannel(chn))  //&& newValue(chn,value,field))
            {
                string cmd = getCmd(field);



                string command = cmd + (chn + 1).ToString(CultureInfo.InvariantCulture) + ":" + value.ToString(CultureInfo.InvariantCulture);

                sendCommand(command);
            }
        }
        /**
         * Interpret the command and return the proper string
         * PSUIOValues indicates the type of action requested
         * int chn the channel number
         * double value the optional output value
         * represenation for the PSU
         * */
        private string getCmd(PSUIOValues val, int chn, double value)
        {
            string cmd = "";

            switch (val)
            {
            case PSUIOValues.CurrentSet:
                cmd = "I1?";
                break;

            case PSUIOValues.SetCurrent:
                cmd = "I1 " + value.ToString(CultureInfo.InvariantCulture);
                break;

            case PSUIOValues.VoltageSet:
                cmd = "V1?";
                break;

            case PSUIOValues.SetVoltage:
                cmd = "V1 " + value.ToString(CultureInfo.InvariantCulture);
                break;

            case PSUIOValues.CurrentOut:
                cmd = "I1O?";
                break;

            case PSUIOValues.VoltageOut:
                cmd = "V1O?";
                break;

            default:
                break;
            }



            return(cmd);
        }
Esempio n. 6
0
        /**
         * Get the specified value from the PSU
         * */
        private double getValue(int chn, PSUIOValues val)
        {
            double retval = 0;

            if (validateChannel(chn))
            {
                string cmd = getCmd(val);
                //remember to add one since the PSU assumes channel 1 and 2, i.e. is index-1 based
                string command = cmd + (chn + 1).ToString() + "?";
                //flag the datareceived to be false so the eventhandler will start picking up data
                dataReceived       = false;
                dataStringReceived = "";
                //send the command to the PSU
                sendCommand(command);

                //set values for the wait loop
                int ti_max = 200;
                int ti     = 0;
                while (!dataReceived && ti < ti_max)
                {
                    Thread.Sleep(1);
                    ti++;
                }
                //convert the received string to a useful number
                string s = dataStringReceived;;
                try
                {
                    string subStr = dataStringReceived.Substring(0, dataStringReceived.Length - 1);

                    retval = Double.Parse(subStr, CultureInfo.InvariantCulture);
                }
                catch (Exception ex)
                {
                }
            }

            return(retval);
        }
        /**
         * Get the specified value from the PSU
         * */
        private double getValue(int chn, PSUIOValues val)
        {
            double retval = 0;

            if (validateChannel(chn) && mbSession != null)
            {
                string command = getCmd(val, chn, 0);
                mbSession.RawIO.Write(command + "\n");
                // string retString = mbSession.RawIO.ReadString();
                string retString = "";
                try
                {
                    retval = Convert.ToDouble(retString, CultureInfo.InvariantCulture);
                }
                catch (FormatException ex)
                {
                }
                catch (OverflowException ex)
                {
                }
            }
            return(retval);
        }
        /**
         * Get the specified value from the PSU
         * */
        private double getValue(int chn, PSUIOValues val)
        {
            double retval = 0;

            if (validateChannel(chn) && mbSession != null)
            {
                string command = getCmd(val, chn, 0);
                mbSession.RawIO.Write(command + "\n");
                Thread.Sleep(100);
                string retString = mbSession.RawIO.ReadString();
                try
                {
                    //The format of the output is "V 1 VAL" (V is for voltage; if a current is returned then V->I)
                    retval = Convert.ToDouble(retString.Substring(3), CultureInfo.InvariantCulture);
                }
                catch (FormatException ex)
                {
                }
                catch (OverflowException ex)
                {
                }
            }
            return(retval);
        }
        /**
         * Interpret the command and return the proper string
         * PSUIOValues indicates the type of action requested
         * int chn the channel number
         * double value the optional output value
         * represenation for the PSU
         * */
        private string getCmd(PSUIOValues val, int chn, double value)
        {
            string cmd = "";

            switch (val)
            {
            case PSUIOValues.CurrentSet:
                cmd = ":CHAN" + (chn + 1).ToString(CultureInfo.InvariantCulture) + ":CURR ?";
                break;

            case PSUIOValues.SetCurrent:
                cmd = ":CHAN" + (chn + 1).ToString(CultureInfo.InvariantCulture) + ":CURR " + value.ToString(CultureInfo.InvariantCulture);
                break;

            case PSUIOValues.VoltageSet:
                cmd = ":CHAN" + (chn + 1).ToString(CultureInfo.InvariantCulture) + ":VOLT ?";
                break;

            case PSUIOValues.SetVoltage:
                cmd = ":CHAN" + (chn + 1).ToString(CultureInfo.InvariantCulture) + ":VOLT " + value.ToString(CultureInfo.InvariantCulture);
                break;

            case PSUIOValues.CurrentOut:
                cmd = ":CHAN" + (chn + 1).ToString(CultureInfo.InvariantCulture) + ":MEAS:CURR ?";
                break;

            case PSUIOValues.VoltageOut:
                cmd = ":CHAN" + (chn + 1).ToString(CultureInfo.InvariantCulture) + ":MEAS:VOLT ?";
                break;

            default:
                break;
            }

            return(cmd);
        }