Need Perl Equivalent for C ioctl Functions for Modem Control

H

Hal Vaughan

I have a problem with my mode, which I am controlling from
Device::SerialPort. It usually works (meaning I can run a Perl script that
uses my modem and it'll be able to control it easily). After the system
has rebooted, or after I've run minicom and exited, my Perl scripts can't
control the modem. If I rum minicom and quit without resetting the modem,
my Perl script works.

I figure there must be something in the modem that I have to set (or reset
or change) that I'm missing. I do not know C, but was able to go through
the minicom source (it's in C), and find out that when I exit, an extra
routine is run to reset the modem to previous settings. There is also an
opposite routine, to save settings (but no matter what the settings before
running minicom, whenever I run it and exit, my Perl script still won't
work).

Here's the part of the C code that gets the modem info:

tcgetattr(fd, &savetty);
ioctl(fd, TIOCGETP, &sg);
ioctl(fd, TIOCGETC, &tch);
ioctl(fd, TIOCLGET, &lsw);
ioctl(fd, TIOCMODG, &m_word);

And here's the part that restores it when I exit minicom:

tcsetattr(fd, TCSANOW, &savetty);
ioctl(fd, TIOCSETP, &sg);
ioctl(fd, TIOCSETC, &tch);
ioctl(fd, TIOCLSET, &lsw);
ioctl(fd, TIOCMODS, &m_word);

From my understanding, ioctl is changing the settings on the modem. I
figure if I knew what it was changing, I could make sure I set it to what
works for my Perl script in that script. I'm not clear if "tcgetattr" is
storing the ENTIRE modem configuration or not. It would help to know if it
does. Also knowing what is being changed in the ioctl calls (TIOCSETP,
TIOCSETC, TIOCLSET, TIOCMODS) would help, too. Can anyone tell me what the
program is doing or what settings would be the equivalent in working with
the modem in Device::SerialPort? While there are web pages with these
terms mentioned, they are always used in the context of people who already
know about them.

Thanks for any help!

Hal
 
H

Hal Vaughan

Thank you so much! Not knowing C, I had no idea where to look next. This
is a big help, especially since it points me to where I can explore for
more info!

Hal

Jim said:
Hal Vaughan said:
I have a problem with my mode, which I am controlling from
[...]


Here's the part of the C code that gets the modem info:

tcgetattr(fd, &savetty);
ioctl(fd, TIOCGETP, &sg);
ioctl(fd, TIOCGETC, &tch);
ioctl(fd, TIOCLGET, &lsw);
ioctl(fd, TIOCMODG, &m_word);

And here's the part that restores it when I exit minicom:

tcsetattr(fd, TCSANOW, &savetty);
ioctl(fd, TIOCSETP, &sg);
ioctl(fd, TIOCSETC, &tch);
ioctl(fd, TIOCLSET, &lsw);
ioctl(fd, TIOCMODS, &m_word);

From my understanding, ioctl is changing the settings on the modem.

tcsetattr and ioctl are changing settings in the terminal driver, not
the modem. There is very limited direct control of a modem, which is
probably attached to your computer via an RS-232 interface. Your
computer normally controls the modem by sending characters to it over
the serial line using "AT" commands.
I
figure if I knew what it was changing, I could make sure I set it to what
works for my Perl script in that script. I'm not clear if "tcgetattr" is
storing the ENTIRE modem configuration or not.

tcgetattr is saving the contents of the termios structure. See man 4
termios and /usr/include/sys/termois.h for details (if you are on a
unix system).
It would help to know if it
does. Also knowing what is being changed in the ioctl calls (TIOCSETP,
TIOCSETC, TIOCLSET, TIOCMODS) would help, too.

The first four calls to ioctl are getting and saving the parameters,
special characters, local modes, and modem control state (see ioctl.h,
ioctl_compat.h, or ttycom.h). The next four are restoring these same
values. What exactly these are, I do not know.
Can anyone tell me what the
program is doing or what settings would be the equivalent in working with
the modem in Device::SerialPort? While there are web pages with these
terms mentioned, they are always used in the context of people who
already know about them.

See "Advanced Programming in the UNIX Environment" by W. Richard
Stevens for an explanation of what some of the flags mean.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top