- LICENSE AND COPYRIGHT
RPi::Serial - Basic read/write interface to a serial port
use RPi::Serial; my $dev = "/dev/ttyAMA0"; my $baud = 115200; my $ser = RPi::Serial->new($dev, $baud); $ser->putc(5); $ser->puts("hello, world!"); my $char = $ser->getc; my $num_bytes = 12; my $str = $ser->gets($num_bytes); $ser->flush; my $bytes_available = $ser->avail; $ser->close;
Provides basic read and write functionality on the Raspberry Pi's GPIO serial interface (GPIO pins 14 and 15).
In order to use GPIO pins 14 and 15 as a serial interface on the Raspberry Pi, you need to disable the built-in Bluetooth adaptor. This distribution will not operate correctly without this being done.
To disable Bluetooth on the Pi, edit the
/boot/config.txt, and add the following line:
Save the file, then reboot the Pi.
Opens the specified serial port at the specified baud rate, and returns a new RPi::Serial object.
Mandatory, String: The serial device to open (eg:
Mandatory, Integer: A valud baud rate to use.
Closes an already open serial device.
Returns the number of bytes waiting to be read if any.
Flush any data currently in the serial buffer.
ioctl file descriptor for the current serial object.
Retrieve a single character from the serial port.
Read a specified number of bytes into a string.
Mandatory, Integer; The number of bytes to read. If this number is larger than what is available to be read, a 10 second timeout will briefly hand your application.
Writes a single character to the serial device.
Mandatory, Unsigned Char: The character to write to the port.
Write a character string to the serial device.
Mandatory, String: Whatever you want to write to the serial line.
<steveb at cpan.org>
Copyright 2018 Steve Bertrand.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.