Example #1
0
 private void SapiMTAThread()
 {
     while (true)
     {
         try
         {
             _process.WaitOne();
             _exception = null;
             if (_doit != null)
             {
                 _result = _doit();
                 _doit   = null;
             }
             else
             {
                 _doit2();
                 _doit2 = null;
             }
         }
         catch (Exception exception)
         {
             Exception ex = _exception = exception;
         }
         _done.Set();
     }
 }
Example #2
0
        private void RecvPub(IAsyncResult res) // Function used to handle received UDP messages
        {
            IPEndPoint recv = new IPEndPoint(IPAddress.Any, PUBLISH_PORT_NUMBER);

            byte[] message = null;
            string dmessage;

            if (!isClosing)
            {
                message = pub.EndReceive(res, ref recv);
            }

            if (message != null) // If a message was received
            {
                ObjectDelegate del = new ObjectDelegate(HandleUDPDatagram);
                dmessage = Encoding.ASCII.GetString(message);
                del.Invoke(dmessage, recv);
                HandleUDPDatagram(dmessage, recv);
            }

            if (!isClosing)
            {
                pub.BeginReceive(new AsyncCallback(RecvPub), null);
            }
        }
Example #3
0
        public Client(RC6 alg)
        {
            InitializeComponent();

            odabrano = "Alisa";

            timer = new System.Timers.Timer(300);

            timer.Elapsed += new System.Timers.ElapsedEventHandler(Obradi);
            timer.Enabled  = false;

            del = new ObjectDelegate(UpdateTextBox);

            Rc6 = alg;

            txtDestinationText.Enabled = false;
            txtSourceText.Enabled      = false;
            btnSend.Enabled            = false;

            lblPrimUnesi.Text = "Unesi poruku ispod";
            lblPrimPosl.Text  = "Poslato:";

            btnPokreni.Left    = (this.ClientSize.Width - btnPokreni.Size.Width) / 2;
            lblPokretanje.Left = (this.ClientSize.Width - lblPokretanje.Size.Width + (btnPokreni.Size.Width - lblPokretanje.Size.Width) / 2) / 2;
            lblPokusaj.Left    = (this.ClientSize.Width - lblPokretanje.Size.Width + (btnPokreni.Size.Width - lblPokretanje.Size.Width) / 2) / 2;
        }
Example #4
0
        public static void UpdateMsgBox(object obj)
        {
            if (myForm.InvokeRequired)
            {
                ObjectDelegate method = new ObjectDelegate(UpdateMsgBox);
                myForm.Invoke(method, obj);
                return;
            }
            string text = (string)obj;

            myForm.textBox1.Text = text;
            var myJson = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(text);

            if (myJson["status"] == "record_started")
            {
                if (stimEnabled)
                {
                    string myDir = stimForm.textBox1.Text;
                    PlayStim(myDir);
                    //Console.WriteLine("Will be starting Sim");
                }
            }
            else if (myJson["status"] == "record_stoped")
            {
                StopStim();
            }
            //Console.WriteLine("GOT JSON:");
            //Console.WriteLine(myJson["status"]);
            //foreach (KeyValuePair<string, string> item in myJson)
            // {
            //    Console.WriteLine("Key:{0}, Value:{1}", item.Key, item.Value);
            // }
        }
Example #5
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                textBox2.AppendText("Please provide the server port \n");
                return;
            }

            if (textBox3.Text == "")
            {
                textBox2.AppendText("Please provide the server IP \n");
                return;
            }

            try {
                textBox2.AppendText("Connecting to " + textBox1.Text + "\n");
                tcpclnt.Connect(textBox3.Text, Int32.Parse(textBox1.Text));

                ObjectDelegate del = new ObjectDelegate(UpdateTextBox);

                Thread th = new Thread(new ParameterizedThreadStart(WorkThread));
                th.Start(del);
            }
            catch (Exception err)
            {
                textBox2.AppendText("An error occured: " + err.ToString() + "\n");
            }
        }
Example #6
0
        private void OnRenamed(object source, RenamedEventArgs e)
        {
            string oldPath  = e.OldFullPath;
            string newPath  = e.FullPath;
            string filename = Path.GetFileName(oldPath);
            string changed  = e.ChangeType.ToString();
            string ext      = Path.GetExtension(newPath);
            // currTime.LastAccessTIme will have a data type of DateTime
            FileInfo currTime = new FileInfo(oldPath);
            string   message  = "File: " + filename + " Renamed "
                                + Path.GetFileName(newPath) + " Path: " + newPath + " " +
                                e.ChangeType + " Date: " + currTime.LastAccessTime;

            // Allows for the writing of text to a textbox,
            // i.e. safe hadling of CrossThreadException.
            ObjectDelegate del = new ObjectDelegate(UpdateTextBox);

            del.Invoke(message);

            // Adds a row to the table with the info on the renamed file.
            if (filesWatchedTable == null)
            {
                createTable();
            }
            row = filesWatchedTable.NewRow();
            row["file_name"]      = filename;
            row["path_name"]      = newPath;
            row["event_occurred"] = changed;
            row["day_time"]       = currTime.LastAccessTime;
            row["extension"]      = ext;
            filesWatchedTable.Rows.Add(row);
        }
Example #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            // ateTextBox();

            if (textBox1.Text == "")
            {
                textBox2.AppendText("Please provide the server port \n");
                return;
            }

            if (textBox3.Text == "")
            {
                textBox2.AppendText("Please provide the server IP \n");
                return;
            }

            ipAd   = IPAddress.Parse(textBox3.Text);
            myList = new TcpListener(ipAd, Int32.Parse(textBox1.Text));
            myList.Start();

            textBox2.AppendText("The server is running at port " + textBox1.Text + "... \n");
            textBox2.AppendText("The local End point is  :" + myList.LocalEndpoint + "\n");
            textBox2.AppendText("Waiting for a connection..... \n ");

            s = myList.AcceptSocket();
            textBox2.AppendText("Connection accepted from " + s.RemoteEndPoint + "\n");

            ObjectDelegate del = new ObjectDelegate(UpdateTextBox);

            Thread th = new Thread(new ParameterizedThreadStart(WorkThread));

            th.Start(del);
        }
Example #8
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);
            }
        }
Example #9
0
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            string pathName = e.FullPath;
            string filename = Path.GetFileName(pathName);
            string changed  = e.ChangeType.ToString();
            string ext      = Path.GetExtension(pathName);
            // currTime.LastAccessTIme will have a data type of DateTime
            FileInfo currTime = new FileInfo(pathName);

            //Builds the message to be displayed in the textbox
            string message = "File: " + filename +
                             " Path: " + pathName + " " + changed + " Date: " + currTime.LastAccessTime;

            // Allows for the writing of text to a textbox,
            // i.e. safe hadling of CrossThreadException.
            ObjectDelegate del = new ObjectDelegate(UpdateTextBox);

            del.Invoke(message);

            // Adds a row to the table with the info on the changes to a file.
            if (filesWatchedTable == null)
            {
                createTable();
            }
            row = filesWatchedTable.NewRow();
            row["file_name"]      = filename;
            row["path_name"]      = pathName;
            row["event_occurred"] = changed;
            row["day_time"]       = currTime.LastAccessTime;
            row["extension"]      = ext;
            filesWatchedTable.Rows.Add(row);
        }
Example #10
0
 private void onClick(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Q)
     {
         inventoryActive = !inventoryActive;
         if (inventoryActive)
         {
             listBox2.SelectedIndex = 0;
         }
         else
         {
             listBox2.SelectedIndex = -1;
         }
     }
     if (inventoryActive)
     {
         ObjectDelegate del = new ObjectDelegate(inventoryHandler);
         del.Invoke(sender, e);
     }
     else
     {
         listBox2.SelectedIndex = -1; // erase inventory interaction
         ObjectDelegate del = new ObjectDelegate(keyPressHandler);
         del.Invoke(sender, e);
     }
 }
Example #11
0
        private void HandleUDPDatagram(string msg, IPEndPoint sender) // Used for handling UDP messages
        {
            if (!sender.Address.Equals(me))                           // Verifies the UDP datagram received isn't from your own machine.
            {                                                         //This is done because some UDP datagrams are sent to the broadcast address, which means we receive what we've sent. We obviously don't want packets from ourselves so we block them.
                if (InvokeRequired && !isClosing)                     // Used for handling thread magic. Please don't ask me to explain this.
                {
                    ObjectDelegate method = new ObjectDelegate(HandleUDPDatagram);
                    Invoke(method, msg, sender);
                    return;
                }

                switch (msg)
                {
                case CLIENT_ANNOUNCE:                            // If we've received a client connection message
                    if (!hostsLB.Items.Contains(sender.Address)) // If the client is not already in the list box
                    {
                        hostsLB.Items.Add(sender.Address);       // Add the client to the listbox of clients
                    }
                    break;

                case CLIENT_DISCONNECT:                         // If we've received a client disconnection message
                    if (hostsLB.Items.Contains(sender.Address)) // If the client is in the listbox
                    {
                        hostsLB.Items.Remove(sender.Address);   // Remove the client from the listbox of clients
                    }
                    break;
                }
            }
        }
Example #12
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());
            }
        }
Example #13
0
        public void doWork()
        {
            NodeDelegate   collisions = quadCollisions;
            ObjectDelegate movement   = quadMovement;

            tree.traverse(collisions, false);
            tree.traverse(movement, true);
        }
 public static void DoObjectDelegate(ObjectDelegate func, GameObject arg, GameObject obj)
 {
     try {
         func(arg, obj);
     } catch (Exception ex) {
         //TopTip.addTip(a.Method.Name + "执行出错" + ex.ToString());
         FuncUtil.ShowError(func.Method.Name + "执行出错" + ex.ToString());
     }
 }
Example #15
0
 public Server(System.Windows.Forms.TextBox setOut)
 {
     this.tcpListener  = new TcpListener(IPAddress.Any, 8888);
     this.listenThread = new Thread(new ThreadStart(ListenForClients));
     this.listenThread.IsBackground = true;
     this.listenThread.Start();
     output = setOut;
     del    = new ObjectDelegate(outputTextToServer);
 }
Example #16
0
 public void Append(TEntity entity)
 {
     object[] valueList = new object[Table.Columns.Count];
     for (int i = 0; i < Table.Columns.Count; i++)
     {
         valueList.SetValue(ObjectDelegate.GetPropertyValue(entity, Table.Columns[i].ColumnName), i);
     }
     Table.Rows.Add(valueList);
 }
Example #17
0
        /// <summary>
        /// This event handler is called whenever the 1 second CPU timer elapses. It calls the 
        /// SetText method in a thread safe manner in order to update the CPU usage text box.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
        {
            PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            int cpu = (int)cpuCounter.NextValue();
            System.Threading.Thread.Sleep(1000);
            cpu = (int)cpuCounter.NextValue();
            _cpuUsage = cpu;

            ObjectDelegate cpuTextDel = new ObjectDelegate(SetCPUText);    //enable the manual start button
            cpuTextDel.Invoke(_cpu);
        }
Example #18
0
        public Delegate CreateSetPropertyDelegate(string propertyName)
        {
            Type         type     = Owner.GetType();
            PropertyInfo propInfo = type.GetProperty(propertyName);

            if (propInfo == null)
            {
                throw new MissingMemberException("Not found property " + propertyName);
            }
            return(ObjectDelegate.CreateMethodDelegate(propInfo.GetSetMethod()));
        }
Example #19
0
        private void button3_Click(object sender, EventArgs ef)
        {
            if (!isValidated)
            {
                MessageBox.Show("Validate First Please");
                return;
            }
            if (channelList.CheckedItems.Count < 1)
            {
                MessageBox.Show("No Channels Selected");
                return;
            }
            if (outputFolderOpener.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string         p   = outputFolderOpener.SelectedPath; //System.IO.Path.GetDirectoryName(sdCard1.FileName);
            ObjectDelegate del = new ObjectDelegate(writeLog);

            del.Invoke(DateTime.Now + " Saving to " + p);

            /*
             * Thread DoItThread = new Thread(() =>
             * {
             *  DoIt(p,del);
             * });
             */
            bw.WorkerReportsProgress = true;
            //bw.
            //bw.RunWorkerCompleted += Bw_RunWorkerCompleted; //DoIt_Done();

            if (!bwInit)
            {
                bw.RunWorkerCompleted += Bw_RunWorkerCompleted;
                bw.ProgressChanged    += Bw_Update1;
                bw.DoWork             += (obj, e) => DoIt(obj, e, p, del);
                bwInit = true;
            }
            //bw.ProgressChanged += Bw_Update1;
            //object d = new{ p, del };
            //DoItThread.
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;
            button5.Enabled = false;
            if (pf.IsDisposed)
            {
                pf = new progressForm();
            }
            pf.Show();
            bw.RunWorkerAsync();
            //DoItThread.Start();
        }
Example #20
0
        public void traverse(ObjectDelegate del, bool movementChange)
        {
            List <QuadNode> queue = new List <QuadNode>();

            queue.Add(rootNode);
            for (int a = 0; a < queue.Count; a++)
            {
                QuadNode node = queue.ElementAt(a);
                node.traverse(del, queue, movementChange);
            }
        }
Example #21
0
        // Delegate created to avoid Illegeal Cross Thread Expection when writing to the text box.
        private void UpdateTextBox(object obj)
        {
            if (InvokeRequired)
            {
                ObjectDelegate method = new ObjectDelegate(UpdateTextBox);
                Invoke(method, obj);
                return;
            }
            string text = (string)obj + "\n";

            logWindowTextBox.AppendText(text);
        }
Example #22
0
            public void SetCallback(ObjectDelegate meth, object cb_obj)
            {
                lock (this)
                {
                    CallOnSet      = meth;
                    CallbackObject = cb_obj;
                }

                if (IsSet)
                {
                    meth(cb_obj, Result);
                }
            }
Example #23
0
 private void outputTextToServer(String text)
 {
     if (output.InvokeRequired)
     {
         // we then create the delegate again
         // if you've made it global then you won't need to do this
         ObjectDelegate method = new ObjectDelegate(outputTextToServer);
         // we then simply invoke it and return
         output.Invoke(method, text);
         return;
     }
     output.AppendText(Environment.NewLine + " >> " + text);
 }
Example #24
0
 internal override object Invoke(ObjectDelegate pfn)
 {
     lock (this)
     {
         _doit = pfn;
         _process.Set();
         _done.WaitOne();
         if (_exception != null)
         {
             throw _exception;
         }
         return(_result);
     }
 }
        private void UpdateForm(string name, string type, string status)
        {
            if (InvokeRequired)
            {
                ObjectDelegate method = new ObjectDelegate(UpdateForm);
                Invoke(method, name, type, status);
                return;
            }

            this.nameDevice.Text       = name;
            this.typeDevice.Text       = type;
            this.statusDevice.Text     = status;
            this.forgetPassBtn.Enabled = false;
        }
Example #26
0
        /*
         * public bool Escape(Bubble _b)
         * {
         *
         *  if (!InMargin(_b) || IsSameBubble(_b)) { Moved = false;  return false; }
         *  return EscapeWithOutCheck(_b);
         * }
         *
         * public bool EscapeWithOutCheck(Bubble _b)
         * {
         *  Run(GetEscapeDirection(_b.CentralPoint));
         *  Moved = true;
         *  return true;
         * }
         * public bool Escape(Point _p)
         * {
         *
         *
         *  if (!InMargin(_p)) { Moved = false; return false; }
         *  return EscapeWithOutCheck(_p);
         * }
         * public bool EscapeWithOutCheck(Point _p)
         * {
         *  Run(GetEscapeDirection(_p));
         *  Moved = true;
         *  return true;
         * }
         *
         * //moviment
         * public void Run(Point _p)
         * {
         *      BubbleRuning = true;
         *      Point _direction = GetEscapeDirection(_p);
         *      int sleep = 0;
         *      for (int moves = 0; moves <= 50; moves++)
         *      {
         *          AlterPosition(_p);
         *          System.Threading.Thread.Sleep(sleep);
         *          sleep += 1;
         *      }
         *      BubbleRuning = false;
         * }
         */
        public void AlterPosition(Point _direction)
        {
            //LoadLocation( new Point(Location.X + _direction.X, Location.Y + _direction.Y));
            if (InvokeRequired)
            {
                ObjectDelegate method = new ObjectDelegate(LoadNewPosition);
                Invoke(method, _direction);
                return;
            }

            // Left += _direction.X;
            //Top += _direction.Y;
            //Panel.InformBubblePosition(this);
        }
Example #27
0
        public mainForm()
        {
            InitializeComponent();
            load_COM();
            this.KeyPreview    = true;
            RxTx_box.KeyPress += new KeyPressEventHandler(RxTx_box_keyPress);
            this.FormClosing  += new FormClosingEventHandler(mainForm_FormClosed);
            this.KeyDown      += new KeyEventHandler(mainForm_keyDown);
            ObjectDelegate del   = new ObjectDelegate(Set_RX);
            ObjectDelegate del1  = new ObjectDelegate(Set_TX);
            Thread         RX_SY = new Thread(new ThreadStart(Rx_symbol));
            Thread         TX_SY = new Thread(new ThreadStart(Tx_symbol));

            RX_SY.Start();
            TX_SY.Start();
        }
Example #28
0
        private void UpdateTextBox(object obj)
        {
            // do we need to switch threads?
            if (InvokeRequired)
            {
                // slightly different now, as we dont need params
                // we can just use MethodInvoker
                ObjectDelegate method = new ObjectDelegate(UpdateTextBox);
                Invoke(method, obj);
                return;
            }

            string text = (string)obj;

            textBox2.AppendText("Client: " + text + "\n");
        }
Example #29
0
        private void writeLog(object obj)
        {
            if (InvokeRequired)
            {
                // we then create the delegate again
                // if you've made it global then you won't need to do this
                ObjectDelegate method = new ObjectDelegate(writeLog);
                // we then simply invoke it and return
                Invoke(method, obj);
                return;
            }
            // ok so now we're here, this means we're able to update the control
            // so we unbox the object into a string
            string text = (string)obj;

            logBox.AppendText(text + "\r\n");
            //logBox.p
        }
Example #30
0
 internal override object Invoke(ObjectDelegate pfn)
 {
     lock (this)
     {
         _doit = pfn;
         _process.Set();
         _done.WaitOne();
         if (_exception == null)
         {
             return(_result);
         }
         else
         {
             ExceptionDispatchInfo.Throw(_exception);
             return(null);
         }
     }
 }
Example #31
0
 public void Clear()
 {
     onSubmit      = null;
     onClick       = null;
     onDoubleClick = null;
     onHover       = null;
     onPress       = null;
     onSelect      = null;
     onScroll      = null;
     onDragStart   = null;
     onDrag        = null;
     onDragOver    = null;
     onDragOut     = null;
     onDragEnd     = null;
     onDrop        = null;
     onKey         = null;
     onTooltip     = null;
 }
        public void process_keithley_output(object obj)
        {
            if (InvokeRequired)
            {
                ObjectDelegate method = new ObjectDelegate(process_keithley_output);
                Invoke(method, obj);
                return;
            }
            try
            {
                NumberStyles style = NumberStyles.AllowExponent | NumberStyles.Number;
                System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
                char[] trim_char = { 'A' };
                //logger.Info("\n Data: " + (String)obj);
                List<String> data = new List<String>(((string)obj).Split(','));

                data[0] = data[0].TrimEnd(trim_char);
                double x = Double.Parse(data[1], style);
                double y = Double.Parse(data[0], style);
                x -= TransientSession.measurement_start_time;

                this.text_box_keithley_output.Text += x.ToString("####.##", CultureInfo.InvariantCulture) + "\t" + y + "\t" + TransientSession.voltage + "\r\n";
                this.text_box_keithley_output.SelectionStart = this.text_box_keithley_output.Text.Length;
                this.text_box_keithley_output.ScrollToCaret();
                this.text_box_keithley_output.Refresh();

                list_keithley.Add(x, y);
                data_logger.Trace("keithley: " + x.ToString("####.##", CultureInfo.InvariantCulture) + " " + y.ToString());
                GraphPane pane = ZedGraph_I_t.GraphPane;

                pane.CurveList.Clear();
                pane.AddCurve("Iph", list_keithley, Color.Blue, SymbolType.Default);
                ZedGraph_I_t.AxisChange();
                ZedGraph_I_t.Invalidate();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString() + "\n Data: " + (String)obj);
            }
        }
        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 process_agilent_output(object obj)
        {
            if (InvokeRequired)
            {
                ObjectDelegate method = new ObjectDelegate(process_agilent_output);
                Invoke(method, obj);
                return;
            }
            List<String> data = new List<String>(((String)obj.ToString()).Split(',')); ;
            int j = 0;
            try
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
                NumberStyles volt_style = NumberStyles.Number;
                double volt_start = Double.Parse(data[0], volt_style);
                data.RemoveAt(0);
                double volt_stop = Double.Parse(data[0], volt_style);
                data.RemoveAt(0);
                double volt_inc = Double.Parse(data[0], volt_style);
                data.RemoveAt(0);

                for (int i = data.Count - 1; i > 1; i -= 3)
                    data.RemoveAt(i);

                char[] trim_char = { 'A' };

                NumberStyles style = NumberStyles.AllowExponent | NumberStyles.Number;
                if (volt_start < volt_stop)
                {
                    for (double i = volt_start; i <= volt_stop; i += volt_inc)
                    {
                        this.text_box_agilent_output.Text += i + "\t" + data[j] + "\r\n";
                        data[j] = data[j].TrimEnd(trim_char);
                        double x = i;
                        double y = Double.Parse(data[j], style);
                        list_agilent.Add(x, y);
                        data_logger.Trace("agilent: " + x.ToString() + " " + y.ToString());
                        this.text_box_agilent_output.SelectionStart = this.text_box_agilent_output.Text.Length;
                        this.text_box_agilent_output.ScrollToCaret();
                        this.text_box_agilent_output.Refresh();
                        j += 2;
                    }
                }
                else
                {
                    for (double i = volt_start; i >= volt_stop; i -= volt_inc)
                    {
                        this.text_box_agilent_output.Text += i + "\t" + data[j] + "\r\n";
                        data[j] = data[j].TrimEnd(trim_char);
                        double x = i;
                        double y = Double.Parse(data[j], style);
                        list_agilent.Add(x, y);
                        data_logger.Trace("agilent: " + x.ToString() + " " + y.ToString());
                        this.text_box_agilent_output.SelectionStart = this.text_box_agilent_output.Text.Length;
                        this.text_box_agilent_output.ScrollToCaret();
                        this.text_box_agilent_output.Refresh();
                        j += 2;
                    }
                }
                GraphPane pane = ZedGraph_I_V.GraphPane;
                pane.AddCurve("I", list_agilent, Color.Blue, SymbolType.Default);
                ZedGraph_I_V.AxisChange();
                ZedGraph_I_V.Invalidate();
            }
            catch (System.Exception)
            {
                logger.Debug("Data: " + data[j]);
            }
        }
        private void button_start_vac_Click(object sender, EventArgs e)
        {
            this.data_grid_view_agilent.Sort(this.data_grid_view_agilent.Columns[0], ListSortDirection.Ascending);
            foreach (DataGridViewRow row in this.data_grid_view_agilent.Rows)
            {
                if (!check_if_row_is_empty(row))
                {
                    try
                    {
                        NumberStyles style = NumberStyles.Number;
                        double volt_start = Double.Parse(row.Cells[1].Value.ToString(), style);
                        double volt_stop = Double.Parse(row.Cells[2].Value.ToString(), style);
                        double volt_inc = Double.Parse(row.Cells[3].Value.ToString(), style);
                        double time_inc = Double.Parse(row.Cells[4].Value.ToString(), style);
                        if (time_inc < 0 || volt_inc < 0)
                            throw new Exception("No negative values are allowed.");
                        //if (volt_stop < volt_start) throw new Exception("Start > Stop.");
                        if (volt_inc > Math.Abs(volt_stop - volt_start)) throw new Exception("Voltage step is greater than |V stop - V start|.");
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message + " Try another value.");
                        return;
                    }
                }
            }

            ObjectDelegate del = new ObjectDelegate(process_agilent_output);
            if (this.agilent_thread == null || !this.agilent_thread.IsAlive)
            {
                this.agilent_thread = new Thread(new ParameterizedThreadStart(this.agilent_work));
                this.agilent_thread.Start(del);
            }
        }
Example #36
0
 public DelegateTest CallObjectDelegate(ObjectDelegate d)
 {
     return d();
 }