Comedi-Lib

 view release on metacpan or  search on metacpan

Lib.pm  view on Meta::CPAN

class method returns undef if there is an error.

=cut

sub get_board_name {
   my $self = shift;
   $self->_assert_open();
   return lib_get_board_name($self->{handle});
}

=item get_subdevice_type

Type of subdevice.

Example code,

   my $subdev_type = $cref->get_subdevice_type($subdev);
   
   if ($subdev_type == Comedi::Lib::COMEDI_SUBD_AI) {
      print "We've an analog input subdevice\n";
   }

This class method returns the subdevice type, or -1 if there is an error.

=cut

sub get_subdevice_type {
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_get_subdevice_type($self->{handle}, $subdev);
}

=item find_subdevice_by_type

Search for subdevice type.

Example code,

   my $idx = $cref->find_sundevice_by_type(Comedi::Lib::COMEDI_SUBD_DO, 0);
   croak "No digital output subdevice found\n" if $idx == -1;
   
   print "Found digital output subdevice at index - $idx\n";

If it finds a subdevice with the requested type, C<find_subdevice_by_type()>
returns its index. If there is an error, the method returns -1 and sets the
appropriate error.

=cut

sub find_subdevice_by_type {
   my $self  = shift;
   my $type  = shift;
   my $start = shift;
   $self->_assert_open();
   return lib_find_subdevice_by_type($self->{handle}, $type, $start);
}

=item get_read_subdevice

Find streaming input subdevice.

Example code,

   my $streaming_input_support = $cref->get_read_subdevice();

   if ($streaming_input_support == -1) {
      print "No streaming input support available\n";
   }
   else {
      print "Comedi subdevice no. $streaming_input_support ",
            "allows streaming input\n";
   }

This class method returns the subdevice whose streaming input buffer is
accessible through the previous opened device. If there is no such subdevice,
-1 is returned.

=cut

sub get_read_subdevice {
   my $self = shift;
   $self->_assert_open();
   return lib_get_read_subdevice($self->{handle});
}

=item get_write_subdevice

Find streaming output subdevice.

Example code,

   my $streaming_output_support = $cref->get_write_subdevice();

   if ($streaming_output_support == -1) {
      print "No streaming output support available\n";
   }
   else {
      print "Comedi subdevice no. $streaming_output_support ",
            "allows streaming output\n";
   }

This class method returns the subdevice whose streaming output buffer is
accessible through the previous opened device. If there is no such subdevice,
-1 is returned.

=cut

sub get_write_subdevice {
   my $self = shift;
   $self->_assert_open();
   return lib_get_write_subdevice($self->{handle});
}

=item get_subdevice_flags

Properties of subdevice.

Example code,

   my $subdev_flags = $cref->get_subdevice_flags($subdev);

   if ($subdev_flags & Comedi::Lib::SDF_READABLE) {
      print "The subdevice can be read\n";
   }
   else {
      print "The subdevice can't be read\n";
   }

   if ($subdev_flags & Comedi::Lib::SDF_WRITEABLE) {
      print "The subdevice can be written\n";
   }
   else {
      print "The subdevice can't be written\n";
   }

This method returns a bitfield describing the capabilities of the specified
subdevice. If there is an error, -1 is returned, and the C<Comedilib> error
value is set.

=cut

sub get_subdevice_flags {
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_get_subdevice_flags($self->{handle}, $subdev);
}

=item get_n_channels

Number of subdevice channels.

Example code,

   my $n_channels = $cref->get_n_channels($subdev);
   print "Analog input no. of channels - $n_channels\n";

Returns the number of channels of the subdevice with the index subdev. This
method returns -1 on error.

=cut

Lib.pm  view on Meta::CPAN

   # Print the minimal sample value of the given analog input channel
   print "Analog input channel $chan min sample value - $range->{min}\n";
   
The class method C<get_range()> returns a hash reference that contains
information that can be used to convert sample values to or from physical
units. If there is an error, undef is returned.

=cut

sub get_range {
   my $self   = shift;
   my $subdev = shift;
   my $chan   = shift;
   my $rng    = shift;
   $self->_assert_open();
   return lib_get_range($self->{handle}, $subdev, $chan, $rng); 
}

=item find_range

Search for range.

Example code,

   my $rng_idx = $cref->find_range($subdev, $chan, $unit, $min, $max);
   
   if ($rng_idx == -1) {
      print "No matching range available\n"
   }
   else {
      print "Found a matching range for channel $chan at index $rng_idx\n";
   }

If a matching range is found, the index of the matching range is returned.
If no matching range is available, the class method returns -1.

=cut

sub find_range {
   my $self   = shift;
   my $subdev = shift;
   my $chan   = shift;
   my $unit   = shift;
   my $min    = shift;
   my $max    = shift;
   $self->_assert_open();
   return lib_find_range($self->{handle}, $subdev, $chan, $unit, $min, $max);
}

=item get_buffer_size

Streaming buffer size of subdevice.

Example code,

   my $buf_size = $cref->get_buffer_size($subdev);
   croak "An error has occurred" if $buf_size == -1;

   print "Streaming buffer size for the subdevice - $buf_size Bytes\n";
    
This class method returns the size -in Bytes- of the streaming buffer for the
specified subdevice. On error, -1 is returned.

=cut

sub get_buffer_size {
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_get_buffer_size($self->{handle}, $subdev);
}

=item get_max_buffer_size

Maximum streaming buffer size.

Example code,

   my $max_size = $cref->get_max_buffer_size($subdev);
   croak "An error has occurred" if $max_size == -1;

   print "Max. streaming buffer size for the subdevice - $max_size Bytes\n";

This class method returns the maximum allowable size -in Bytes- of the
streaming buffer for the specified subdevice. On error, -1 is returned.

=cut

sub get_max_buffer_size {
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_get_max_buffer_size($self->{handle}, $subdev);
}

=item set_buffer_size

Streaming buffer size of subdevice.

Example code,

   # First, determine the virtual memory page size (look at the Comedi docu)
   require POSIX;

   my $vmps = POSIX::sysconf(&POSIX::_SC_PAGESIZE);
   $vmps   *= 2;

   print "Trying to set the streaming buffer size to $vmps\n";

   if ($cref->set_buffer_size($subdev, $vmps) == -1) {
      print "Warning: Couldn't set new streaming buffer size\n";
   }

The C<set_buffer_size()> class method returns the new buffer size in Bytes.
On error, -1 is returned.

=cut

sub set_buffer_size {
   my $self   = shift;
   my $subdev = shift;
   my $size   = shift;
   $self->_assert_open();
   return lib_set_buffer_size($self->{handle}, $subdev, $size);
}

=item do_insnlist

Perform multible instructions.

Example code,

   my @insn_arr = ({
      insn      => Comedi::Lib::INSN_READ,
      n         => 2,
      data      => [0, 0],
      subdev    => 0,
      chanspec  => $cref->CR_PACK($chan, $rng, $aref)
   }, {
      insn      => Comedi::Lib::INSN_WRITE,
      n         => 1,
      data      => [255],
      subdev    => 1,
      chanspec  => $cref->CR_PACK($chan, $rng, $aref)
   });

   # Now, create a comedi_insnlist like hash reference
   my $comedi_insnlist = {
      n_insns => 2,
      insns   => [@insn_arr]
   };

   my $retval = $cref->do_insnlist($comedi_insnlist);
   croak "An error has occurred" if $retval == -1;

   print "[<1>] data (AI) - ", $insn_arr[0]->{data}[0], "\n";
   print "[<2>] data (AI) - ", $insn_arr[0]->{data}[1], "\n";

This class method returns the number of successfully completed instructions.
If there is an error before the first instruction can be executed, -1 is
returned.   

=cut

sub do_insnlist {
   my $self     = shift;
   my $insnlist = shift;
   $self->_assert_open();
   return lib_do_insnlist($self->{handle}, $insnlist);
}

Lib.pm  view on Meta::CPAN


Example code,

   my $retval = $cref->dio_bitfield2($subdev, $write_mask, \$bits, $base_ch);
   croak "An error has occurred" if $retval == -1;

   # Evaluate the $bits variable...

If successful, C<dio_bitfield2()> returns 0. If there is an error, -1 is
returned.

=cut

sub dio_bitfield2 {
   my $self       = shift;
   my $subdev     = shift;
   my $write_mask = shift;
   my $bits       = shift;
   my $base_ch    = shift;
   $self->_assert_open();
   return lib_dio_bitfield2($self->{handle}, $subdev, $write_mask, $bits,
                           $base_ch);
}

=item get_cmd_src_mask

Streaming input/output capabilities.

Note that this subroutine has no functionality as long as I have no testing
device with the associated driver.

Patches or suggestions are welcome, send me an email (Subject: Comedi::Lib).

=cut

sub get_cmd_src_mask {
   print STDERR __PACKAGE__, '::',
         "get_cmd_src_mask: Sorry, I've no functionality at this time!\n";
   return;
}

=item get_cmd_generic_timed

Streaming input/output capabilities.

Note that this subroutine has no functionality as long as I have no testing
device with the associated driver.

Patches or suggestions are welcome, send me an email (Subject: Comedi::Lib).

=cut

sub get_cmd_generic_timed {
   print STDERR __PACKAGE__, '::',
         "get_cmd_generic_timed: Sorry, I've no functionality at this time\n";
   return;
}

=item cancel

Stop streaming input/output in progress.

Example code,

   # This class method is useful in combination with command()
   # and this class method is not completely implemented yet.

If successful, C<cancel()> returns 0, otherwise -1.

=cut

sub cancel {
   print STDERR __PACKAGE__, '::',
         "cancel: U use me at your own _risk_\n";
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_cancel($self->{handle}, $subdev);
}

=item command

Start streaming input/output.

Note that this subroutine has no functionality as long as I have no testing
device with the associated driver.

Patches or suggestions are welcome, send me an email (Subject: Comedi::Lib).

=cut

sub command {
   print STDERR __PACKAGE__, '::',
         "command: Sorry, I've no functionality at this time\n";
   return;
}

=item command_test

Test streaming input/output configuration.

Note that this subroutine has no functionality as long as I have no testing
device with the associated driver.

Patches or suggestions are welcome, send me an email (Subject: Comedi::Lib).

=cut

sub command_test {
   print STDERR __PACKAGE__, '::',
         "command: Sorry, I've no functionality at this time\n";
   return;
}

=item poll

Force updating of streaming buffer.

Example code,

   my $retval = $cref->poll($subdev);
   croak "An error has occurred" if $retval == -1;

If successful, this class method returns the number of additional bytes
available. If there is an error, -1 is returned.

=cut

sub poll {
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_poll($self->{handle}, $subdev);
}

=item set_max_buffer_size

Streaming buffer size of subdevice.

Example code,

   my $old_buf_size = $cref->set_max_buffer_size($subdev, $max_size);
   
   if ($old_buf_size == -1) {
      croak "An error has occurred";
   }
   else {
      print "Buffer size changed from $old_buf_size to $max_size.\n";
   }

If successful, the old buffer size is returned. On error, -1 is returned.

=cut

sub set_max_buffer_size {
   my $self     = shift;
   my $subdev   = shift;
   my $max_size = shift;
   $self->_assert_open();
   return lib_set_max_buffer_size($self->{handle}, $subdev, $max_size);
}

=item get_buffer_contents

Streaming buffer status.

Example code,

   # This class method is useful in combination with command()
   # and this class method is not completely implemented yet.
   
This class method returns the number of bytes that are available in the
streaming buffer. If there is an error, -1 is returned.

=cut

sub get_buffer_contents {
   print STDERR __PACKAGE__, '::',
         "get_buffer_contents: U use me at your own _risk_\n";
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_get_buffer_contents($self->{handle}, $subdev);
}

=item mark_buffer_read

Streaming buffer control.

Example code,

   # This class method is useful in combination with command()
   # and this class method is not completely implemented yet.

The C<mark_buffer_read()> class method returns the number of bytes
successfully marked as read, or -1 on error.

=cut

sub mark_buffer_read {
   print STDERR __PACKAGE__, '::',
         "mark_buffer_read: U use me at your own _risk_\n";
   my $self      = shift;
   my $subdev    = shift;
   my $num_bytes = shift;
   $self->_assert_open();
   return lib_mark_buffer_read($self->{handle}, $subdev, $num_bytes);
}

=item mark_buffer_written

Streaming buffer control.

Example code,

   # This class method is useful in combination with command()
   # and this class method is not completely implemented yet.

The C<mark_buffer_written()> class method returns the number of bytes
successfully marked as written, or -1 on error.

=cut

sub mark_buffer_written {
   print STDERR __PACKAGE__, '::',
         "mark_buffer_written: U use me at your own _risk_\n";
   my $self      = shift;
   my $subdev    = shift;
   my $num_bytes = shift;
   $self->_assert_open();
   return lib_mark_buffer_written($self->{handle}, $subdev, $num_bytes);
}

=item get_buffer_offset

Streaming buffer status.

Example code,

   # This class method is useful in combination with command()
   # and this class method is not completely implemented yet.

This class method returns the offset in bytes of the read pointer in the
streaming buffer. If there is an error, -1 is returned.

=cut

sub get_buffer_offset {
   print STDERR __PACKAGE__, '::',
         "get_buffer_offset: U use me at your own _risk_\n";
   my $self   = shift;
   my $subdev = shift;
   $self->_assert_open();
   return lib_get_buffer_offset($self->{handle}, $subdev);
}

=back

=head1 AUTHOR

Manuel Gebele <forensixs[at]gmx.de>

=head1 SEE ALSO

The linux control and measurement device interface project at
L<http://www.comedi.org>.

=head1 SUPPORT & DOCUMENTATION

After installing, you can find documentation for this module with the perldoc command

   perldoc Comedi::Lib

or use the man command

   man Comedi::Lib

You can also look for information at:

   Search CPAN
      http://search.cpan.org/dist/Comedi-Lib

   CPAN Request Tracker
      http://rt.cpan.org/NoAuth/Bugs.html?Dist=Comedi-Lib

   AnnoCPAN, annotated CPAN documentation
      http://annocpan.org/dist/Comedi-Lib

   CPAN Ratings
      http://cpanratings.perl.org/d/Comedi-Lib

   Comedi
      http://www.comedi.org

=head1 BUGS

Please report any bugs or feature request to my email address, or through the
web interface at http://rt.cpan.org/Public/Bug/Report.html?Queue=Comedi::Lib.
I'll be notified, and then you'll automatically be notified of progess on your
bug as I make changes.

=head1 COPYRIGHT & LICENSE

Copyright (c) 2009 Manuel Gebele



( run in 1.147 second using v1.01-cache-2.11-cpan-140bd7fdf52 )