示例#1
0
        private void btnStartSpill_Click(object sender, EventArgs e)
        {
            PP.myRun.Events.Clear();
            packet_counter = 0;

            RC_client.Arm();
        }
示例#2
0
        private void btnSetV_Click(object sender, EventArgs e)
        {
            label9.Visible = true;
            label9.Text    = "measuring...";
            Application.DoEvents();
            RC_client.SetV((double)udV.Value);
            double v = RC_client.ReadA0();

            if (v < 1)
            {
                v           = v * 1000;
                label9.Text = v.ToString("F2") + "nA";
            }
            else if (v > 1000)
            {
                v           = v / 1000;
                label9.Text = v.ToString("F3") + "mA";
            }
            else
            {
                label9.Text = v.ToString("F3") + "uA";
            }
            RC_client.SendStr("wr 20 00");
            Application.DoEvents();
        }
示例#3
0
 private void btnSoftTrig_Click(object sender, EventArgs e)
 {
     if (RC_client.ClientOpen)
     {
         RC_client.SendStr("wr 2e 1");
         Thread.Sleep(5);
         RC_client.SendStr("rd 2f");
         string t = "";
         int    rt;
         RC_client.ReadStr(out t, out rt);
         char[] sep = new char[2];
         sep[0] = ' ';
         sep[1] = '\r';
         string[] tok = t.Split(sep);
         if (tok.Length > 3)
         {
             label5.Text = tok[3];
         }
         else
         {
             label5.Text = "blank line";
         }
         label5.Visible = true;
         Application.DoEvents();
     }
 }
示例#4
0
        private void btn_Listen_Click(object sender, EventArgs e)
        {
            G_Spill_Active        = false;
            btnPLOT.Visible       = true;
            btnStartSpill.Visible = true;
            btnStopSpill.Visible  = true;
            object o = (object)u;

            //e = (EventArgs)o;
            backgroundWorker1.RunWorkerAsync(o);
            btn_Listen.Visible = false;

            if (!RC_client.ClientOpen)
            {
                RC_client.Open();
            }
            //if (!WC_client.ClientOpen) { WC_client.Open(); }
            Application.DoEvents();
            RC_client.Clear();
            OpenFiles();
            btnAutomatic.Visible    = true;
            G_Spill_Active          = false;
            btnPLOT.Visible         = true;
            btnStartSpill.Visible   = true;
            btnStopSpill.Visible    = true;
            btnUpdateStatus.Visible = true;
            btnSetMaxTrig.Visible   = true;
            ud_Stop.Visible         = true;

            label2.Visible = true;
        }
示例#5
0
        private void button1_Click(object sender, EventArgs e)
        {
            int  TotalNumEvents = 0;
            bool res            = true;

            gStopThis = false;
            PP.myRun.Events.Clear();
            res = res && RC_client.Arm();
            btnStopThis.Visible = true;
            gFake = true;
            for (int i = 0; i < 2000; i++)
            {
                PP.myRun.Events.Clear();
                packet_counter = 0;

                RC_client.Arm();
                for (int j = 0; j < 128; j++)
                {
                    Thread.Sleep(5);
                    RC_client.SoftwareTrig();
                    if (gStopThis)
                    {
                        i = 2001; btnStopThis.Visible = false; gFake = false;
                    }
                }


                lblDaqMessage2.Text = "fake spill started for spill # " + i.ToString() + " at " + DateTime.Now.TimeOfDay + "with " + TotalNumEvents;
                if (TotalNumEvents > 40000)
                {
                    i = 2001; btnStopThis.Visible = false;
                }
                Application.DoEvents();
                for (int j = 0; j < 50; j++)
                {
                    Thread.Sleep(5);
                    if (gStopThis)
                    {
                        i = 2001; btnStopThis.Visible = false; gFake = false;
                    }
                }

                btnStopSpill_Click(null, null);
                lblDaqMessage2.Text = "fake spill ended for spill # " + i.ToString() + " at " + DateTime.Now.TimeOfDay + " with " + PP.myRun.Events.Count;
                TotalNumEvents     += PP.myRun.Events.Count;
                Thread.Sleep(1000);
                Application.DoEvents();
                for (int j = 0; j < 10; j++)
                {
                    Thread.Sleep(5);
                    Application.DoEvents();
                    lblDaqMessage.Text = "waiting for " + (10 - j) * 5 / 1000;
                    if (gStopThis)
                    {
                        i = 2001; btnStopThis.Visible = false; gFake = false;
                    }
                }
            }
        }
示例#6
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (!RC_client.ClientOpen)
            {
                RC_client.Open();
            }
            //PP.myTelnet.Show();
//            PP.myPlot.Show();
        }
示例#7
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            //btnSoftTrig_Click(null, null);
            //Thread.Sleep(10);
            RC_client.SendStr("rdm 13 101");
            string t = "";
            int    rt;

            RC_client.ReadStr(out t, out rt);
            RC_client.Disarm();
            char[] sep = new char[2];
            sep[0] = ' ';
            //sep[1] = '\r';
            string[] tok = t.Split(sep, StringSplitOptions.RemoveEmptyEntries);
            Event    e13 = new Event();
            int      j = 0; int k = 0;

            for (int i = 0; i < tok.Length; i++)
            {
                if (j == 8)
                {
                    j = 0; k++;
                }
                else
                {
                    try
                    {
                        e13.RawBytes[0, j + 8 * k] = Convert.ToInt16(tok[i], 16);
                        if (e13.RawBytes[0, j + 8 * k] > 0x7ff)
                        {
                            e13.RawBytes[0, j + 8 * k] = (Int16)(e13.RawBytes[0, j + 8 * k] - 0xfff);
                        }
                    }
                    catch
                    {
                        e13.RawBytes[0, j + 8 * k] = -99;
                    }

                    e13.Channels[0, j + 8 * k] = e13.RawBytes[0, j + 8 * k] + 100;
                    j++;
                }
            }
            e13.EvNum = PP.myRun.Events.Count;
            PP.myRun.Events.AddLast(e13);
            plot_e      = PP.myRun.Events.Last.Value;
            txtEvt.Text = PP.myRun.Events.Count.ToString();
            Plot0_display();
            Application.DoEvents();
        }
示例#8
0
        private void frmTelnet_KeyUp(object sender, KeyEventArgs e)
        {
            string r;

            if (e.KeyValue == 13)
            {
                if (RC_client.ClientOpen)
                {
                    string l = txtNet.Lines[txtNet.Lines.Length - 2];
                    r            = RC_client.SendRead(l);
                    txtNet.Text += r;
                    txtNet.Text += "\n";
                }
                else
                {
                    txtNet.Text += "Doh! The the telnet client is not open \n";
                }
            }
        }
示例#9
0
        private void btnUpdateStatus_Click(object sender, EventArgs e)
        {
            string[] tt;
            int      num_pade = RC_client.GetStatus(out tt);

            if (tt.Length > 0)
            {
                lblStat1.Text = tt[0];
            }
            else
            {
                lblStat1.Text = "no status returned";
            }
            if (tt.Length > 1)
            {
                lblStat2.Text = tt[1];
            }
            else
            {
                lblStat2.Text = "no status returned";
            }
            if (tt.Length > 2)
            {
                lblStat3.Text = tt[2];
            }
            else
            {
                lblStat3.Text = "no status returned";
            }
            if (tt.Length > 3)
            {
                lblStat3.Text = tt[3];
            }
            else
            {
                lblStat4.Text = "no status returned";
            }
        }
示例#10
0
        private void btnAutomatic_Click(object sender, EventArgs e)
        {
            if (btnAutomatic.Text.Contains("to stop"))
            {
                if ((timer1.Enabled == true) && (!G_Spill_Active) && (!G_Reading_Out))
                {
                    timer1.Interval = 999;
                    timer1.Enabled  = false;
                    fs.Close();
                    //WC_fs.Close();
                    RC_client.Close();
                    WC_client.Close();
                    btnAutomatic.Text       = "ACTIVATE AUTO RUN";
                    btnUpdateStatus.Visible = false;
                }
                else
                {
                    btnAutomatic.Text = "waiting to stop. Click again!";
                    Application.DoEvents();
                }
            }
            else
            {
                timer1.Interval = 1000;
                button4_Click(null, null);
                btnAutomatic.Text = "AUTO ACTIVE (click to stop)";
                G_SPILL_NUM       = 0;

                Thread.Sleep(100);
                //try
                //{
                //    if (lblLastTime.Text.Substring(1, 2) == "10") { WC_client.EnableTrig(); }
                //}
                //catch { }
            }
        }
示例#11
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            string sz_trig;
            string sz_WC_time;
            bool   in_spill;

            WC_client.check_status(out in_spill, out sz_trig, out sz_WC_time);

            lblTrigEn.Text = "";
            if (G_Spill_Active)
            {
                lblTrigEn.Text += "TRIG ARMED";
            }
            if (G_Reading_Out)
            {
                lblTrigEn.Text += " and READING OUT";
            }

            if (in_spill)
            {
                lblSpillStatus.Text = "in spill"; time_of_last_spill = DateTime.Now;
            }
            else
            {
                lblSpillStatus.Text = "waiting..." + G_SPILL_NUM.ToString() + " spills so far";
            }

            //t = WC_client.ReadTrigEn();
            //lblTrigEn.Text = t;
            if (sz_trig.Length < 1)
            {
            }
            else
            {
                lblLastTime.Text = DateTime.Now.Subtract(time_of_last_spill).TotalSeconds.ToString("F0");

                if (!G_Spill_Active)
                {
                    if ((DateTime.Now.Subtract(time_of_last_spill).TotalSeconds > 40) && (DateTime.Now.Subtract(time_of_last_spill).TotalSeconds < 44))
                    {
                        G_Spill_Active = true;
                        btnStartSpill_Click(null, null);
                    }
                }
                else
                {
                    if (!G_Reading_Out)
                    {
                        if ((DateTime.Now.Subtract(time_of_last_spill).TotalSeconds < 4) && (DateTime.Now.Subtract(time_of_last_spill).TotalSeconds > 1))
                        {
                            //G_SPILL_NUM++;
                            //WC_fs.WriteLine("*** starting spill num " + G_SPILL_NUM.ToString() + " *** at " + DateTime.Now.ToString());
                            //fs.WriteLine("*** starting spill num " + G_SPILL_NUM.ToString() + " *** at " + DateTime.Now.ToString());
                            timer1.Enabled = false;
                            //timer1.Enabled = false;
                            int ret_len = 0;
                            //byte[] data = WC_client.read_TDC(out ret_len);
                            //string status = "Read " + ret_len + " bytes from WC";
                            //lblWC_status.Text = status;
                            //int j = 0;
                            //for (int i = 0; i < ret_len; i++)
                            //{
                            //    WC_fs.Write(data[i].ToString("X2") + " ");
                            //    j++;
                            //    if (j == 8)
                            //    {
                            //        j = 0; WC_fs.WriteLine();
                            //    }
                            //}
                            //WC_fs.WriteLine();
                            flgGotStatus   = false;
                            timer1.Enabled = true;
                            if ((DateTime.Now.Subtract(time_of_last_spill).TotalSeconds < 38) && (DateTime.Now.Subtract(time_of_last_spill).TotalSeconds > 1))
                            {
                                timer1.Enabled = false;
                                G_Reading_Out  = true;
                                btnStopSpill_Click(null, null);
                                timer1.Enabled = true;
                            }
                        }
                        else
                        {
                            if (!flgGotStatus)
                            {
                                string[] tt;
                                flgGotStatus = true;
                                int num_pade = RC_client.GetStatus(out tt);
                                if (tt.Length > 0)
                                {
                                    lblStat1.Text = tt[0];
                                }
                                else
                                {
                                    lblStat1.Text = "";
                                }
                                if (tt.Length > 1)
                                {
                                    lblStat2.Text = tt[1];
                                }
                                else
                                {
                                    lblStat2.Text = "";
                                }
                                if (tt.Length > 2)
                                {
                                    lblStat3.Text = tt[2];
                                }
                                else
                                {
                                    lblStat3.Text = "";
                                }
                                if (tt.Length > 3)
                                {
                                    lblStat4.Text = tt[3];
                                }
                                else
                                {
                                    lblStat4.Text = "";
                                }
                            }
                        }
                    }
                    else
                    {
                        lblStat1.Text = "currently reading..." + PP.myRun.Events.Count + " so far";
                    }
                }
            }
        }
示例#12
0
        private void btnStopSpill_Click(object sender, EventArgs e)
        {
            bool events_reading = true;
            int  old_count      = 0;
            int  timeout        = 0;
            int  timeout_max    = 20;

            string[] spill_stat;
            RC_client.Disarm();
            RC_client.GetStatus(out spill_stat);
            PP.myRun.spill_status = spill_stat;
            RC_client.ReadAll();

            while (events_reading)
            {
                this.lblDaqMessage.Visible = true;
                this.lblDaqMessage.Text    = "looking for events : timeout=" + timeout.ToString();
                //this.lblDaqMessage2.Text = "last event from " + PP.myRun.Events.Last.Value.RawBytes[0, 6].ToString();
                Thread.Sleep(50);
                Application.DoEvents();
                if (PP.myRun.Events.Count > old_count)
                {
                    events_reading          = true; old_count = PP.myRun.Events.Count; timeout = 0;
                    this.lblDaqMessage.Text = old_count + " events read so far";
                }
                else
                {
                    timeout++;
                    if (timeout < timeout_max)
                    {
                    }
                    else
                    {
                        events_reading = false;
                    }
                }
            }
            this.lblDaqMessage.Text = "all done";

            Event this_evt = new Event();
            LinkedListNode <Event> this_node = PP.myRun.Events.First;
            bool   in_spill;
            string sz_num_trig;
            string sz_WC_time;

            WC_client.check_status(out in_spill, out sz_num_trig, out sz_WC_time);
            G_SPILL_NUM++;
            fs.WriteLine("*** starting spill num " + G_SPILL_NUM.ToString() + " *** at " + DateTime.Now.ToString() + " WC says: num trig= " + sz_num_trig + " time = " + sz_WC_time);
            if (gFake)
            {
                fs.WriteLine("*** this spill is fake ***");
            }
            for (int i = 0; i < PP.myRun.spill_status.Length - 1; i++)
            {
                fs.WriteLine("*** spill status " + i + " " + PP.myRun.spill_status[i] + " ***");
            }
            for (int i = 0; i < PP.myRun.Events.Count; i++)
            {
                if (this_node != null)
                {
                    this_evt = this_node.Value;
                    for (int j = 0; j < 32; j++)
                    {
                        if (this_evt.RawBytes[j, 0] < 32)
                        {
                            string t = this_evt.Ticks[j].ToString();
                            for (int k = 0; k < 9; k++)
                            {
                                t += " " + this_evt.RawBytes[j, k].ToString("X2");
                            }
                            for (int k = 0; k < 120; k++)
                            {
                                t += " " + this_evt.Channels[j, k].ToString("X3");
                            }
                            fs.WriteLine(t);
                            lblDaqMessage2.Text = i.ToString();
                        }
                    }
                }
                this_node = this_node.Next;
            }
            RC_client.Clear();
            fs.Flush();
            G_Spill_Active = false;
            G_Reading_Out  = false;
        }