[nSLUG] Re: /dev/ttyS0: open from Perl ?? [An answer found]

Mike mspencer at tallships.ca
Wed Mar 10 23:28:23 AST 2004

gnw> ttyS0 is often a symbolic link, you need to see the permissions on
gnw> the actual device file:

Not the problem.

   bogus% ls -l /dev/ttyS0
   crw-rw-rw-    1 root     uucp       4,  64 Mar 10 22:44 /dev/ttyS0

gnw> You may also encounter permission issues for lock files.

Since I'm trying to write bare code, no lock files are (AFAIK)
created.  It appears (from the code that Jeff mentions, infra) that
you can do lock files or not as you please but AFAICT, the kernel
doesn't do it automatically whenever you open the /dev file.  But I'm
forwarned.  There's a lock file there now, as I write while on line,
created apparently by pppd.

jeff> CPAN is your friend.  Look at Device::SerialPort.

Hah!  Okay.  Well, as far as I can puzzle out on short notice, the
part of Device::SerialPort that opens a dialogue with /dev/ttyS0 is
just a front end for IO::Handle which is a front end for open().
Maybe, though, I can find some guidance by rooting around in the code
to see how they manage the details.

But I think I have the answer:  open( /dev/$THE_SERIAL_PORT... will
hang waiting for DCD to go high if clocal is off.  It's off by default
on my machine.  If I run:

   stty -F /dev/ttyS0 clocal

first, then I can open( "/dev/ttyS0"..., then send to and receive from
the serial port.  E.g. I can write "AT\r\n" to the external modem and
sysread( <filehandle>, <buffer>, 6) will get back what appears to be

Given this, I don't quite understand how the kdcpi (camera interface)
script was meant to work.  The author issues a system("stty... command
*after* calling open on the serial port's /dev file; And that stty
command doesn't include either "clocal" or "-clocal"  explicitly
or by implication.  Maybe his system has different default tty
settings?  Dunno.

So:  Thanks for pointers.  Initial roadblock is cleared.  I'm sure
there'll be more.  

I got this whole serial port thing beat up exactly once in CP/M and
once in MS-DOS.  Time to do it again, I guess.  Sigh. :-)

- Mike

Michael Spencer                  Nova Scotia, Canada       .~. 
mspencer at tallships.ca                                     /( )\
http://home.tallships.ca/mspencer/                        ^^-^^


More information about the nSLUG mailing list