private void disconnectToolStripMenuItem_Click(object sender, EventArgs e) { if (PortDataComm.IsOpen) { PortDataComm.Close(); } }
private void fmMain_FormClosing(object sender, FormClosingEventArgs e) { if (__Reader != null) { __Reader.Abort(); } if (PortDataComm.IsOpen) { PortDataComm.Close(); } }
private void clickPort(object sender, EventArgs eventArgs) { #if MEGA2560 __Port = new SerialPort(((ToolStripMenuItem)sender).Text, 115200); __Port.DataReceived += PortOnDataReceived; __Port.Open(); __ComBuffer = String.Empty; #endif #if STM32 try { if (PortDataComm.IsOpen) { return; } PortDataComm.Open(((ToolStripMenuItem)sender).Text, 115200); byte[] tbuff; var answer = PortDataComm.SendCommand(4, out tbuff, 1, 2, 3, 4); if (answer != PortDataComm.CommandStatus.OK) { ShowError("Unable to connect"); PortDataComm.Close(); } toolStripConnection.Text = "Connected"; } catch { ShowError("Unable to connect"); } #endif __Reader = new Thread(RunReaderOnTick) { IsBackground = true }; __Reader.Start(); connectToolStripMenuItem.Enabled = false; disconnectToolStripMenuItem.Enabled = true; }