Exemple #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);
            }
        }
        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());
            }
        }
Exemple #4
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());
            }
        }