Device-SaleaeLogic

 view release on metacpan or  search on metacpan

SaleaeDeviceApi.h  view on Meta::CPAN

class SALEAE_DEVICE_API LogicInterface : public LogicAnalyzerInterface
{
public:
	LogicInterface( LogicDevice* logic_device );

	void ReadStart( ); //Start data collection.  You can get the resulting data in your OnReadData callback.
	void WriteStart( ); //Start writing out data.  Your OnWriteData callback will be called to provide the data to Logic.
	void Stop( ); //Stop data collection.  Only use if data collection is actually in progress.

	//Single Byte Data
	U8 GetInput( );					//Get the current byte Logic is reading.  Don't do this while you're doing the Read or Write streaming above.
	void SetOutput( U8 val );		//Make logic output a particular byte value.  Don't do this while you're doing the Read or Write streaming above.

protected:
	LogicDevice* mLogicDevice;
};

class SALEAE_DEVICE_API Logic16Interface : public LogicAnalyzerInterface
{
public:
	Logic16Interface( Logic16Device* logic_16_device );

SaleaeLogic.xs  view on Meta::CPAN

unsigned int
saleaeinterface_is_usb2(obj, id)
    saleaeinterface_t *obj
    unsigned int id
    CODE:
        RETVAL = saleaeinterface_isusb2(obj, id);
    OUTPUT:
        RETVAL

unsigned int
saleaeinterface_is_streaming(obj, id)
    saleaeinterface_t *obj
    unsigned int id
    CODE:
        RETVAL = saleaeinterface_isstreaming(obj, id);
    OUTPUT:
        RETVAL

unsigned int
saleaeinterface_get_channel_count(obj, id)
    saleaeinterface_t *obj
    unsigned int id
    CODE:
        RETVAL = saleaeinterface_getchannelcount(obj, id);
    OUTPUT:

lib/Device/SaleaeLogic.pm  view on Meta::CPAN

}

sub DESTROY {
    saleaeinterface_DESTROY($_[0]->{obj}) if $_[0]->{obj};
}

sub is_usb2 {
    return saleaeinterface_is_usb2($_[0]->{obj}, $_[1]);
}

sub is_streaming {
    return saleaeinterface_is_streaming($_[0]->{obj}, $_[1]);
}

sub get_channel_count {
    return saleaeinterface_get_channel_count($_[0]->{obj}, $_[1]);
}

sub get_sample_rate {
    return saleaeinterface_get_sample_rate($_[0]->{obj}, $_[1]);
}

lib/Device/SaleaeLogic.pm  view on Meta::CPAN

        # ... checking for USB 2.0 may not be that useful except ...
        # ... when say using an computer with an older USB port ...
        # ... it may determine the speed with which you may be able to sample
        # ... but it is still not very useful
    }

This method can be invoked from any callback provided to the C<new()> function
or from outside the callbacks as long as you have a copy of the
Device::SaleaeLogic object created by C<new()> and a copy of the C<$id> as well.

=item C<is_streaming($id)>

This method informs the user whether the device with ID C<$id> is streaming data
or not. This is useful to know before calling methods like C<read_start()>,
C<write_start()> and C<stop()>. It returns 1 if streaming is going on and 0
otherwise.

The way to invoke this method is as below:

    if ($self->is_streaming($id)) {
        # ... do something ...
        # ... look at the section for read_start() for an example ...
    }

This method can be invoked from any callback provided to the C<new()> function
or from outside the callbacks as long as you have a copy of the
Device::SaleaeLogic object created by C<new()> and a copy of the C<$id> as well.

=item C<get_channel_count($id)>

lib/Device/SaleaeLogic.pm  view on Meta::CPAN

    $self->set_active_channels($id, $channels);

This method can be invoked from any callback provided to the C<new()> function
or from outside the callbacks as long as you have a copy of the
Device::SaleaeLogic object created by C<new()> and a copy of the C<$id> as well.

=item C<read_start($id)>

This method starts the data sampling from the Logic or Logic16 device given by
the ID C<$id>. This should be called only once and to check for whether to call
it or not the user should use C<is_streaming($id)> before that.

The way to invoke this method is as below:

    unless ($self->is_streaming($id)) {
        $self->read_start($id);
    }

This method should B<not> be invoked from any callback provided to the C<new()>
function. It has to be invoked from outside of the callbacks as shown in
F<share/example.pl> in the distribution.

=item C<stop($id)>

This method stops the data streaming that is currently happening for the Logic
or Logic16 device given by the device ID C<$id>. This should be called after
checking with C<is_streaming($id)>. 

The way to invoke this method is as below:

    if ($self->is_streaming($id)) {
        $self->stop($id);
    }

This method can be invoked from any callback provided to the C<new()> function
or from outside the callbacks as long as you have a copy of the
Device::SaleaeLogic object created by C<new()> and a copy of the C<$id> as well.

=item C<write_start($id)>

This method starts the data writing to the Logic device given by

saleaeinterface.cpp  view on Meta::CPAN

        U64 did = saleaeinterface_id_map_get_id(obj->id_map, id);
        GenericInterface *gi = saleaeinterface_map_get(obj->interface_map, did);
        if (gi) {
            LogicAnalyzerInterface *lai = dynamic_cast<LogicAnalyzerInterface *>(gi);
            return lai->IsUsb2pt0() ? 1 : 0;
        }
    }
    return 0;
}

unsigned int saleaeinterface_isstreaming(saleaeinterface_t *obj, unsigned int id)
{
    if (obj) {
        U64 did = saleaeinterface_id_map_get_id(obj->id_map, id);
        GenericInterface *gi = saleaeinterface_map_get(obj->interface_map, did);
        if (gi) {
            LogicAnalyzerInterface *lai = dynamic_cast<LogicAnalyzerInterface *>(gi);
            return lai->IsStreaming() ? 1 : 0;
        }
    }
    return 0;

saleaeinterface.h  view on Meta::CPAN

void saleaeinterface_internal_on_connect(saleaeinterface_t *obj, unsigned int id);
void saleaeinterface_internal_on_disconnect(saleaeinterface_t *obj, unsigned int id);
void saleaeinterface_internal_on_error(saleaeinterface_t *obj, unsigned int id);
void saleaeinterface_internal_on_readdata(saleaeinterface_t *obj, unsigned int id,
                    unsigned char *data, unsigned int len);
void saleaeinterface_internal_on_writedata(saleaeinterface_t *obj, unsigned int id,
                    unsigned char *data, unsigned int len);

unsigned int saleaeinterface_islogic16(saleaeinterface_t *obj, unsigned int id);
unsigned int saleaeinterface_islogic(saleaeinterface_t *obj, unsigned int id);
unsigned int saleaeinterface_isstreaming(saleaeinterface_t *obj, unsigned int id);
unsigned int saleaeinterface_isusb2(saleaeinterface_t *obj, unsigned int id);
unsigned int saleaeinterface_getchannelcount(saleaeinterface_t *obj, unsigned int id);
unsigned int saleaeinterface_getsamplerate(saleaeinterface_t *obj, unsigned int id);
void saleaeinterface_read_start(saleaeinterface_t *obj, unsigned int id);
void saleaeinterface_stop(saleaeinterface_t *obj, unsigned int id);
void saleaeinterface_write_start(saleaeinterface_t *obj, unsigned int id);
/* pass in an array of channel indexes and the number of channels */
void saleaeinterface_setactivechannels(saleaeinterface_t *obj, unsigned int id, unsigned int *channels, unsigned int count);
/* user has to pass in an array of at least 16 elements */
unsigned int saleaeinterface_getactivechannels(saleaeinterface_t *obj, unsigned int id, unsigned int *channels, unsigned int count);

share/example.pl  view on Meta::CPAN

    $arr = $self->get_active_channels($id);
    print "$subname: Active channels: ", join(", ", @$arr), "\n";
    print "$subname: Use 5 Volts: ", $self->get_use5volts($id), "\n";
}

sub on_disconnect {
    my ($self, $id) = @_;
    my $subname = 'on_disconnect';
    print "$subname: Device with id: $id disconnected\n";
    $done = 1;
    if ($self->is_streaming($id)) {
        $self->stop($id);
    }
}
sub on_error {
    my ($self, $id) = @_;
    my $subname = 'on_error';
    print "$subname: Device with id: $id has error\n";
}
sub on_readdata {
    my ($self, $id, $data, $len) = @_;

share/example.pl  view on Meta::CPAN

        $sl->set_sample_rate($g_id, $arr->[0]);
        sleep 1;
        print "$subname: Device sample rate is now: ", $sl->get_sample_rate($g_id), " Hz\n";
        $arr = $sl->get_active_channels($g_id);
        print "$subname: Active channels: ", join(", ", @$arr), "\n";
        print "$subname: Use 5 Volts: ", $sl->get_use5volts($g_id), "\n";
        $once++; # once is 1
    }
    my $t2 = time;
    if ($g_id > 0 and ($t2 - $t1) > 10) {
        unless ($sl->is_streaming($g_id)) {
            if (not $read_once) {
                $sl->read_start($g_id);
                print "Starting Read\n";
            }
        }
        if (($t2 - $t1) > 30) {
            if ($sl->is_streaming($g_id)) {
                $sl->stop($g_id);
                print "Stopping Read\n";
                $t1 = time;
                $read_once++; # read_once is 1
            }
        }
    }
}
print "Done\n";

t/Device-SaleaeLogic.t  view on Meta::CPAN

}
use_ok('Device::SaleaeLogic');

my $sl = new_ok('Device::SaleaeLogic');
can_ok($sl, 'DESTROY');
can_ok($sl, 'begin');
can_ok($sl, 'get_channel_count');
can_ok($sl, 'get_sample_rate');
can_ok($sl, 'set_sample_rate');
can_ok($sl, 'is_usb2');
can_ok($sl, 'is_streaming');
can_ok($sl, 'get_supported_sample_rates');
can_ok($sl, 'is_logic');
can_ok($sl, 'is_logic16');
can_ok($sl, 'get_device_id');
undef $sl;
done_testing();



( run in 0.318 second using v1.01-cache-2.11-cpan-a5abf4f5562 )