Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

baudrate issue with script

by motoprog (Initiate)
on Nov 08, 2012 at 20:45 UTC ( #1002980=perlquestion: print w/ replies, xml ) Need Help??
motoprog has asked for the wisdom of the Perl Monks concerning the following question:

With the following script I get the error message "Can't call method "baudrate" on an undefined value at line 10."
#!/usr/bin/perl use strict; use warnings; use Device::SerialPort; local $| = 1; ## Set up the serial port... my $port = Device::SerialPort->new("/dev/ttyS0"); $port->baudrate(19200); $port->databits(8); $port->parity("none"); $port->stopbits(1); $port->handshake("none"); $port->stty_icrnl(1); $port->write_settings; #!/usr/bin/perl use strict; use warnings; use Device::SerialPort;
Any help would be appreciated!! Thanks

Comment on baudrate issue with script
Download Code
Re: baudrate issue with script
by roboticus (Canon) on Nov 08, 2012 at 21:26 UTC


    It looks like the Device::SerialPort->new("/dev/ttyS0"); statement isn't returning a serial port for you. You should check things like that in your code. For example:

    my $port = Device::SerialPort->new("/dev/ttyS0"); die "Can't open /dev/ttyS0: $!" if ! defined $port;

    Please note: Your code may not have enough permissions to open the serial port. For some versions of *nix, you may not even have a /dev/ttyS0!


    When your only tool is a hammer, all problems look like your thumb.

Re: baudrate issue with script
by jmlynesjr (Pilgrim) on Nov 08, 2012 at 23:48 UTC
      No I haven't tried Arduino. The script above worked when using it on my other ten year old laptop that ubuntu 10 installed on it and a serial port. Now I have a new laptop with ubuntu 12 installed, and a laptop that only has USB ports. I would really like to get this programme going. I think it's a permission thing. When testing the ports my RS232 adapter does get identified. It's just when I run the script I get the baudrate message. Any ideas??

        This may take a few posts to resolve.

        Does it work correctly if run from a root login and fail when run from a regular login? If so, it's a permission issue. What do you get if you plug in your usb device and run the lsusb shell command as root and as a regular login?

        I'm not a linux guru, but I did resolve permission issues with installing SANE drivers for a Kodak 5250 AIO printer/scanner with a USB interface. The fix involved creating and assigning myself to a group, in my case "scanner"(step 6) and creating a new rule in the /etc/udev/rules.d/ directory(step 7).

        Have you searched Ex: search "setting usb permissions" Or search "udev syntax"


        Also google udev rules, or

        As an example(from the SANE Scanner fix below:


        Thanks to all for your efforts in the development of the CUPS driver/S +ANE backend for Kodak Aio printers! I had previously successfully installed the CUPS driver and would now +like to document my experience installing the SANE backend for Kodak +Aio for an ESP 5250 printer. I run Ubuntu 10.10 on an old IBM Thinkpad laptop and I am a user rath +er than a developer. This process took about 8 +/- hours of reading r +elease notes, readme files, man pages, and forum posts and a good bit + of trial and error. Here's what finally worked for me: 1. From +ckend Downloaded kodakaio-02.4.tar.gz Extracted to /home/kodak direct +ory 2. Installed 3 of the recommended packages. libusb-dev was already ins +talled on my system. sudo apt-get install libcups2-dev sudo apt-get i +nstall libcupsimage2-dev sudo apt-get install libcupsdriver1-dev 3. Followed Release Notes instructions: cd kodakaio-02.4 cd sane-backe +nds-kodakaio-02.4 ./configure --prefix=/usr --sysconfdir=/etc --local +statedir=/var BACKENDS=kodakaio make sudo make install 4. Edited the file /etc/sane.d/kodakaio.conf # net autodiscovery (I do +n't use wifi with this printer) usb 0x040a 0x4041 (ESP 5250 usb codes +) scanimage -L still did not see the scanner 5. Edited the file /etc/sane.d/dll.conf kodakaio scanimage -L now sees + the scanner as root only (Note: The Release Notes seem to be in erro +r here, referencing kodakaio.conf instead of dll.conf. As corrected, +steps 4 and 5 should be reversed to match the Release Notes.) 6. Created a scanner group using system->Administration->Users and Gro +ups and added myself to this group. 7. Created /etc/udev/rules.d/90-libsane.rules LABEL="libsane_usb_rules +_begin" # Kodak ESP 5250 ATTRS{idVendor}=="040a", ATTRS{idProduct}==" +4041", MODE="0664", GROUP="scanner", ENV{libsane_matched}="yes" LABEL +="libsane_usb_rules_end" 8. scanimage -L now sees the scanner as myself(and root) scanimage > mytestscanfile Simple Scan XSane Image Scanning Program Ar +e all working under Ubuntu 10.10 I hope this summary helps someone save a few hours of research.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1002980]
Approved by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-09-20 12:06 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (159 votes), past polls