tags:

views:

227

answers:

2

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; }

+2  A: 

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.)

Richard
+1  A: 

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.

schnaader
is it instead of Hello World i need to replace Ctrl-E ??
Girish1984
That would send the text of Ctrl-E to the serial port, probably not what you want. You have to find the byte code that represents Ctrl + E.
Samuel