Bruce32903 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I have some code that I have been running for months with no problems. The code opens a serial port, collects messages at 9600 baud and displays the proprietary format data in a collection of Perl Tk windows. Once again, this has been running great.

I now need to leave the box in my office and set up another in a lab. I have several Ubuntu 7.04 and 7.10 boxes available so I assumed there would be no problem. But, I am not able to open the serial port on either of the two boxes I have tried so far. Here are some of the details:

Key code lines from big file that has AND STILL DOES work ok on one box:
      use Device::SerialPort
      my $serial_port = new Device::SerialPort("/dev/ttyS0") || die "can't open ttyS0\n";

I have done both an "apt-get install libdevice-serialport-perl" and built the SerialPort module using the EXACT SAME downloaded file and instructions that were used on the working box.

Downloaded file: Device-SerialPort-1.002001.tar.gz downloaded on 06-29-2007.

Build instructions from http://www.sendpage.org/device-serialport/README.txt. This was downloaded and archived on 06-29-2007.

The downloaded instructions were:
      untar
      perl Makefile.PL
      make
      make test
      make install

My error message is: "can't getattr: Input/output error at ./(my_file_name.pl) line (line_with_new_Device::SerialPort).

After Googling I have tried:
      chmod a+rwx /dev/ttyS0
      chown me:me /dev/ttyS0
      execution from user "me" and user "root" tried.

After Googling I don't seem to be getting much that looks useful (and I understand) beyond changing permissions. Any suggestions would be appreciated.

Also, if a "fix" won't hold past a power cycle then I would like to add a part 2 "how to I make a fix that will survive a power cycle?".

And one more: I think it is GREAT that Linux has "ls", "lspci" and "lsusb". With these great features I was suprised that there does not seem to be a "lstty". Since my problem might be my Linux configuration and not Perl, what tools are available to me to gain information on my configuration? CuteCom seems happy wiht ttyS0 so I am using that to make the assumption that my hardware is ok.

Thanks,
Bruce

  • Comment on can't open ttyS0 with Device::SerialPort

Replies are listed 'Best First'.
Re: can't open ttyS0 with Device::SerialPort
by pc88mxer (Vicar) on Apr 03, 2008 at 20:35 UTC
    I would first check to see if you can just open /dev/ttyS0:
    open(T, "</dev/ttyS0") or die "unable to open for reading: $!\n"; open(T, ">/dev/ttyS0") or die "unable to open for writing: $!\n"; open(T, "+</dev/ttyS0") or die "unable to open for read-write: $!\n";

    I just did a cpan Device::SerialPort on my Ubuntu system, and your code worked just fine. It seems that the owner and group for /dev/ttyS0 are set up to user=root, group=dialout. If these are restored when the box is power-cycled, just make sure that the process running the script has 'dialout' in its set of groups (you can use the 'groups' command to help you determine this.)

    HTH!

    Update: corrected read-write open call.

      In only and out only do not post any error messages. The ">+" attempt produces a "no such file or directory" error.

      Thanks,
      Bruce
        Sorry, the read-write open call should be open(T, "+</dev/ttyS0").
Re: can't open ttyS0 with Device::SerialPort
by Joost (Canon) on Apr 03, 2008 at 20:43 UTC
      The error is from my own code. So far I have not gone through the distributed test code and changed it to /dev/ttyS0.

      Thanks,
      Bruce
Re: can't open ttyS0 with Device::SerialPort
by zentara (Cardinal) on Apr 04, 2008 at 14:58 UTC
    One thing that pops to mind, is that on many linux versions, you need to be a member of group UUCP in order to access the serial ports. Maybe Ubuntu dosn't set that up correctly? Google for "Ubuntu /dev/ttyS0 uucp" and see if it helps. Also have you checked the bios setup on the Ubuntu boxes to see if the settings are right for the serial ports? Alot of setups have a serial mouse on /dev/ttyS0, so your modem would have to be on /dev/ttyS1

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      This helped.

      The box that I tried the serial communications program CuteCom on is still a mystery. But, on the other box I set aside my assumption that the serial ports were ttyS0 and ttyS1. With a little random coding I discovered that the two serial ports on the motherboard were ttyS2 and ttyS3. I had not considered this a possibility, but I also never thought that I would see a motherboard with two serial ports on it (not plug in cards).

      This gives me two boxes with the serial ports working. That coveres the emergency of the day. I'll figure out the other box later.

      Thanks for the help,
      Bruce