示例#1
0
        private void keithley_work(object obj)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            try
            {
                List <List <String> > line = this.keithley_command_line.get_command_string();
                Main.clear_buffer_keithley();
                ObjectDelegate del      = (ObjectDelegate)obj;
                SerialPort     keithley = Serial_port_keithley.Instance;

                if (false == Serial_port_keithley.try_to_open_com_port())
                {
                    return;
                }

                int index = 0;
                TransientSession.isFirstSetOfCommands = true;
                foreach (List <String> command_list in line)
                {
                    clear_buffer_keithley();
                    String voltage_command = command_list[0];

                    foreach (String command in command_list)
                    {
                        keithley.WriteLine(command);
                        if (command.Contains("TRIG:COUN"))
                        {
                            lock (TransientSession.mutex)
                            {
                                String[] num_of_ticks = command.Split(' ');
                                TransientSession.voltage     = Convert.ToDouble(this.data_grid_view_keithley.Rows[index].Cells[1].Value.ToString());
                                TransientSession.counterMax  = Int32.Parse(num_of_ticks[1]);
                                TransientSession.currentTick = 0;
                                TransientSession.isReady     = false;
                            }
                        }
                    }
                    //wait till current session stops;
                    while (!TransientSession.isReady)
                    {
                        ;
                    }
                    stop_keithley();
                    lock (TransientSession.mutex)
                    {
                        TransientSession.isFirstSetOfCommands = false;
                    }
                    index++;
                }
            }
            catch (ThreadAbortException abortException)
            {
                logger.Info("Measurement stopped: " + (string)abortException.ExceptionState);
            }
            catch (Exception ex)
            {
                logger.Error("Keithley error: " + ex.ToString());
            }
        }
示例#2
0
        private void stop_keithley()
        {
            SerialPort keithley = Serial_port_keithley.Instance;

            if (false == Serial_port_keithley.try_to_open_com_port())
            {
                return;
            }
            char[] ctrlX = new char[1];
            ctrlX[0] = (char)24;
            keithley.WriteLine(new String(ctrlX));
            keithley.WriteLine("*RST");
            keithley.WriteLine("*CLS");
            keithley.WriteLine("TRAC:CLE");
        }
示例#3
0
        public Main()
        {
            InitializeComponent();
            Serial_port_keithley.setCallback(process_keithley_output);
            GraphPane pane_it = this.ZedGraph_I_t.GraphPane;

            pane_it.XAxis.Title = new AxisLabel("t, ms", "Verdana", (float)14, Color.Black, true, false, false);
            pane_it.YAxis.Title = new AxisLabel("I, A", "Verdana", (float)14, Color.Black, true, false, false);
            pane_it.Title.Text  = "Transient current I(t)"; ZedGraph_I_t.AxisChange();
            ZedGraph_I_t.Invalidate();
            GraphPane pane_iv = this.ZedGraph_I_V.GraphPane;

            pane_iv.XAxis.Title = new AxisLabel("U, V", "Verdana", (float)14, Color.Black, true, false, false);
            pane_iv.YAxis.Title = new AxisLabel("I, A", "Verdana", (float)14, Color.Black, true, false, false);
            pane_iv.Title.Text  = "Volt-Ampere Characteristic I(V)";
            ZedGraph_I_V.AxisChange();
            ZedGraph_I_V.Invalidate();
        }
示例#4
0
        public static void clear_buffer_keithley()
        {
            SerialPort keithley = Serial_port_keithley.Instance;

            if (false == Serial_port_keithley.try_to_open_com_port())
            {
                return;
            }

            //TODO any other way to clear the output queue?
            keithley.WriteLine("TRAC:CLE"); //page 6-3 of User's Guide
            char[] clear_the_buff = new char[256];
            if (keithley.BytesToRead > 0)
            {
                while (keithley.Read(clear_the_buff, 0, clear_the_buff.Length) == clear_the_buff.Length)
                {
                }
            }
        }
        private void button_keithley_test_connection_Click(object sender, EventArgs e)
        {
            SaveKeithleyComSettings();
            Main.clear_buffer_keithley();
            SerialPort keithley = Serial_port_keithley.Instance;

            if (Serial_port_keithley.try_to_open_com_port() == true)
            {
                keithley.WriteLine("*RST");
                keithley.WriteLine("*IDN?");
                String response = keithley.ReadLine();
                this.label_keithley_com_response.Text = response.ToString();
                this.label_keithley_com_response.Update();
            }
            else
            {
                this.label_keithley_com_response.Text = "Failed to connect";
                this.label_keithley_com_response.Update();
            }
        }
示例#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());
            }
        }