public MAIN() { InitializeComponent(); this.Resize += new EventHandler(FrmResize); cmb_baud.Items.Add(300); cmb_baud.Items.Add(600); cmb_baud.Items.Add(1200); cmb_baud.Items.Add(2400); cmb_baud.Items.Add(4800); cmb_baud.Items.Add(9600); cmb_baud.Items.Add(14400); cmb_baud.Items.Add(19200); cmb_baud.Items.Add(28800); cmb_baud.Items.Add(38400); cmb_baud.Items.Add(57600); cmb_baud.Items.Add(115200); ComPort.DataReceived += new SerialDataReceivedEventHandler(ComPort_DataReceived); ComPortStatus = EnumComPortStatus.NotConnected; btn_connect.Enabled = false; EOLChars.Add("None", ""); EOLChars.Add("Newline", "\n"); EOLChars.Add("Carraige Regurn", "\r"); EOLChars.Add("Both NL and CR", "\n\r"); cmb_eol.DataSource = new BindingSource(EOLChars, null); cmb_eol.DisplayMember = "Key"; cmb_eol.ValueMember = "Value"; DB = new RealTimeDB(); ASI = new AdvancedSerial_API(DB); //Initialized the Buffer Buffer.Add("TEST_sin", new List <Tuple <Single, Single> >()); Buffer.Add("TEST_cos", new List <Tuple <Single, Single> >()); //Create a Timer to update the test data sw = new Stopwatch(); TimerCallback tcb = UpdateTestData; updateTimer = new System.Threading.Timer(tcb, sw, 0, 100); sw.Start(); }
private void btn_connect_Click(object sender, EventArgs e) { if (ComPortStatus == EnumComPortStatus.Connected) { ComPort.Close(); tb_status.Text = "Disconnected."; cmb_baud.Enabled = true; cmb_ports.Enabled = true; btn_connect.Text = "Connect"; btn_send.Enabled = false; btn_reset.Enabled = false; ComPortStatus = EnumComPortStatus.Disconnected; } else { ComPort.PortName = cmb_ports.Text; ComPort.BaudRate = Convert.ToInt32(cmb_baud.Text); ComPort.DataBits = 8; ComPort.StopBits = StopBits.One; tb_status.Text = "Connecting..."; try { ComPort.Open(); ComPortStatus = EnumComPortStatus.Connected; tb_status.Text = "Connected"; cmb_baud.Enabled = false; cmb_ports.Enabled = false; btn_send.Enabled = true; btn_connect.Text = "Disconnect"; btn_reset.Enabled = true; rtb_serialdata.Clear(); //Get Symbols ASI.getSymbols(ComPort); } catch { ComPortStatus = EnumComPortStatus.ConnectionFailed; tb_status.Text = "Connection Failed"; } } }