Ioctl to detect CTS

I’m trying to convert some working C that watches a serial port for
CTS to go high, at which point it does some stuff. It watches for CTS
by doing


ioctl(fd, TIOCMGET, &s);
if ((s & TIOCM_CTS) == TIOCM_CTS) {

I tried to reimplement this in ruby with stuff like

f = File.open '/dev/modem’
p f.ioctl(0x5415)

but it results in errors.
irb(main):006:0> f.ioctl(0x5415)
Errno::EFAULT: Bad address - "/dev/modem"
from (irb):6:in `ioctl’
from (irb):6

So I wrote something to brute out the ioctls that didn’t raise an
exception, and tried them all, but I never seem to get anything sane.
Please give me a clue what’s wrong.

but it results in errors.
irb(main):006:0> f.ioctl(0x5415)
Errno::EFAULT: Bad address - “/dev/modem”
from (irb):6:in `ioctl’
from (irb):6

Basically, it seems to be caused by bugs in the ~2002.11.10 snapshot.
Code in io.c seems to think that ioctl returns its goodies in the
return value, but that doesn’t really seem to be the way at works, at
least in Linux and OpenBSD. The third argument of ioctl is a pointer
to an integer, and the goodies come back in that, not in the return
value. So I sort of fixed the bug and got stuff to work and told Nobu
and hopefully people who actually know what they’re doing will make
actual good fixes at some point in the near future.

Hi,

···

At Sat, 9 Nov 2002 14:17:08 +0900, Brian wrote:


ioctl(fd, TIOCMGET, &s);
if ((s & TIOCM_CTS) == TIOCM_CTS) {

I tried to reimplement this in ruby with stuff like

f = File.open ‘/dev/modem’
p f.ioctl(0x5415)

f.ioctl(0x5415, s = “”)
p s.unpack(“i”)[0]


Nobu Nakada

nobu.nokada@softhome.net wrote in message news:200211120146.gAC1kJq05740@sharui.nakada.kanuma.tochigi.jp

Hi,


ioctl(fd, TIOCMGET, &s);
if ((s & TIOCM_CTS) == TIOCM_CTS) {

I tried to reimplement this in ruby with stuff like

f = File.open ‘/dev/modem’
p f.ioctl(0x5415)

f.ioctl(0x5415, s = “”)
p s.unpack(“i”)[0]

Doh. I didn’t see that the number of arguments to ioctl changed after
1.6.7 somewhere. Thanks.

···

At Sat, 9 Nov 2002 14:17:08 +0900, > Brian wrote:

Hi,

···

At Fri, 15 Nov 2002 03:00:36 +0900, Brian wrote:

f.ioctl(0x5415, s = “”)
p s.unpack(“i”)[0]

Doh. I didn’t see that the number of arguments to ioctl changed after
1.6.7 somewhere. Thanks.

IO#ioctl takes an optional argument since version 1.1.


Nobu Nakada