NAME

Device::LabJack::Control


VERSION

0.04


SYNOPSIS

        use Device::LabJack::Control;
    # Instanciate an object.
        my $lj = Device::LabJack::Control->new();
        # Configure device
        $lj->set_configs(
        );
        print join qq{\n}, $self->get_config('Gain Values'),
        print join qq{\n}, $lj->update_device();


DESCRIPTION

An OO API for Device::LabJack plus a few OO methods so that it may be employed to collect data via Text::CSV::Munge and graphed via Chart::EPS_graph (which two modules I also wrote).

LabJack firmware version used in development: 1.10000002384186


SUBROUTINES/METHODS

Channel mask array

Used as mask for each individual channel for keeping track of which are inputs and which outputs, etc.

Method names explained.

The folks at LabJack and Chris Drake, author of Device::LabJack which is the parent to this module employed CamelCaseNaming for their code. As a fifty- year-old and sporting bifocals, I just cannot abide to squint at such awful typography anymore.

So I have translated the every instance to the far more easily distinguished under_score_naming system in this daughter module. Yet in so doing I have adhered to easily recognized variants from Chris Drake's module and from the LabJack manual.

Create a new instance object.

        my $obj = Device::LabJack::Control->new();

This Device::LabJack::Control employs its main object hash (%self) as a repository for most all of the control parameters expected by the LabJack device as inputs. Upon creation of a new object, defaluts are set for each of these.

Configure the device

        $obj->set_configs( 'Foo' => 1, 'Bar' => \@foobar );

Call the set_configs() method to modify any inputs expected by the LabJack device from their defaults as initialized by the new() method.

        $self->config_limits_check();

Called internally by set_configs(), the config_limits_check() method contstrains user-supplied input to reasonable and expected values. If any prove objectionable, a verbose reply is given to explain the objection.

        $self->ai_wiring('DDSSSS');

Called internally by set_configs(), the ai_wiring() method interprets user's choice of channel wiring configuraiton. Translates strings such as 'DDSSSS' so as to divy up the eight single-ended channels by pairs into substs including up to four differential channels. This way the user may consider channels in the hardware sense, however they may have wired it. Channels are thereby innumerated 0 thru N, never minding the LabJack's own AI channel innumeration.

Read device configuration

        $obj->get_config('Foo Bar');

Call the get_config() method to read back any previously set configuration by naming its hash key.

LabJack Device Functionality

Refer to the LabJack U12 User's Guide for specific details to all those methods which follow that are not described as internal.

        $self->$self->assemble_args( 'Foo 'Bar' );
        

Called internally by set_configs(), the assemble_args() method assembles parameters from out of the object's main hash into a format expected by the LabJack device. All such input arguments thus assembled are overridden by any suplied to the calling method itself.

        $obj->easy_analog_out( 2.2, 3.3 ); # AO2 to 2.2 Volts. AO3 to 3.3 Volgs.

Ref: LabJack manual, the EAnalogOut() function.

Call upon the easy_analog_out() method to set outputs for the LabJack's two fixed AO channels and also return a hash containing 'Error' and 'ID Number' for those channels.

        $obj->easy_count( 0 );

Call upon the easy_count() method to return a hash containing 'Error 'ID Number 'Count' and 'Miliseconds'.

        $obj->easy_digital_in( 15, 1 ); # Channel and IO-vs-D flag.

Ref: LabJack manual, the EDigitalIn() function.

Call upon easy_digital_in() to read from a digital input. Said input will be an IO if flag is 0, a D if flag is 1. Returns a hash containing 'Error 'ID Number and 'State' of selected input.

        $obj->lj_easy_digital_out( 15, 1, 1) ); # Channel, IO-vs-D flag, state.

Ref: LabJack manual, the EDigitalOut() function.

Call upon the easy_digital_out() method to write to an output, setting it to given state. Said output will be an IO if flag is 0, a D if flag is 1. Returns a hash containing only 'Error'.

        $obj->ai_sample([0,1,2,3]); # Sample wired channels 0 thru 3.

Ref: LabJack manual, the AISample() function.

Call upon the ai_sample() method to return a hash containing 'Error 'ID Number 'IO 0 'IO 1 'IO 2 'IO 3 'Over-Voltage' and 'Voltages' of which, the last two hash keys point to array refs.

        $obj->ai_burst([0,1,2,3]); # Sample wired channels 0 thru 3.

Ref: LabJack manual, the AIBurst() function.

Call upon the ai_burst() method to return a hash containing 'Error 'ID Number 'IO 0 'IO 1 'IO 2 'IO 3 'Over-Voltage' and 'Voltages' of which, the last two hash keys point to array refs.

        $obj->lj_ai_stream_start();
        $obj->lj_ai_stream_read();
        $obj->lj_ai_stream_clear();

Ref: LabJack manual, the AIStream*() group of functions.

Empty methods which do nothing except proclaim the parent module's non-support of them. Included only so as to prevent mystified head-scrathing on the part of newbie users.

        $obj->ao_update(1.75, 4.25); # Set AOs to 1.75 and 4.25 Volts respectively.

Ref: LabJack manual, the AOUpdate() function.

Call upon the ao_update() method to set AO1 and AO2 to given voltages. Returns a hash containing 'Error 'ID Number 'State D 'State IO' and 'Count'.

        $obj->asynch_config();

Ref: LabJack manual, the AsynchConfig() function.

Call upon the asynch_config() method to configure the asynchronous comm channel(s). Sets the baud rate, etc. Refer to Labjack manual for more details. Returns a hash containing only 'ID Number'.

        $obj->asynch();

Ref: LabJack manual, the Asynch() function.

Call upon the asynch() method to write then read half-duplex asynch data on pre-configured pairs of D lines. Refer to Labjack manual for more details. Returns a hash containing only 'ID Number' and 'Data'.

This method is not tested and likely to remain so until a later version.

        $obj->bits_to_volts(0, 4095); # Channel and bits.

Ref: LabJack manual, the BitsToVolts() function.

Call upon the bits_to_volts() method to convert for the given channel (at its current gain), a voltage equivalent to the given bits.

        $obj->volts_to_bits(0, 19.99); # Channel and voltage.

Ref: LabJack manual, the VoltsToBits() function.

Call upon the volts_to_bits() method to convert for the given channel (at its current gain), a 12-bit value equivalent to the given voltage.

        $obj->counter();

Ref: LabJack manual, the Counter() function.

Call upon the counter() method to read current state of the counter.

        $obj->digital_io();

Ref: LabJack manual, the DigitalIO() function.

Call upon the digital_io() method to read and write all 20 digital IO's. All D lines must be configured first as, contrary to the LabJack manual, this function does not set them as either input or output. Use either a prior call to easy_digital_out(), easy_digital_in() or set_configs() for that.

        $obj->get_firmware_version();

Ref: LabJack manual, the BetFirmwareVersion() function.

Call upon the get_firmware_version() method to return the firmware version.

        $obj->local_id();

Ref: LabJack manual, the LocalID() function.

Call upon the local_id() method to change a LabJack's local ID. Changes will not take effect until the LabJack is re-enumerated.

        $obj->pulse_out_calc(5, 0.666); # 5 Hz at 60% duty cycle.

Ref: LabJack manual, the PulseOutCalc() function. Note significant differences. I elected to re-write this function for two reasons. Firstly, because in the parent module Device::LabJack as of version 0.21 it did not work. Secondly, I preferred it should work this way instead.

Call upon the pulse_out_calc() method to calcuate the inputs required by the pulse_out() method.

        $obj->pulse_out_calc_retro(254, 26, 255, 13); # timeB1, timeC1, timeB2, timeC2

Call upon the pulse_out_calc_retro() method to reverse-calcuate the the output waveform given a set of LabJack Reference Manual type input values.

        my @b1_c1_b2_c2 = (254, 26, 255, 13);
        $obj->pulse_out( 0, 2, 512, @b1_c1_b2_c2 );

Ref: LabJack manual, the PulseOut() function. Usage differs in that any D line you choose to pulse will be automatically set as an output if not done already.

Call upon the pulse_out() method to output pulses on any or all of the eight digital IO lines, D0-D7. The wierdness of this method originates in the LabJack itself and is reflected in all its ugliness within the parent module Device::LabJack. Just in case it might have some reason behind it, rather than rewrite it more to my liking, I have defined an a additional method named easy_pulse_out(). Look for it further down in this file.

BUG NOTE: To use either the this pulse_out() method or its daughter method easy_pulse_out() without crashing you will require the module Device::LabJack version 0.3 or later. Versions 0.21 and earlier suffer a small typo in their LabJack.xs files. As of this writing, said latest version was not yet in CPAN and available from Chris Drake directly or from myself. Thanks to Chris for acting upon my bug report immediately upon being informed of it and for emailing the fix to me directly.

        $obj->easy_pulse_out( 0, 2, 512, 10, 0.5 );

Call upon the easy_pulse_out() method to in the place of pulse_out() where you prefer to supply frequency and duty cycle in the place of the four timing critera timeB1, timeC1, timeB2, timeC2.

        my @b1_c1_b2_c2 = (254, 26, 255, 13);
        $obj->pulse_out_start( 0, 2, 512, @b1_c1_b2_c2 );

Ref: LabJack manual, the PulseOutStart() function. Usage differs in that any D line you choose to pulse will be automatically set as an output if not done already.

Call upon the pulse_out_start() method the same as for pulse_out() where you prefer the interpreter should not wait its return, but proceed with the rest of the script.

        $obj->update_tris_d( bool, channels );

Called by those subroutines which make changes of direction in the digital IO's so that their status is tracked in the main hash.

        $obj->easy_pulse_out_start( 0, 2, 512, 10, 0.5 );

Call upon the easy_pulse_out_start() method in the place of easy_pulse_out() where you prefer to supply frequency and duty cycle rather than the four timing critera timeB1, timeC1, timeB2, timeC2.

        $obj->pulse_out_finish( 30 ); # Thirty secs timeout.

Ref: LabJack manual, the PulseOutFinish() function.

Call upon the pulse_out_finish() method to pause interpretation while awaiting pulses initiated by pulse_out() or easy_pulse_out() to be completed.

        $obj->reenum();

Ref: LabJack manual, the ReEnum() function.

Call the method reenum() to cause the LabJack to reset after two seconds. The LabJack will re-enumerate upon resetting.

        $obj->re_set(); # Think 'reset' for LabJack.

Ref: LabJack manual, the Reset() function.

Call the method lj_Reset() to cause the LabJack to reset after two seconds. The LabJack will re-enumerate upon resetting.

        $obj->sht1x();
        $obj->sht_comm();
        $obj->sht_crc();

Ref: LabJack manual, the SHT1X(), SHTComm() and SHTCRC() functions.

I don't have one of these sensors. Not being able to test, I have put off writing these methods until such time as I obtain one. As of now they only inform of not being supported.

        hashify($names_aref, @values);

Called internally by most methods to compose the hash returned by those methods. I do it this way because there were so many different ones that I could not remember them.

        print $obj->explain( $lj->foo( 3 ) );

Call upon the explain() method to return a verbose description for whatever hash another method might return.

        $obj->extract_from_href( $obj->foo('bar'), 'this_key', 'that_key' );

Call upon the extract_from_href() method to return an array of select values from the hash ref returned by most methods below.


BUGS AND LIMITATIONS

I wrote this for me and you are welcome to it for free. I offer absolutely no warranties or guarantees of any kind (expressed, implied, or even vaguely hinted at). In all probability it is riddled with bugs and wholly incompatible with all hardware everywhere...software and wetware too...down to your very DNA. Thus forewarned, employ it entirely at your own risk.


AUTHOR

Gan Uesli Starling <gan@starling.us>


LICENSE AND COPYRIGHT

Copyright (c) 2006 Gan Uesli Starling. All rights reserved.

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

LabJack Error Codes.

0 No error. 1 Unknown error. 2 No LabJacks found. 3 LabJack n not found 4 Set USB buffer error. 5 Open handle error. 6 Close handle error. 7 Invalid ID. 8 Invalid array size or value. 9 Invalid power index. 10 FCDD size too big. 11 HVC size too big. 12 Read error. 13 Read timeout error. 14 Write error. 15 Turbo error. 16 Illegal channel index. 17 Illegal gain index. 18 Illegal AI command. 19 Illegal AO command. 20 Bits out of range. 21 Illegal number of channels. 22 Illegal scan rate. 23 Illegal number of samples. 24 AI response error. 25 LabJack RAM checksum error. 26 AI sequence error. 27 Maximum number of streams. 28 AI stream start error. 29 PC buffer overflow. 30 LabJack buffer overflow. 31 Stream read timeout. 32 Illegal number of scans. 33 No stream was found.

40 Illegal input. 41 Echo error. 42 Data echo error. 43 Response error. 44 Asynch read timeout error. 45 Asynch read start bit error. 46 Asynch read framing error. 47 Asynch DIO config error. 48 Caps error. 49 Caps error. 50 Caps error. 51 HID number caps error. 52 HID get attributes warning.

57 Wrong firmware version error. 58 DIO config error.

64 Could not claim all Labjacks. 65 Error releasing all LabJacks. 66 Could not claim LabJack. 67 Error releasing LabJack. 68 Claimed abandoned LabJack. 69 Local ID -1 thread stopped. 70 Stop thread timeout. 71 Thread termination failed. 72 Feature handle creation error. 73 Create mutex error.

80 Synchronous CS state or direction error. 81 Synchronous SCK direction error. 82 Synchronous MSIO direction error. 83 Synchronous MOSI direction error.

89 SHT1X CRC error. 90 SHT1X measurement ready error. 91 SHT1X ack error. 92 SHT1X serial reset error