K8055 mh interface

K8055 mh interface

Enclosed is the first release of my K8055 interface code for mh. It comes
in two parts, the mh stuff and a standalone daemon.

The daemon source is in the .tar.bz2 file. Two files will be created, the
daemon and a client. The daemon can be run on any unix-like box that has
libusb. The client, and mh parts too, can be run on any machine with TCP
connectivity to the daemon. The client-server protocol is plain text, so
you can send commands through a standard telnet prompt. Look at the daemon
code if you are interested in the protocol itself. Multiple clients can
access the daemon at the same time. Port settings are on a last set wins
basis if there are conflicting settings.

The mh part is composed of two files. The .pm is the interface code and the
.pl is meant to be placed in mh/web/bin. It is a crude, but complete
interface to the main code. Type perldoc k8055.pm to get detailed
instructions. You can read any port and write to any port.

The code is designed to automatically (every 10 seconds by default) read a
subset of all the input ports. In other words, asking for the current state
of digital port 1 actually returns the last retrieved value of digital port
1, it doesn't ask the board at that point in time. You can call
K8055->update() to get the code to immediately request new values, however
this will still happen asynchronously, so it is not guaranteed that the next
call to read values includes the updated value.

You need to tell K8055 which ports to get values for. If you don't, no
values will be retrieved, either on the 10 second schedule or on a manual
update call. If the value of a monitored port changes, the value of
K8055->state_now will be set to the name of the port (i.e. "digital 1" if
digital port 1 goes from 0 to 1 or from 1 to 0).

Sample code is below. In order to use the web interface as written, you
need to create $k8055 somewhere in your code at a minimum. As well, there
are mh parameters k8055_host and k8055_port that should point to the daemon.

Whenever the value of these ports change, $k8055->state_now will return the name of the port that has changed (i.e. 'digital 4'). The state of each port is checked every 10 seconds (by default, can be changed).

Use the write... methods to change the value of the output ports.

=head1 mh.ini parameters

=over

=item B<k8055_host>

Hostname that is running k8055d.

=item B<k8055_port>

Port on hostname to which daemon is listening.

=back

=head1 Methods

=over

=item B<state_now>

For one pass, will return the name of the input port that has just changed.