How to send CTRL-S & CTRL-X over serial port

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Blip

    #1

    How to send CTRL-S & CTRL-X over serial port

    Hello -

    I'm trying to wite these control characters to the serial port w/o
    success.

    I've tried sp.Write((Keys. ControlKey & Keys.X).ToStrin g());
    sp.Write((Keys. Control & Keys.X).ToStrin g());

    char[] temp = { Convert.ToChar( Keys.Control), Convert.ToChar( Keys.X)
    };
    sp.Write(temp, 0, 2);

    and other screwy variations.

    Any suggestions how to do this?

    Thanks, Tom
  • Peter Duniho

    #2
    Re: How to send CTRL-S & CTRL-X over serial port

    On Sat, 27 Sep 2008 11:00:54 -0700, Blip <blip@krumpli.c omwrote:
    Hello -
    >
    I'm trying to wite these control characters to the serial port w/o
    success.
    >
    I've tried sp.Write((Keys. ControlKey & Keys.X).ToStrin g());
    sp.Write((Keys. Control & Keys.X).ToStrin g());
    What's "sp"? Is that an instance of the SerialPort class?

    The bottom line here is that you are trying to mix the user-input data
    structures associated with keyboard input with the ASCII used to represent
    that input.

    The first non-zero byte values for ASCII are reserved for control input.
    By convention, the letters are assigned in sequence, with Control-A being
    1, Control-B being 2, etc. Control-S would be 19. You can probably
    figure out Control-X on your own. :)

    Just send the correct byte value. You aren't going to get anywhere trying
    to use values from the Keys enumeration, as that's tied to the keyboard,
    not ASCII.

    Pete

    Comment

    • Alberto Poblacion

      #3
      Re: How to send CTRL-S &amp; CTRL-X over serial port

      "Blip" <blip@krumpli.c omwrote in message
      news:3assd4heqq r0r641eu5igd11a df2ra0t8l@4ax.c om...
      I'm trying to wite these control characters to the serial port w/o
      success.
      >
      I've tried sp.Write((Keys. ControlKey & Keys.X).ToStrin g());
      sp.Write((Keys. Control & Keys.X).ToStrin g());
      >
      char[] temp = { Convert.ToChar( Keys.Control), Convert.ToChar( Keys.X)
      };
      sp.Write(temp, 0, 2);
      >
      and other screwy variations.
      >
      Any suggestions how to do this?

      You can use the numeric value of the control character: Ctrl-A is ASCII
      1, Ctrl-B is 2, Ctrl-C is 3, and so on.

      SerialPort sp = ...;
      ....
      char ctrlS = (char)('S'-'A'+1);
      char[] charsToWrite = new char[]{ctrlS};
      sp.Write(charsT oWrite, 0, 1);


      Comment

      • MC

        #4
        Re: How to send CTRL-S &amp; CTRL-X over serial port

        To make the same point Pete did, a little more explicitly:

        Serial ports don't transmit keys. They transmit bytes, which are normally
        the ASCII representations of characters.

        "Keys.ControlKe y & Keys.X" has to do with sensing what is going on on a PC
        keyboard. But serial ports do not transmit the whole state of the keyboard.
        For instance, the F keys and the arrows are entirely outside the ASCII
        system.

        An ASCII chart will tell you that, for instance, Ctrl-A is 1, Ctrl-B is 2,
        'A' is 65, and so on.



        Comment

        Working...