public void Initialize(string portName) { try { if (File.Exists("configuration.json")) { Configuration.Default.Load(); //InitializePort(portName); commPort.InitializePort(portName); /*toolStripLabel1.Text =*/ var msg = new ToolStripMessage() { Text = string.Format("Connecting : {0}", portName) }; evAgg.PublishOnUIThread(msg); //serialPort.DataReceived += SerialPort_DataReceived; //serialPort.PinChanged += SerialPort_PinChanged; //serialPort.ErrorReceived += SerialPort_ErrorReceived; //serialPort.Open(); commPort.Open(); //if (serialPort.IsOpen) if (commPort.IsOpen) { evAgg.PublishOnUIThread(new PortConnected()); samplingTimer = new System.Timers.Timer(Configuration.Default.SamplingTimerIntervalMilisec); samplingTimer.Elapsed += SamplingTimer_Elapsed; samplingTimer.Enabled = true; samplingTimer.Start(); } } else { evAgg.PublishOnUIThread(new ToolStripMessage() { Text = string.Format("Could not connect, missing coonfiguration file") }); //toolStripLabel1.Text = string.Format("Could not connect, missing coonfiguration file"); } } catch (Exception e) { logger.Error(e); //MessageBox.Show("Error, " + e.Message); evAgg.PublishOnUIThread(new MessageBoxMessage() { Message = e.Message, Title = "Error" }); //this.Close(); //this.Dispose(); } }
private void buttonStart_Click(object sender, System.EventArgs e) { _comPort.Open(comboBoxPorts.Text); EnablePortControls(); }