NAME

Device::Velleman::K8055::Fuse - Communication with the Velleman K8055 USB experiment board using Fuse and K8055fs

VERSION

Version 0.3

ABSTRACT

Device::Velleman::K8055::Fuse provides an object-oriented API to the k8055fs Fuse-based interface to the Velleman K8055 USB Experimental Interface Board.

Using the module, it is possible to set two 5v analog output ports, read from two 5v analog input boards, read from a 5-bit digital input stream, write to an 8-bit digital output stream, and set two digital counters with configurable gate times.

SYNOPSIS

    use Device::Velleman::K8055::Fuse
	my $dev = new(pathToDevice=>'/path/to/device','debug'=>1);

    
    # let us flicker the Analog output leds three times each
    for (my $i = 0; $i < 3; $i++)
    {
        for (my $j = 1; $j < 3; $j++)
        {
            $dev->SetAnalogChannel($j);
            $dev->ClearAnalogChannel($j == 1 ? 2 : ($j -1));
            sleep(1);
        }
    }
    # clear the analog output
    $dev->ClearAllAnalog();

In order to work with this module, the k8055fs utility must be installed. This utility relies on Fuse, which must also be installed.

new(%args)

The constructor. Buils the object.

Example:

New object with k8055 card initialisation

my $dev = Device::Velleman::K8055::Fuse->new(
    initDevice => { -U => 0, pathToDevice => '/tmp/k8055', -b => 2, test => 1 },
    debug   => 1
) || die "Failed to get an object $!";

New object using initialized k8055 card

    my $dev = Device::Velleman::K8055::Fuse->new(
	pathToDevice => '/tmp/8055',
        debug   => 1,
    ) || die "Failed to get an object $!";

Inputs

(optional) initDevice: hash reference containing the inputs expected by InitialiseDevice. Refer to method documentation below for input specifications. If initDevice exists, then method InitialseDevice is called inside the constructor.

debug = 0 / 1 : Debug flag for outputing debugging information

pathToDevice : the name of the path where the k8055fs commands are mounted.

Returns the object on success

ReadAnalogChannel();

This reads the value from the analog channel indicated by $channel (1 or 2). The input voltage of the selected 8-bit Analogue to Digital converter channel is converted to a value which lies between 0 and 255.

Returns the string containing the value.

ReadAllAnalog();

This reads the values from the two analog ports into $data1 and $data2.

OutputAnalogChannel();

This outputs $value to the analog channel indicated by $channel. The indicated 8-bit Digital to Analogue Converter channel is altered according to the new value. This means that the value corresponds to a specific voltage. The value 0 corresponds to a minimum output voltage (0 Volt) and the value 255 corresponds to a maximum output voltage (+5V). A value of $value lying in between these extremes can be translated by the following formula : $value / 255 * 5V.

OutputAllAnalog();

This outputs $value1 to the first analog channel, and $value2 to the second analog channel. See OutputAnalogChannel for more information.

ClearAnalogChannel();

This clears the analog channel indicated by $channel. The selected DA-channel is set to minimum output voltage (0 Volt).

Input: channel number

Output: value between 0 (min) and 255 (max)

$dev->ClearAnalogChannel(1);

($value1,$value1) ClearAllAnalog();

The two DA-channels are set to the minimum output voltage (0 volt).

Returns 255 on success. returns undef if either of the analog channels failed.

SetAnalogChannel($channel);

The selected 8-bit Digital to Analogue Converter channel is set to maximum output voltage. Returns the set value.

SetAllAnalog();

The two DA-channels are set to the maximum output voltage. Returns 255 on success. returns undef if either of the analog channels failed.

WriteAllDigital($value);

The channels of the digital output port are updated with the status of the corresponding bits in the $value parameter. A high (1) level means that the microcontroller IC1 output is set, and a low (0) level means that the output is cleared. $value is a value between 0 and 255 that is sent to the output port (8 channels).

ClearDigitalChannel($channel);

This clears the digital output channel $channel, which can have a value between 1 and 8 that corresponds to the output channel that is to be cleared.

This is the opposite of SetDigitalChannel.

ClearAllDigital();

This clears (sets to 0) all digital output channels.

SetDigitalChannel($channel);

This sets the digital output channel $channel, which can have a value between 1 and 8 that corresponds to the output channel that is to be cleared.

This is the opposite of ClearDigitalChannel.

AssignDigitalChannel($channel,$value,[$digitalFlag]);

This sets digital channel $channel to the assigned value.

SetAllDigital();

This sets all digital output channels to 1 (true).

$obj->SetAllDigital();

sets all digital output channels to 1, giving '1111111'.

ReadAllDigital('bin') or ReadAllDigital();

This reads all 5 digital ports at once. The 5 least significant bits correspond to the status of the input channels. A high (1) means that the channel is set, a low (0) means that the channel is cleared. Returns the decimal value of the the 8-channel interface card (0-255) unless flag 'bin' is set.

If flag 'bin' is set, then returns an array of binary characters (0/1).

Returns undef on error.

ReadDigitalChannel($channel);

The status of the selected input $channel is read.

$channel can have a value between 1 and 8 which corresponds to the input channel whose status is to be read.

The return value will be true (1) if the channel has been set, false (0) otherwise

returns undef on error.

ReadCounter($counternumber);

The function returns the status of the selected 16 bit pulse counter. The counter number 1 counts the pulses fed to the input I1 and the counter number 2 counts the pulses fed to the input I2.

returns an 16 bit count on success.

returns undef on error.

ResetCounter($counternumber);

This resets the selected pulse counter.

returns undef on error.

SetCounterDebounceTime($counternumber, $debouncetime);

The counter inputs are debounced in the software to prevent false triggering when mechanical switches or relay inputs are used. The debounce time is equal for both falling and rising edges. The default debounce time is 2ms. This means the counter input must be stable for at least 2ms before it is recognised, giving the maximum count rate of about 200 counts per second. If the debounce time is set to 0, then the maximum counting rate is about 2000 counts per second.

The $deboucetime value corresponds to the debounce time in milliseconds (ms) to be set for the pulse counter. Debounce time value may vary between 0 and 5000.

returns the set time in milliseconds on success.

returns undef on error.

get($file,$value)

uses IO::File to retrieve data from the FUSE files. Refer to the k8055fs readme for details.

$dev->set('/tmp/8055/digital_out',255);

This is a low-level call that is not particualrly intended for direct access from the API.

Returns $value on success and undef on error.

set($file,$value)

uses IO::File to send io to the FUSE files. Refer to the k8055fs readme for details.

$dev->set('/tmp/8055/digital_out',255);

This is a low-level call that is not particualrly intended for direct access from the API. Using the set function could desynchronize the internal representation for the binary array held in array

$dev->{binary_out}

Returns $value on success and undef on error.

dec2bin($dec)

convert a decimal to a string representing a bin

The binary string is represented as a big-endiani. In big-endian encoding, digits increase as the string progresses to the left:

  0 (dec) =        0 (bin).
  1 (dec) =        1 (bin).
  2 (dec) =       10 (bin).
  3 (dec) =       11 (bin).
  4 (dec) =      100 (bin).
255 (dec) = 11111111 (bin).

bin2dec($bin)

convert a string representing a binary number to a decimal number.

Refer to dec2bin for information on the binary format in use.

InitDevice (\%args)

Initialises the k8055 USB device by mounting the k8055 file system.

usage: $dev->InitialseDevice({-U=>1, -b=>2, pathToDevice=>'/tmp/8055'})

Input arguments

-b board number. (2-4) If skipped, default board (1) number is taken.

-U 1 0r 0 turn on USB debugging if true.

pathToDevice: Desired mount point of the k8055fs application. This directory needs to be accessible by the user.

fuseOptions: additional options to pass to FUSE.

test: do not run the k8055fs initialiaation. Print the command to STDOUT and return success. This is for debugging support.

See also new().

AUTHOR

Ronan Oger, <ronan@cpan.org>

ACKNOWLEDGEMENTS

Special thanks to Jouke Visser, author of Device::Velleman::K8055 for writing the original win32-based module. I extensively copied his documentation and derived the method names from the names used by Jouke.

BUGS

Likely to be many, please use http://rt.cpan.org/ for reporting bugs. The counter functionality is poorly tested and I suspect it has bugs.

SEE ALSO

For more information on this board, visit http://www.velleman.be.

For more information on the K0855fs fuse implementation of K0855, visit https://launchpad.net/k8055fs

For more information on the Fuse driver, visit the FUSE project on sourceforge: http://fuse.sourceforge.net

For Win32 applications, see Jouke Visser's Device::Velleman::K8055 implementation.

COPYRIGHT & LICENSE

Copyright 2008 Ronan Oger, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.