如何通过串口MSComm1发送ctrl-E?当loop..Here是我的代码时,它应该继续传递ctrl-E…就像for循环或do:
MSComm1.CommPort = Convert.ToInt16(Settings.Default.PortName);SendKeys.Send("^(e)");
设置= 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; }发布于 2009-03-17 13:08:41
Control-E是5的键盘快捷键,因此:
serial.Write(new byte[]{ 5 }, 0, 1);(假设serial是System.IO.Ports.SerialPort的实例。)
发布于 2009-03-17 13:09:04
使用here中的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进行编码。
https://stackoverflow.com/questions/654146
复制相似问题