通过 MSComm1 发送 ctrl-E

发布于 2024-07-14 18:13:45 字数 1147 浏览 2 评论 0原文

如何通过串口 MSComm1 发送 ctrl-E ? 它应该继续传递 ctrl-E....就像 for 循环或 do while 循环..这是我的代码:

MSComm1.CommPort = Convert.ToInt16(Settings.Default.PortName); SendKeys.Send("^(e)");
MSComm1.Settings = Settings.Default.BaudRate.ToString().Trim() + "," + Settings.Default.Parity.Substring(0, 1).ToString().Trim() + "," + Settings.Default .DataBits.ToString().Trim() + "," + Settings.Default.StopBits.ToString().Trim();
MSComm1.PortOpen = true;
MSComm1.InputLen = 0;
MSComm1.InputMode = MSCommLib.InputModeConstants.comInputModeText;
if (Settings.Default.FlowControl == "Xon/Xoff")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comXOnXoff;
}
else if (Settings.Default.FlowControl == "None")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comNone;
}
else if (Settings.Default.FlowControl == "RTS")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comRTS;
}
else if (Settings.Default.FlowControl == "RTSXon/Xoff")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comRTSXOnXOff; }

How do i send ctrl-E through serial port MSComm1 ?
it should keep on passing ctrl-E....like for loop or do while loop..Here is my code:

MSComm1.CommPort = Convert.ToInt16(Settings.Default.PortName); SendKeys.Send("^(e)");
MSComm1.Settings = Settings.Default.BaudRate.ToString().Trim() + "," + Settings.Default.Parity.Substring(0, 1).ToString().Trim() + "," + Settings.Default.DataBits.ToString().Trim() + "," + Settings.Default.StopBits.ToString().Trim();
MSComm1.PortOpen = true;
MSComm1.InputLen = 0;
MSComm1.InputMode = MSCommLib.InputModeConstants.comInputModeText;
if (Settings.Default.FlowControl == "Xon/Xoff")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comXOnXoff;
}
else if (Settings.Default.FlowControl == "None")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comNone;
}
else if (Settings.Default.FlowControl == "RTS")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comRTS;
}
else if (Settings.Default.FlowControl == "RTSXon/Xoff")
{
MSComm1.Handshaking = MSCommLib.HandshakeConstants.comRTSXOnXOff;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浪漫之都 2024-07-21 18:13:45

Control-E 是 5 的键盘快捷键,因此:(

serial.Write(new byte[]{ 5 }, 0, 1);

假设串行是 System.IO.Ports.SerialPort 的实例。)

Control-E is a keyboard shortcut for 5, so:

serial.Write(new byte[]{ 5 }, 0, 1);

(Assuming serial is an instance of System.IO.Ports.SerialPort.)

因为看清所以看轻 2024-07-21 18:13:45

使用 C# 进行串行端口通信,来自 此处

private static void SendSampleData() {
  // Instantiate the communications
  // port with some basic settings
  SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

  // Open the port for communications
  port.Open();

  // Write a string
  port.Write("Hello World");

  // Write a set of bytes
  port.Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);

  // Close the port
  port.Close(); 
}

现在您只需以某种方式对 Ctrl+E 进行编码即可。

Serial port communication using C# from here:

private static void SendSampleData() {
  // Instantiate the communications
  // port with some basic settings
  SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

  // Open the port for communications
  port.Open();

  // Write a string
  port.Write("Hello World");

  // Write a set of bytes
  port.Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);

  // Close the port
  port.Close(); 
}

Now you just have to encode Ctrl+E some way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文