示例#1
0
        private void button_start_transient_Click(object sender, EventArgs e)
        {
            this.keithley_command_line.clear();
            this.data_grid_view_keithley.Sort(this.data_grid_view_keithley.Columns[0], ListSortDirection.Ascending);

            int index = 0;

            foreach (DataGridViewRow row in this.data_grid_view_keithley.Rows)
            {
                if (!check_if_row_is_empty(row))
                {
                    try
                    {
                        voltage_params param = new voltage_params();
                        param.isSweepModeUsed = false;
                        param.const_voltage   = Convert.ToDouble(row.Cells[1].Value.ToString());
                        Keithley_command command = new Keithley_command(param, row.Cells[3].Value.ToString(), row.Cells[2].Value.ToString(), row.Cells[4].Value.ToString(), row.Cells[5].Value.ToString());
                        this.keithley_command_line.add_command(index, command);
                        index++;
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message + " Try another value.");
                        return;
                    }
                }
            }
            ObjectDelegate del = new ObjectDelegate(process_keithley_output);

            if (this.keithley_thread == null || !this.keithley_thread.IsAlive)
            {
                this.keithley_thread = new Thread(new ParameterizedThreadStart(this.keithley_work));
                this.keithley_thread.Start(del);
            }
        }
 public Keithley_command(voltage_params param, String Duration, String TimeStep, String NPLC, String Range)
 {
     this.voltage = param;
        // if (!this.voltage.isSweepModeUsed && this.voltage.const_voltage > 42)
      //   throw new Exception("Applied Voltage is higher than maximum allowed 42V.");//page 2-2 of User's Manual - Maximum Applied Voltage
     //if(this.voltage.isSweepModeUsed && (Math.Abs(this.voltage.start_voltage) > 42 || Math.Abs(this.voltage.stop_voltage) > 42))
       //  throw new Exception("Applied Voltage is higher than maximum allowed 42V.");//page 2-2 of User's Manual - Maximum Applied Voltage
     this.duration = Convert.ToInt32(Duration);
     if(!param.isSweepModeUsed)
         if (duration < 1 || duration > 2500) //page 7-7 bottom line
             throw new Exception("Time value exceeds the limit 2500s");
     this.time_step = Convert.ToDouble(TimeStep.ToString());
     if (time_step < 0 || time_step >= 1000) //page 7-6
         throw new Exception("Step (Delay) value exceeds the limit");
     this.nplc = NPLC; //page 4-5 of instruction manual
     switch (Range)// page 4-2 of instruction manual
     {
         case "2 nA":
             this.range = "2e-9";
             break;
         case "20 nA":
             this.range = "2e-8";
             break;
         case "200 nA":
             this.range = "2e-7";
             break;
         case "2 uA":
             this.range = "2e-6";
             break;
         case "20 uA":
             this.range = "2e-5";
             break;
         case "200 uA":
             this.range = "2e-4";
             break;
         case "2 mA":
             this.range = "2e-3";
             break;
         case "20 mA":
             this.range = "2e-2";
             break;
         default:
             break;
     }
     //Page 7-6 contains autodelay settings
     if (this.time_step < delay_nplc_limits[range])
         throw new Exception("NPLC is too small for the selected range/delay.");
     //Page 4-5 One PLC for 50Hz is 20msec. So, NPLC*20msec < step
     if (this.time_step < 0.02 * Double.Parse(this.nplc))
         throw new Exception("step is to small for for the selected NPLC.\nOne PLC for 50Hz is 20msec. So, NPLC*20msec < step.\n");
 }
示例#3
0
        public Keithley_command(voltage_params param, String Duration, String TimeStep, String NPLC, String Range)
        {
            this.voltage = param;
            // if (!this.voltage.isSweepModeUsed && this.voltage.const_voltage > 42)
            //   throw new Exception("Applied Voltage is higher than maximum allowed 42V.");//page 2-2 of User's Manual - Maximum Applied Voltage
            //if(this.voltage.isSweepModeUsed && (Math.Abs(this.voltage.start_voltage) > 42 || Math.Abs(this.voltage.stop_voltage) > 42))
            //  throw new Exception("Applied Voltage is higher than maximum allowed 42V.");//page 2-2 of User's Manual - Maximum Applied Voltage
            this.duration = Convert.ToInt32(Duration);
            if (!param.isSweepModeUsed)
            {
                if (duration < 1 || duration > 2500) //page 7-7 bottom line
                {
                    throw new Exception("Time value exceeds the limit 2500s");
                }
            }
            this.time_step = Convert.ToDouble(TimeStep.ToString());
            if (time_step < 0 || time_step >= 1000) //page 7-6
            {
                throw new Exception("Step (Delay) value exceeds the limit");
            }
            this.nplc = NPLC; //page 4-5 of instruction manual
            switch (Range)    // page 4-2 of instruction manual
            {
            case "2 nA":
                this.range = "2e-9";
                break;

            case "20 nA":
                this.range = "2e-8";
                break;

            case "200 nA":
                this.range = "2e-7";
                break;

            case "2 uA":
                this.range = "2e-6";
                break;

            case "20 uA":
                this.range = "2e-5";
                break;

            case "200 uA":
                this.range = "2e-4";
                break;

            case "2 mA":
                this.range = "2e-3";
                break;

            case "20 mA":
                this.range = "2e-2";
                break;

            default:
                break;
            }
            //Page 7-6 contains autodelay settings
            if (this.time_step < delay_nplc_limits[range])
            {
                throw new Exception("NPLC is too small for the selected range/delay.");
            }
            //Page 4-5 One PLC for 50Hz is 20msec. So, NPLC*20msec < step
            if (this.time_step < 0.02 * Double.Parse(this.nplc))
            {
                throw new Exception("step is to small for for the selected NPLC.\nOne PLC for 50Hz is 20msec. So, NPLC*20msec < step.\n");
            }
        }
        private void button_start_transient_Click(object sender, EventArgs e)
        {
            this.keithley_command_line.clear();
            this.data_grid_view_keithley.Sort(this.data_grid_view_keithley.Columns[0], ListSortDirection.Ascending);

            int index = 0;
            foreach (DataGridViewRow row in this.data_grid_view_keithley.Rows)
            {
                if (!check_if_row_is_empty(row))
                {
                    try
                    {
                        voltage_params param = new voltage_params();
                        param.isSweepModeUsed = false;
                        param.const_voltage = Convert.ToDouble(row.Cells[1].Value.ToString());
                        Keithley_command command = new Keithley_command(param, row.Cells[3].Value.ToString(), row.Cells[2].Value.ToString(), row.Cells[4].Value.ToString(), row.Cells[5].Value.ToString());
                        this.keithley_command_line.add_command(index, command);
                        index++;
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message + " Try another value.");
                        return;
                    }
                }
            }
            ObjectDelegate del = new ObjectDelegate(process_keithley_output);
            if (this.keithley_thread == null || !this.keithley_thread.IsAlive)
            {
                this.keithley_thread = new Thread(new ParameterizedThreadStart(this.keithley_work));
                this.keithley_thread.Start(del);
            }
        }
        private void agilent_work(object obj)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            try
            {
                SerialPort agilent = Serial_port_agilent.Instance;
                SerialPort keithley = Serial_port_keithley.Instance;
                //if (false == Serial_port_agilent.try_to_open_com_port()) return;
                if (false == Serial_port_keithley.try_to_open_com_port()) return;
                ObjectDelegate del = (ObjectDelegate)obj;
                foreach (DataGridViewRow row in this.data_grid_view_agilent.Rows)
                {
                    if (!check_if_row_is_empty(row))
                    {
                        //try
                        {
                            NumberStyles style = NumberStyles.Number;

                            voltage_params param = new voltage_params();
                            param.isSweepModeUsed = true;
                            param.start_voltage = Double.Parse(row.Cells[1].Value.ToString(), style);
                            param.stop_voltage = Double.Parse(row.Cells[2].Value.ToString(), style);
                            param.step_voltage = Double.Parse(row.Cells[3].Value.ToString(), style);

                            Keithley_command command_keithley = new Keithley_command(param, "0", row.Cells[4].Value.ToString(),
                                row.Cells[5].Value.ToString(), row.Cells[6].Value.ToString());

                            stop_keithley();

                            List<String> command_list = command_keithley.get_command_string();
                            foreach (String command in command_list)
                                keithley.WriteLine(command);

                            String response = param.start_voltage.ToString() + ", " +
                                param.stop_voltage.ToString() + ", " + param.step_voltage.ToString() + ", ";

                            var regex_pairs = new Regex(@"[+-][0-9].[0-9]*E[+-][0-9]*");
                            String fromBuffer = keithley.ReadLine();

                            MatchCollection MatchList = regex_pairs.Matches(fromBuffer);
                            while (MatchList.Count == 0)
                            {
                                fromBuffer = keithley.ReadLine();
                                MatchList = regex_pairs.Matches(fromBuffer);
                            }
                            response += fromBuffer;

                            del.Invoke(response);
                        }
                    }
                }
            }
            catch (ThreadAbortException abortException)
            {
                logger.Info("Measurement stopped: " + (string)abortException.ExceptionState);
            }
            catch (Exception ex)
            {
                logger.Error("Agilent error: " + ex.ToString());
            }
        }
示例#6
0
        private void agilent_work(object obj)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            try
            {
                SerialPort agilent  = Serial_port_agilent.Instance;
                SerialPort keithley = Serial_port_keithley.Instance;
                //if (false == Serial_port_agilent.try_to_open_com_port()) return;
                if (false == Serial_port_keithley.try_to_open_com_port())
                {
                    return;
                }
                ObjectDelegate del = (ObjectDelegate)obj;
                foreach (DataGridViewRow row in this.data_grid_view_agilent.Rows)
                {
                    if (!check_if_row_is_empty(row))
                    {
                        //try
                        {
                            NumberStyles style = NumberStyles.Number;

                            voltage_params param = new voltage_params();
                            param.isSweepModeUsed = true;
                            param.start_voltage   = Double.Parse(row.Cells[1].Value.ToString(), style);
                            param.stop_voltage    = Double.Parse(row.Cells[2].Value.ToString(), style);
                            param.step_voltage    = Double.Parse(row.Cells[3].Value.ToString(), style);

                            Keithley_command command_keithley = new Keithley_command(param, "0", row.Cells[4].Value.ToString(),
                                                                                     row.Cells[5].Value.ToString(), row.Cells[6].Value.ToString());

                            stop_keithley();

                            List <String> command_list = command_keithley.get_command_string();
                            foreach (String command in command_list)
                            {
                                keithley.WriteLine(command);
                            }

                            String response = param.start_voltage.ToString() + ", " +
                                              param.stop_voltage.ToString() + ", " + param.step_voltage.ToString() + ", ";

                            var    regex_pairs = new Regex(@"[+-][0-9].[0-9]*E[+-][0-9]*");
                            String fromBuffer  = keithley.ReadLine();

                            MatchCollection MatchList = regex_pairs.Matches(fromBuffer);
                            while (MatchList.Count == 0)
                            {
                                fromBuffer = keithley.ReadLine();
                                MatchList  = regex_pairs.Matches(fromBuffer);
                            }
                            response += fromBuffer;

                            del.Invoke(response);
                        }
                    }
                }
            }
            catch (ThreadAbortException abortException)
            {
                logger.Info("Measurement stopped: " + (string)abortException.ExceptionState);
            }
            catch (Exception ex)
            {
                logger.Error("Agilent error: " + ex.ToString());
            }
        }