| perl-Hardware-UPS-Perl documentation | view source | Contained in the perl-Hardware-UPS-Perl distribution. |
Hardware::UPS::Perl::Connection::Serial - package of methods dealing with connection to a serial port
use Hardware::UPS::Perl::Connection::Serial;
$port = '/dev/ttyS0';
$serial = new Hardware::UPS::Perl::Connection::Serial $port;
undef $serial; # disconnects
Hardware::UPS::Perl::Connection::Serial provides methods dealing with connections to a serial port.
new - creates a new serial object
$serial = Hardware::UPS::Perl::Connection::Serial->new();
$serial = Hardware::UPS::Perl::Connection::Serial->new($port);
$serial = Hardware::UPS::Perl::Connection::Serial->new({
SerialPort => $port,
Logger => $Logger,
});
new initializes a serial object $serial and opens the serial port to
connect to, if the port is specified.
new expects either a single argument, the serial port, or an anonymous hash as options consisting of key-value pairs.
$portoptional; serial device; defines a valid serial port.
SerialPort => $portoptional; serial device; defines a valid serial port.
Logger => $loggeroptional; a Hardware::UPS::Perl::Logging object; defines a logger; if not specified, a logger sending its output to STDERR is created.
"connect", "connected", "disconnect", "getLogger", "getPort", "setLogger", "setPort"
setPort - sets the serial device to connect to
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $serial->setPort($port);
setPort sets the serial port to connect to and returns the previous port if available, undef otherwise.
$portserial device; defines a valid serial port.
getPort - gets the serial device being connected to
$serial = Hardware::UPS::Perl::Connection::Serial->new($port); $port = $serial->getPort();
getPort returns the serial port being connected to.
setDebugLevel - sets the debug level
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $serial->setDebugLevel(1);
setDebugLevel sets the debug level, the higher, the better. It returns the previous one if available, 0 otherwise.
$debugLevelinteger number; defines the debug level.
getDebugLevel - gets the current debug level
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $debugLevel = $serial->getDebugLevel();
getDebugLevel returns the current debug level.
setLogger - sets the logger to use
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $serial->setLogger($logger);
setLogger sets the logger, a Hardware::UPS::Perl::Logging object, used for logging. setLogger returns the previous logger used.
$loggerrequired; a Hardware::UPS::Perl:Logging object; defines the logger for logging.
getLogger - gets the current logger for logging
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $logger = $serial->getLogger();
getLogger returns the current logger, a Hardware::UPS::Perl::Logging object used for logging, if defined, undef otherwise.
getErrorMessage - gets the internal error message
$serial = Hardware::UPS::Perl::Connection::Serial->new($port);
unless ($serial->connected()) {
print STDERR $serial->getErrorMessage($errorMessage), "\n";
exit 0;
}
getErrorMessage returns the internal error message, if something went wrong.
connect - connects to a serial port
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $serial->connect($port);
connect connects to a serial port $port using package FileHandle. If there is a connection already and the port has changed, the old connection is dropped, otherwise nothing will be done. If no port is specified, it will be checked whether the port has been previously set by method setPort, and used for the connection, consequently. If no port is available at all. the default port provided by package Hardware::UPS::Perl::Constants will be used, usually being /dev/ttyS0. The serial port will be locked using the Perl builtin function flock, In addition, the serial port settings will be modified to have a Baud rate of 2400, with XON/XOFF flow control enabled and echo off using standard package IO::Stty.
optional; serial device; defines a valid serial port.
connected - tests the connection status
$serial = Hardware::UPS::Perl::Connection::Serial->new();
$serial->connect($port);
if ($serial->connected()) {
...
}
connected tests the connection status, returning 0, when not connected, and 1 when connected.
disconnect - disconnects from a serial port
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $serial->connect($port); $serial->disconnect(); $serial = Hardware::UPS::Perl::Connection::Serial->new(); $serial->connect($port); undef $serial;
disconnect disconnects from a serial port, unlocks it and restores the previous settings of the serial port using package IO::Stty.
undef $serial has the same effect as $serial->disconnect().
sendCommand - sending a command to the serial port
$serial = Hardware::UPS::Perl::Connection::Serial->new(); $serial->connect($port); $serial->sendCommand($command, \$response, $responseSize);
sendCommand sends the command $command appended with the \r to a
serial port connected and reads the response from it using the package
IO::Select awaiting the size of the response $responseSize.
$commandstring; defines a command.
$responsestring; the response from the serial port.
$responseSizeinteger; the buffer size of the response from the serial port.
Errno(3pm), Fcntl(3pm), FileHandle(3pm), IO::Select(3pm), Hardware::UPS::Perl::Connection(3pm), Hardware::UPS::Perl::Connection::Net(3pm), Hardware::UPS::Perl::Constants(3pm), Hardware::UPS::Perl::Driver(3pm), Hardware::UPS::Perl::Driver::Megatec(3pm), Hardware::UPS::Perl::General(3pm), Hardware::UPS::Perl::Logging(3pm), Hardware::UPS::Perl::Utils(3pm)
Hardware::UPS::Perl::Connection::Serial was inspired by the usv.pl program by Bernd Holzhauer, <www.cc-c.de>. The latest version of this program can be obtained from
http://www.cc-c.de/german/linux/linux_usv.php
Another great resource was the Network UPS Tools site, which can be found at
http://www.networkupstools.org
Hardware::UPS::Perl::Connection::Serial was developed using perl 5.8.8 on a SuSE 10.1 Linux distribution.
There are plenty of them for sure. Maybe the embedded pod documentation has to be revised a little bit.
Suggestions to improve Hardware::UPS::Perl::Connection::Serial are welcome, though due to the lack of time it might take a while to incorporate them.
Copyright (c) 2007 by Christian Reile, <Christian.Reile@t-online.de>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. For further licensing details, please see the file COPYING in the distribution.
| perl-Hardware-UPS-Perl documentation | view source | Contained in the perl-Hardware-UPS-Perl distribution. |