Strudle
Strudle

Reputation: 361

Writing to serial port in Perl

I need to communicate with a serial port inside a Perl script. I need to send characters and read the input and search for strings.

What is the simplest way to achieve this? By using "expect" or by opening the /dev/ttys0 device in Perl itself ? Or some other method ?

I prefer to use perl but I don't know if it is simple and featured as expect.

Upvotes: 1

Views: 17623

Answers (3)

askovpen
askovpen

Reputation: 2494

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;

$port->lookclear; 
$port->write("some command to com-port");

my $answer = $port->lookfor;
# or my $answer=$port->read(255);

Upvotes: 6

rpg
rpg

Reputation: 1652

You can try Win32::SerialPort for Win32 and Device::SerialPort for linux.

Upvotes: 3

daxim
daxim

Reputation: 39158

Upvotes: 0

Related Questions