1. unbuffered getc() ?
- Posted by tubby.toast at ntlworld.com May 12, 2003
- 394 views
Hi, I am using Euphoria (2.4 alpha) in Linux to interface with a serial LCD screen and keypad. Sending output is no problem (once I'd remembered to use flush() ) but I'm having trouble reading from the keypad. I tried something like the following: integer lcd, key lcd=open("/dev/ttyS1","ub") while 1 do puts(lcd,{#FE,#26}) -- this tells the device to return the contents of its key buffer, or if the -- buffer is empty, to return 0x00 flush(lcd) key=getc(lcd) --just locks up here! print(1,key) end while This doesn't work because according to the Euphoria docs: "File input using getc() is buffered, i.e. getc() does not actually go out to the disk for each character. Instead, a large block of characters will be read in at one time and returned to you one by one from a memory buffer. When getc() reads from the keyboard, it will not see any characters until the user presses Enter. Note that the user can type control-Z, which the operating system treats as "end of file". -1 will be returned. " So it seems that getc() won't return anything until Euphoria sees a line feed or an EOF. So my question (if you've read this far): how can I get a Euphoria program to read a single byte, immediately and without dealing with buffers, from a file descriptor. Is there a standard C function I can easily wrap? (I'm not very good with C) I hope that made some sort of sense, chris.
2. Re: unbuffered getc() ?
- Posted by tubby.toast at ntlworld.com May 12, 2003
- 395 views
Erm, no. That won't work through the serial port, or will it? Sorry, I'm rubbish at explaining things - it's the serial port I'm trying to read from. chris. > > Did you try get_key() and/or wait_key()? > > -- Brian > > chris wrote: > > > > Hi, > > I am using Euphoria (2.4 alpha) in Linux to interface with a serial LCD > > screen and keypad. Sending output is no problem (once I'd remembered to > > use > > flush() ) but I'm having trouble reading from the keypad. I tried > > something > > like the following: > > > > integer lcd, key > > > > lcd=open("/dev/ttyS1","ub") > > while 1 do > > puts(lcd,{#FE,#26}) > > -- this tells the device to return the contents of its key buffer, or if > > the > > -- buffer is empty, to return 0x00 > > flush(lcd) > > key=getc(lcd) --just locks up here! > > print(1,key) > > end while > > > > This doesn't work because according to the Euphoria docs: > > > > "File input using getc() is buffered, i.e. getc() does not actually go > > out > > to the disk for each character. Instead, a large block of characters > > will be > > read in at one time and returned to you one by one from a memory buffer. > > When getc() reads from the keyboard, it will not see any characters > > until > > the user presses Enter. Note that the user can type control-Z, which the > > operating system treats as "end of file". -1 will be returned. " > > > > So it seems that getc() won't return anything until Euphoria sees a line > > feed or an EOF. So my question (if you've read this far): how can I get > > a > > Euphoria program to read a single byte, immediately and without dealing > > with > > buffers, from a file descriptor. Is there a standard C function I can > > easily wrap? (I'm not very good with C) > > > > I hope that made some sort of sense, > > chris. > > > > > > > TOPICA - Start your own email discussion group. FREE! > >
3. Re: unbuffered getc() ?
- Posted by Sabal.Mike at notations.com May 12, 2003
- 380 views
Chris, I used the following functions to bypass Euphoria's buffering. I don't know if they'll work for your situation, but give them a try and let me know. Michael J. Sabal ------ code follows --------- function old_getc(object z) return getc(z) end function function getc(integer z) object temp if length(inbuffer)<100 then inbuffer = inbuffer & get_bytes(z,4096) end if if length(inbuffer)=0 then return 0 end if temp = inbuffer[1] if length(inbuffer)>1 then inbuffer = inbuffer[2..length(inbuffer)] else if temp = 26 then temp = 0 end if -- if the only char in the buffer is CTRL-Z, call it end of file. inbuffer = "" end if return temp end function --------- end code ------------- >>> tubby.toast at ntlworld.com 05/12/03 04:00PM >>> line feed or an EOF. So my question (if you've read this far): how can I get a Euphoria program to read a single byte, immediately and without dealing with buffers, from a file descriptor. Is there a standard C function I can easily wrap? (I'm not very good with C) I hope that made some sort of sense, chris.
4. unbuffered getc() ?
- Posted by Bernie Ryan <xotron at bluefrognet.net> May 12, 2003
- 371 views
chris: Down load this program from the archive. http://www.rapideuphoria.com/xserial.zip You should be able to adapt this to linux. All you need to do is capture the serial port characters one at a time as they are typed and then send them to the LCD until you see a Enter or Carraige return. Bernie
5. Re: unbuffered getc() ?
- Posted by tubby.toast at ntlworld.com May 14, 2003
- 379 views
Hi, Thanks to everybody who suggested solutions to my problem regarding reading from the serial port. I tried all the suggestions and more but with no luck. Then, after playing about with minicom for a bit, I found that the problem was due simply to a misconfigured serial port. getc() can read a single byte from the serial port just fine - it wasn't Euphoria's fault at all. Sorry about that! chris.