Sep 10, 2012

HowTo: Perl Serial Port Fedora 17

1. yum install -y perl-Device-SerialPort
2. usermod -a -G dialout user
     (replace user with your username)
3. log-out or restart computer
4. your user is now allowed to read / write on Serial Port
5. below is a sample of a perl program for a push button I made for a serial port. When I push on the button, Pin 2 and 4 are shorted.


#!/usr/bin/perl

use strict;
use Device::SerialPort;

my $port = new Device::SerialPort("/dev/ttyS0"); 
$port->user_msg('ON'); 
$port->baudrate(9600); 
$port->parity("none"); 
$port->databits(8); 
$port->stopbits(1); 
$port->handshake("xoff"); 
$port->write_settings;

while(1){
my ($count_in, $string_in) = $port->read(255);
if($count_in > 0){
print "BUTTON PRESSED";
}
}

No comments:

Post a Comment