Net::Elexol::EtherIO24 - Object interface for manipulating Elexol Ether I/O 24 units with Perl
Version 0.18.
Requires Perl 5.8.0.
use Net::Elexol::EtherIO24;
Net::Elexol::EtherIO24->debug(1); my $eio = Net::Elexol::EtherIO24->new(target_addr=>$addr, threaded=>1);
for my $line (0..23) {
print "line $line dir: ".$eio->get_line_dir($line)." ".
"line $line val: ".$eio->get_line($line)."\n";
}
$eio->close;
The Ether I/O 24 manufactured by Elexol is an inexpensive and simple to use/operate device designed for remote control or remote sensing. It has 24 lines that are each programmable for input or output and a variety of other things.
The control protocol is relatively simplistic and UDP based. This Perl module attempts to abstract this protocol and add other features along the way. In particular, programmers are encouraged to investigate setting direct_writes => 0 and direct_reads => 0 in the constructor for network efficiency (since these are not yet the defaults).
It is thread savvy and will use threads unless told not to. It might perform adequately without threads, but various functionality would be reduced as a result. In particular, the module functions in a nice asynchronous way when it can use threads. Threads support requires Perl 5.8. This module may not function correctly, or even compile, with an older Perl. Your Perl will require Threads to be enabled at compile-time, even if you don't use Threads.
It uses IO::Socket::INET for network I/O and Time::HiRes for timing.
It was developed using Perl on a FreeBSD and a Linux system, but has
been known to function using Perl with Cygwin or ActivePerl on Windows.
Net::Elexol::EtherIO24 object complete with associated
socket and any necessary threads (if enabled). Returns undef if
this is not possible, whereupon the application can check
Net::Elexol::EtherIO24->error() for any relevant error string.
Arguments are given in key => value form from these candidates:
recv_timeout defaults to '1.0', service_recv_timeout to '1.0' and service_status_fetch to '60.0'.
The latter method (a setting of '0') can cause less network traffic if you are constantly polling the device at the expense of a marginally longer interval before the device is polled. However, you must call the indirect_write_send method in order to push out writes quickly, or especially if you are not using threads.
By default, if the close method is called any pending writes are sent (See flush_writes_at_close below).
If data is received that would overwrite a pending write then any pending writes are sent.
It should be noted that this is very risky since collisions will occur if two such agents attempt to write to the same group of lines at approximately the same time.
Net::Elexol::EtherIO24::debug(1) before cloning
it).
$debug_prefix is displayed at the start of all debug output and defaults to 'eio24'. You can set this, for example, if you have more than one EtherIO24 object so you can differentiate the debugging output of each.
See also the debug method. Also note that when using threads, the thread ID
that produced the debugging output is included after the prefix.
Many of the items in this hash are threads::shared when we are threading.
The object destructor will attempt to call this function when the world ends, but Perl might not be patient enough to wait for threads to end by that time.
Can be called on the parent to set default debugging level, and on each object to control that objects debug level.
Note that this value is global - it is shared between all EtherIO24 objects
so that you can return an error should new() fail to construct a new object.
This is used in the send/receive routines if a high enough debug level is set and is provided here in case someone else finds it useful.
$offset is optional and specifies the offset in the packet to start at, defaults to 0.
$increment is optional and specifies how many items to display per line, defaults to 16.
Additionally gets all the reserved and user space words if $fetchall is 1.
Returns 1 on success, 0 on failure.
If recv is 1 then it will wait for the results to arrive, otherwise it returns immediately.
Returns 1 on success, 0 on failure.
Returns 1 on success, 0 on failure.
It should be called periodically (often) if you aren not using threads; otherwise it is not necessary (but not harmful) to call this.
Verify commands to be sent. Returns 1 if the command(s) is(are) valid. Returns
0 if any command is invalud. Will search the entire string given for multiple commands.
Will perform various processing tasks on the command, such as resetting the ``status received'' flags for any status fields referenced by the command.
Verify a command is valid and if so, return how many bytes of it form that valid command or 0 if invalid.
Will perform various tasks on the command, such as updating the stored status of things referenced in the command. When threading, it also sends a signal to indicate that new status has arrived, if relevant.
Returns 0 on failure, or the result of send_pkt otherwise.
recv_result() instead.
Wait for a packet from the EtherIO24 unit. Returns an array of received commands upto any point where an invalid command was found in the input. Is NOT thread-friendly unless used in a particular way!
Received packets are passed through verify_recv_command to parse into commands and perform any automatic processing on them.
Need to give $cmd for threaded operation so it knows what result in particular to wait for. Returns undef if there was a problem doing this, such as a timeout waiting for the reply.
Replies with the reply command as received, except when it's an eeprom command and threads are being used. In this case the actual command returned is an indeterminate recent eeprom related reply.
Ignored if line is (believed to be) an input.
If using direct_reads then this method always queries the device. Otherwise this method uses the cached value, unless expired (See indirect_read_interval constructor parameter) whereupon it will query the device.
See get_line for direct_reads and cachine heuristics.
See get_line for direct_reads and cachine heuristics.
See get_line for direct_reads and cachine heuristics.
See get_line for direct_reads and cachine heuristics.
$addr is an ASCII string representation of an IP address. $port is a numeric UDP port number.
If not specified, it will attempt to determine the current IP address and port of the open UDP socket. This may not always be successful!
If $addr is a numeric 0 then the autoscan function will be disabled on the module.
Changes made by this function require a module restart to take effect.
Where $state = 1, the module will send status changes for $line.
Changes made by this function require a module restart to take effect.
Otherwise, disables startup port status setting.
Changes made by this function require a module restart to take effect.
The author is not in any way affiliated with Elexol, the manufacturer of the device this Perl module is designed to operate. This module has been developed using only data available in the public domain.
http://www.flirble.org/chrisy/elexol/, http://www.elexol.com/, http://www.elexol.com/Downloads/EtherIO24UM11.pdf
Chris Luke <chrisy@flirble.org>
Please report any bugs or feature requests to
bug-net-elexol-etherio24@rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
Copyright 2005..2008 Chris Luke, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.