private void btnWrite_Click(object sender, EventArgs e) { isWritingError = false; if (string.IsNullOrEmpty(cboCommand.Text)) { MessageBox.Show(Resources.CommandNotEmpty); return; } string content; if (isAsciiCommand) { content = cboCommand.Text; } else { try { content = cboCommand.Text.ToAsciiString(); } catch (Exception ex) { isWritingError = true; MessageBox.Show(ex.Message); return; } } Stopwatch stopwatch = Stopwatch.StartNew(); try { portOperatorBase.WriteLine(content); cboCommand.AddItem(cboCommand.Text); } catch { content = $"写入命令\"{cboCommand.Text}\"失败!"; } DisplayToTextBox($"[Time:{stopwatch.ElapsedMilliseconds}ms] Write: {cboCommand.Text}"); }
private void writeCMD(PortOperatorBase opBase) { isWritingError = false; if (string.IsNullOrEmpty(commandTB.Text)) { MessageBox.Show("Command is empty!"); return; } string content = commandTB.Text; Stopwatch stopwatch = Stopwatch.StartNew(); try { opBase.WriteLine(content); // cboCommand.AddItem(cboCommand.Text); } catch { content = $"写入命令\"{content}\"失败!"; } listBox1.Items.Add($"[Time:{stopwatch.ElapsedMilliseconds}ms] Write: {content}"); }