home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!mcsun!news.funet.fi!ousrvr.oulu.fi!ousrvr!nix
- From: nix@zombie.oulu.fi (Tero Manninen)
- Subject: Re: console device raw mode
- In-Reply-To: jdickson@jato.jpl.nasa.gov's message of Fri, 14 Aug 1992 18:02:24 GMT
- Message-ID: <NIX.92Aug15110928@zombie.oulu.fi>
- Lines: 69
- Sender: news@ousrvr.oulu.fi
- Reply-To: nix@stekt.oulu.fi
- Organization: University of Oulu, Finland
- References: <DEREKN.92Aug12113036@vw.ece.cmu.edu> <NIX.92Aug14014127@zombie.oulu.fi>
- <1992Aug14.114648.9446@syma.sussex.ac.uk>
- <1992Aug14.180224.2182@jato.jpl.nasa.gov>
- Distribution: comp
- Date: Sat, 15 Aug 1992 09:09:28 GMT
-
-
- On Fri, 14 Aug 1992 18:02:24 GMT,
- jdickson@jato.jpl.nasa.gov (Jeff Dickson) said:
-
- Jeff> Yes, the original question was about how to read from a RAW with dos.library.
-
- Jeff> The reason Read() hangs, is because it will block until the number of char-
- Jeff> acters you specified to be read are read! There's no way to judge how many
- Jeff> characters may have been input, because unlike some of the other devices (i.e.
- Jeff> serial device) a kind of QUERY command (i.e. SCMD_QUERY) is not supported.
-
- Ok, how about this then:
- #include <exec/types.h>
- #include <dos/dos.h>
- #include <signal.h>
-
- BPTR con = 0;
-
- void sigint_handler() {
- if (con) {
- SetMode(con, 0);
- Close(con);
- }
- exit(0);
- }
-
- int main(void)
- {
- signal(SIGINT, sigint_handler);
-
- con = Open("CONSOLE:", MODE_OLDFILE);
- if (con) {
- SetMode(con, 1);
-
- for (;;) {
- char buf[5], numbuf[10];
- long n;
- n = Read(con, buf, sizeof(buf));
- if (n) {
- int i;
- for (i = 0; i < n; i++) {
- sprintf(numbuf, "%02x,", buf[i]);
- Write(con, numbuf, 3);
- }
- }
- if (buf[0] == 'q') break;
- }
-
- SetMode(con, 0);
- Close(con);
- }
- return (0);
- }
-
- This works quite well, producing for example following output
- (one hex number after each key press):
- SRC:test> raw
- 61,62,63,64,65,66,67,71,SRC:test>
- SRC:test>
-
- If you dont want the behaviour that Read does not return until
- there is at least one character available you can check the
- file handler by calling WaitForChar(fh, delay_time_in_usec).
- In case there won't be character available in check time,
- WaitForChar returns 0. I guess you could use this even in
- normal line buffered mode ? but Read() would then hang for
- waithing the linefeed :-/
-
- ++Tero
-