From: Kari Laine on
Hi,

I hope someone can put me in the right direction.
I am making front end to Byvac BV4626 multi IO card in Java. Part of the
implementation is little terminal program. Problem is the BV4626 wants
strings starting with escape. No when I read the System.in I don't get
escape. This in Linux X11 and I think kterm.
Problem seems to be that shell in terminal window changes what the Java
program sees.

I have inspected this little with google and it seems I would have to
set the terminal in raw mode. Default is cooked. But all I find is asm
and c examples how to do this. I would like not to have platform
dependent code. Is there any way to read keyboard raw in Java?

Also if there already exist a terminal program written in Java, which
is GPL or BSD license - that would be optimal. Also I am after XMODEM
implementation with Java.

Best Regards
Kari

--
PIC - Microcontrollers - I2C - SPI
Keypads - USB-RS232 - USB-I2C - Accessories
http://www.byvac.com
I am just a happy customer


From: Andreas Leitgeb on
Kari Laine <klaine8(a)gmail.com> wrote:
> I hope someone can put me in the right direction.
> I am making front end to Byvac BV4626 multi IO card in Java. Part of the
> implementation is little terminal program. Problem is the BV4626 wants
> strings starting with escape. No when I read the System.in I don't get
> escape.

On Linux (and unices), you can enter a literal Esc-key, by quoting it:
precede it with a (usually, unless redefined) <Ctrl>-V sequence.
That way, it should be literally readable from System.in.

Calling out to external program stty won't add much new platform-
dependency, as switching the terminal to raw ... well, I don't think
that the very concept even exists on windows command-lines.

I once did something like that in a similar situation:
static void raw(boolean on) {
String s=on? "" : "-";
try { Runtime.getRuntime().exec(new String [] {
"sh", "-c", "stty "+s+"raw </dev/tty"}).waitFor();
} catch (Exception e) {}
}

If you really need input of some special keys cross-platform from
terminal through System.in, you can define your own meta-syntax,
like \e for escape, and \\ for literal backslash...

> Also if there already exist a terminal program written in Java, which
> is GPL or BSD license - that would be optimal. Also I am after XMODEM
> implementation with Java.

Sorry, can't help with that.
From: Joshua Cranmer on
On 08/08/2010 01:31 PM, Kari Laine wrote:
> I have inspected this little with google and it seems I would have to
> set the terminal in raw mode. Default is cooked. But all I find is asm
> and c examples how to do this. I would like not to have platform
> dependent code. Is there any way to read keyboard raw in Java?

You can find some Java curses libraries, which should allow you full raw
access to the keyboard in Java (basically, it allows you to make a full
UI in the console). Google gets me here:
<http://sourceforge.net/projects/javacurses/>.

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
From: Arne Vajhøj on
On 08-08-2010 17:10, Andreas Leitgeb wrote:
> Kari Laine<klaine8(a)gmail.com> wrote:
>> I hope someone can put me in the right direction.
>> I am making front end to Byvac BV4626 multi IO card in Java. Part of the
>> implementation is little terminal program. Problem is the BV4626 wants
>> strings starting with escape. No when I read the System.in I don't get
>> escape.
>
> On Linux (and unices), you can enter a literal Esc-key, by quoting it:
> precede it with a (usually, unless redefined)<Ctrl>-V sequence.
> That way, it should be literally readable from System.in.
>
> Calling out to external program stty won't add much new platform-
> dependency, as switching the terminal to raw ... well, I don't think
> that the very concept even exists on windows command-lines.
>
> I once did something like that in a similar situation:
> static void raw(boolean on) {
> String s=on? "" : "-";
> try { Runtime.getRuntime().exec(new String [] {
> "sh", "-c", "stty "+s+"raw</dev/tty"}).waitFor();
> } catch (Exception e) {}
> }
>
> If you really need input of some special keys cross-platform from
> terminal through System.in, you can define your own meta-syntax,
> like \e for escape, and \\ for literal backslash...

The last suggestion sounds by far as the best solution to me!

Arne
From: Kari Laine on
On 08/09/2010 03:35 AM, Arne Vajh�j wrote:
> On 08-08-2010 17:10, Andreas Leitgeb wrote:
>
> Arne

Thanks a lot Arne !

Best Regards
Kari



--
PIC - ARM - Microcontrollers - I2C - SPI
Keypads - USB-RS232 - USB-I2C - Accessories
http://www.byvac.com
I am just a happy customer