Java program simulating control-z being pressed

Discussion in 'Java' started by Per Magnus L?vold, Mar 5, 2004.

  1. Hi,
    I have tried to figure out how to make my Java program simulate
    control-z (^z) being pressed.
    The program communicates over the serial port with a modem
    /* sample code */
    ..
    ..
    sp = (SerialPort) port.open("Test", 1000);
    ps = new PrintStream(sp.getOutputStream());
    ..
    ..
    public void sendBytes(String s) {
    for (int i = 0; i < s.length(); i++) {
    char b = s.charAt(i);
    ps.write(b);
    }
    }
    /* end sample code */

    My question is this:
    How can I make the Java program send the equivalent of control-z to
    the modem?
    Typing control-z in hyperterminal manually works, but I want the Java
    program to do this. I have thought of using:
    sendBytes(KeyEvent.CONTROL+"z");
    But this doesn't work.

    I find in another posting that "control-c has the numerical value of
    3"
    http://www.google.com/groups?hl=no&...r=&ie=ISO-8859-1&q=java+control-c+serial+port
    ....and someone tip'ed me that control-z then might be 26, but that
    does not seem to be right.

    Hope someone can help me! :)

    Regards,
    Per Magnus
     
    Per Magnus L?vold, Mar 5, 2004
    #1
    1. Advertising

  2. (Per Magnus L?vold) writes:

    > ...and someone tip'ed me that control-z then might be 26, but that
    > does not seem to be right.


    Yes, but most often you will need to send a CRLF pair as well, ie. the
    bytes 26, 13, 10. The reason is that the modem or whatever you talk to
    at the other end often will collect characters until a whole line has
    been entered, then process that.

    Also, remember to flush() the output buffer after writing.
     
    Tor Iver Wilhelmsen, Mar 5, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Si
    Replies:
    3
    Views:
    778
    Andrey Kuznetsov
    Feb 28, 2006
  2. Rune
    Replies:
    6
    Views:
    1,312
    Richie Hindle
    Jan 29, 2004
  3. Angus
    Replies:
    5
    Views:
    2,237
    Michael Rauscher
    Nov 18, 2006
  4. mcsejung
    Replies:
    2
    Views:
    310
    Marc 'BlackJack' Rintsch
    Feb 22, 2008
  5. Novice

    Leave button depressed after being pressed

    Novice, Jun 21, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    431
    Ken Cox [Microsoft MVP]
    Jun 23, 2004
Loading...

Share This Page