public Form1() { InitializeComponent(); zedGraphControl_scope.MasterPane[0].IsFontsScaled = false; zedGraphControl_scope.MasterPane[0].Title.IsVisible = false; zedGraphControl_scope.MasterPane[0].XAxis.MajorGrid.IsVisible = true; zedGraphControl_scope.MasterPane[0].XAxis.Title.IsVisible = false; zedGraphControl_scope.MasterPane[0].YAxis.MajorGrid.IsVisible = true; zedGraphControl_scope.MasterPane[0].YAxis.Title.IsVisible = false; scope = new Scope_thread(); zedGraphControl_generator.MasterPane[0].IsFontsScaled = false; zedGraphControl_generator.MasterPane[0].Title.IsVisible = false; zedGraphControl_generator.MasterPane[0].XAxis.MajorGrid.IsVisible = true; zedGraphControl_generator.MasterPane[0].XAxis.Title.Text = "time (s)"; zedGraphControl_generator.MasterPane[0].YAxis.MajorGrid.IsVisible = true; zedGraphControl_generator.MasterPane[0].YAxis.Title.IsVisible = false; generator = new Generator_thread(); this.panel5.Enabled = false; this.tableLayoutPanel14.Enabled = false; GUITimer.Elapsed += new ElapsedEventHandler(Update_GUI); GUITimer.Interval = 50; comm = new Thread(new ThreadStart(sc.comm_run)); scope_th = new Thread(new ThreadStart(scope.run)); gen_th = new Thread(new ThreadStart(generator.run)); mode = Paint_mode.Mode.IDLE; scope.scopePane = zedGraphControl_scope.GraphPane; scope.trig_level = this.trackBar_trig_level.Value; scope.pretrig = this.trackBar_pretrig.Value; generator.generatorPane = zedGraphControl_generator.GraphPane; comm.Start(); }
private void tabPage_scope_Enter(object sender, EventArgs e) { if (this.checkBox_scope_enable.Checked) { this.mode = Paint_mode.Mode.SCOPE; sc.scope_start(); } }
private void tabPage_generator_Enter(object sender, EventArgs e) { this.mode = Paint_mode.Mode.GENERATOR; if (this.checkBox_scope_enable.Checked) { sc.scope_stop(); } }
/*metody generator konec*/ private void tabPage_device_Enter(object sender, EventArgs e) { this.mode = Paint_mode.Mode.IDLE; if (this.checkBox_scope_enable.Checked) { sc.scope_stop(); } }
protected override void OnPaint(PaintEventArgs e) { switch (mode) { case Paint_mode.Mode.IDLE: break; case Paint_mode.Mode.SEARCHING: if (sc.is_connecting_in_progress()) { this.button_connect.Enabled = false; this.toolStripStatusLabel_status.Text = "Serching for available devices"; this.toolStripProgressBar1.Value = sc.get_connecting_progress(); } else { if (sc.is_new_devices()) { this.mode = Paint_mode.Mode.DEV_FOUND; } } break; case Paint_mode.Mode.DEV_FOUND: if (sc.is_new_devices()) { if (sc.get_num_of_devices() > 0) { this.toolStripStatusLabel_status.Text = "Searching done"; this.button_connect.Enabled = true; for (int i = 0; i < sc.get_num_of_devices(); i++) { this.listBox_devices.Items.Add(sc.get_dev_names()[i]); } this.listBox_devices.SelectedIndex = 0; } else { this.toolStripStatusLabel_status.Text = "No device found"; } } break; case Paint_mode.Mode.CONNECTING: if (sc.is_connected()) { this.mode = Paint_mode.Mode.CONNECTED; } else { watchdog++; if (watchdog > 20) { watchdog = 0; this.mode = Paint_mode.Mode.COMM_ERR; comm_error(); sc.disconnect_device(); } } break; case Paint_mode.Mode.CONNECTED: connected(); validate_general(); validate_scope(); generator.set_gen_buff_lenght(sc.get_dev_configuration().genBuffLenght); validate_generator(); this.mode = Paint_mode.Mode.IDLE; break; case Paint_mode.Mode.DISCONECTED: break; case Paint_mode.Mode.COMM_ERR: break; case Paint_mode.Mode.SCOPE: paint_scope(); zedGraphControl_scope.Refresh(); break; case Paint_mode.Mode.GENERATOR: // paint_generator(); if (this.checkBox_gen_en_output.Checked && sc.get_ackn()) { this.panel_gen_enabled_color.BackColor = Color.LawnGreen; sc.clear_ackn(); } zedGraphControl_generator.Refresh(); break; default: break; } }
/* zavirani okna */ private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (this.scope.mode == Paint_mode.Mode.SCOPE) { scope.update_mode(Paint_mode.Mode.IDLE); scope_th.Join(); sc.scope_stop(); } if (this.generator.mode == Paint_mode.Mode.GENERATOR) { generator.update_mode(Paint_mode.Mode.IDLE); gen_th.Join(); sc.gen_stop(); } this.mode = Paint_mode.Mode.IDLE; sc.comm_stop(); }
/* Scope enable */ private void checkBox_scope_enable_CheckedChanged(object sender, EventArgs e) { if (this.checkBox_scope_enable.Checked) { this.mode = Paint_mode.Mode.SCOPE; scope.update_mode(mode); scope_th = new Thread(new ThreadStart(scope.run)); scope_th.Start(); if (scope.firstRun) { scope.firstRun = false; sc.set_scope_trigger_edge(Defines.RISE); sc.set_scope_trigger_type(Defines.SCOPE_TRIG_SINGLE); sc.set_scope_sampling_freq(Defines.FREQ_10K); } scope.buffLenght = sc.get_dev_configuration().scopeBuffLenght; scope.accuracy = (double)(sc.get_dev_configuration().ScopeVref_mv) / 255; scope.time = new double[scope.buffLenght]; scope.update_time_base(); scope.signal = new double[scope.buffLenght]; // sc.set_scope_pretrig(sc.get_dev_configuration().scopeBuffLenght * scope.pretrig / 100); // sc.set_scope_trigger_level(scope.trig_level); sc.scope_start(); } else { this.mode = Paint_mode.Mode.IDLE; scope.update_mode(mode); scope_th.Join(); sc.scope_stop(); } }
private void button_scan_Click(object sender, EventArgs e) { sc.find_dev_req(); this.listBox_devices.Items.Clear(); mode = Paint_mode.Mode.SEARCHING; if (!GUITimer.Enabled) { GUITimer.Enabled = true; } Thread.Sleep(10); }
/* Button Connect */ private void button_connect_Click(object sender, EventArgs e) { if (this.button_connect.Text.Equals("Connect")) { string dev = (string)this.listBox_devices.SelectedItem; if (dev == null) { MessageBox.Show("You have to select device first", "No device selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (dev[4] == ':') { dev = dev.Substring(0, 4); } else { dev = dev.Substring(0, 5); } sc.connect_device(dev); this.toolStripStatusLabel_status.Text = "Connecting to " + dev; this.mode = Paint_mode.Mode.CONNECTING; } } else { this.mode = Paint_mode.Mode.DISCONECTED; //vypnuti osciloskopu scope.update_mode(mode); if (scope_th.ThreadState != System.Threading.ThreadState.Unstarted) { scope_th.Join(); } sc.scope_stop(); this.checkBox_scope_enable.Checked = false; invalidate_scope(); //vypnuti generatoru generator.update_mode(mode); if (gen_th.IsAlive) { gen_th.Join(); } sc.gen_stop(); invalidate_generator(); sc.disconnect_device(); disconnect(); } }
public void update_mode(Paint_mode.Mode m) { this.mode = m; }