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"; } } } }
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; }