From 81053ca6108f03213abeffb60cbb64377ce7509f Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Tue, 29 Jan 2013 14:37:29 -0500 Subject: more named parameters --- libvxi11client/perlbits/Client.pm | 99 +++++++++++++++++++++++++++++----- libvxi11client/perlbits/Client.xs | 14 ++--- libvxi11client/perlbits/VXI11-Client.t | 16 +++--- libvxi11client/perlbits/testscript.pl | 14 ++--- 4 files changed, 109 insertions(+), 34 deletions(-) (limited to 'libvxi11client/perlbits') diff --git a/libvxi11client/perlbits/Client.pm b/libvxi11client/perlbits/Client.pm index f4c76a4..a5c5164 100644 --- a/libvxi11client/perlbits/Client.pm +++ b/libvxi11client/perlbits/Client.pm @@ -35,38 +35,102 @@ XSLoader::load('VXI11::Client', $VERSION); # Preloaded methods go here. + sub vxi_enable_srq { return vxi_enable_srq_long($_[0], 1, $_[1]); } + sub vxi_disable_srq { return vxi_enable_srq_long($_[0], 0 , ""); } + +sub vxi_clear { + my $self = shift; + my %args = ( + waitforlock => 0, + @_ + ); + return vxi_clear_long ($self, $args{waitforlock}); +} + + +sub vxi_local { + my $self = shift; + my %args = ( + waitforlock => 0, + @_ + ); + return vxi_local_long ($self, $args{waitforlock}); +} + + +sub vxi_remote { + my $self = shift; + my %args = ( + waitforlock => 0, + @_ + ); + return vxi_remote_long ($self, $args{waitforlock}); +} + + +sub vxi_trigger { + my $self = shift; + my %args = ( + waitforlock => 0, + @_ + ); + return vxi_trigger_long ($self, $args{waitforlock}); +} + + +sub vxi_lock { + my $self = shift; + my %args = ( + waitforlock => 0, + @_ + ); + return vxi_lock_long ($self, $args{waitforlock}); +} + + +sub vxi_open { + my %args = ( + address => '127.0.0.1', + device => 0, + @_ + ); + return vxi_open_long ($args{address}, $args{device}); +} + + sub vxi_write { my $self = shift; my $data = shift; my %args = ( len => -1, - waitlock => 0, + waitforlock => 0, end => 1, @_ ); - return vxi_write_long($self, $data, $args{len}, $args{waitlock}, $args{end}); + return vxi_write_long($self, $data, $args{len}, $args{waitforlock}, $args{end}); } + sub vxi_read { my $self = shift; my %args = ( bufferlen => 1024, - waitlock => 0, + waitforlock => 0, termchrset => 0, termchr => 0, autochomp => 1, @_ ); - my ($bytes, $string, $reason) = vxi_read_long($self, $args{bufferlen}, $args{waitlock}, $args{termchrset},$args{termchr}); + my ($bytes, $string, $reason) = vxi_read_long($self, $args{bufferlen}, $args{waitforlock}, $args{termchrset},$args{termchr}); if (defined($string) && $args{autochomp}) { chomp ($string); @@ -75,6 +139,17 @@ sub vxi_read { return ($bytes, $string, $reason); } + +sub vxi_readstatusbyte { + my $self = shift; + my %args = ( + waitforlock => 0, + @_ + ); + return vxi_readstatusbyte_long ($self, $args{waitforlock}); +} + + sub vxi_docmd { my $self = shift; my $cmd = shift; @@ -82,12 +157,12 @@ sub vxi_docmd { datain => "", datainlen => -1, dataoutbufferlen => 256, - waitlock => 0, + waitforlock => 0, autochomp => 1, @_ ); - my ($ret, $dataout, $dataoutlen) = vxi_docmd_long($self, $args{datain}, $args{datainlen}, $args{dataoutbufferlen}, $args{waitlock}); + my ($ret, $dataout, $dataoutlen) = vxi_docmd_long($self, $args{datain}, $args{datainlen}, $args{dataoutbufferlen}, $args{waitforlock}); if (defined($dataout) && $args{autochomp}) { chomp ($dataout); @@ -110,9 +185,9 @@ VXI11::Client - Perl extension for interfacing with VXI-11 networked instruments vxi_startinterruptserver(); - my $instr = vxi_open("192.168.0.62", 0); + my $instr = vxi_open(address => "192.168.0.62"); - $instr->vxi_lock(0); + $instr->vxi_lock(); $instr->vxi_write("*idn?"); my ($bytes, $buff, $reason) = $instr->vxi_read(); print "got " . $bytes . ";" . $buff . " reason " . $reason ."\n"; @@ -126,10 +201,10 @@ VXI11::Client - Perl extension for interfacing with VXI-11 networked instruments $instr->vxi_disable_srq(); $instr->vxi_destroy_intr_chan(); $instr->vxi_abort(); - $instr->vxi_clear(0); - $instr->vxi_trigger(0); - $instr->vxi_local(0); - $instr->vxi_remote(0); + $instr->vxi_clear(); + $instr->vxi_trigger(); + $instr->vxi_local(); + $instr->vxi_remote(); $instr->vxi_unlock(); $instr->vxi_close(); diff --git a/libvxi11client/perlbits/Client.xs b/libvxi11client/perlbits/Client.xs index 48571d9..d84482e 100644 --- a/libvxi11client/perlbits/Client.xs +++ b/libvxi11client/perlbits/Client.xs @@ -35,7 +35,7 @@ vxi_abort(context) RETVAL int -vxi_clear(context,waitforlock = 0) +vxi_clear_long(context,waitforlock) VXI11::Client context bool waitforlock CODE: @@ -101,7 +101,7 @@ vxi_wait_for_interrupt() int -vxi_local(context, waitforlock = 0) +vxi_local_long(context, waitforlock) VXI11::Client context bool waitforlock CODE: @@ -110,7 +110,7 @@ vxi_local(context, waitforlock = 0) RETVAL int -vxi_lock(context, waitforlock = 0) +vxi_lock_long(context, waitforlock) VXI11::Client context bool waitforlock CODE: @@ -119,7 +119,7 @@ vxi_lock(context, waitforlock = 0) RETVAL VXI11::Client -vxi_open(address, device) +vxi_open_long(address, device) char * address char * device CODE: @@ -142,7 +142,7 @@ vxi_read_long(context, OUTLIST bytesread, OUTLIST buffer, bufferlen, waitlock, t bytesread = vxi11_read(context, buffer, bufferlen, waitlock, termchrset, termchr, &reason); void -vxi_readstatusbyte(context, OUTLIST error, OUTLIST statusbyte, waitforlock) +vxi_readstatusbyte_long(context, OUTLIST error, OUTLIST statusbyte, waitforlock) VXI11::Client context int error int statusbyte @@ -157,7 +157,7 @@ vxi_readstatusbyte(context, OUTLIST error, OUTLIST statusbyte, waitforlock) error = ret; int -vxi_remote(context, waitforlock = 0) +vxi_remote_long(context, waitforlock) VXI11::Client context bool waitforlock CODE: @@ -166,7 +166,7 @@ vxi_remote(context, waitforlock = 0) RETVAL int -vxi_trigger(context, waitforlock = 0) +vxi_trigger_long(context, waitforlock) VXI11::Client context bool waitforlock CODE: diff --git a/libvxi11client/perlbits/VXI11-Client.t b/libvxi11client/perlbits/VXI11-Client.t index bbb6f3b..331337a 100644 --- a/libvxi11client/perlbits/VXI11-Client.t +++ b/libvxi11client/perlbits/VXI11-Client.t @@ -16,24 +16,24 @@ BEGIN { use_ok('VXI11::Client') }; # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. -&VXI11::Client::vxi_startinterruptserver(); +vxi_startinterruptserver(); -my $address = "192.168.0.62"; -my $instr = &VXI11::Client::vxi_open($address, 0); +my $ip_addr = "192.168.0.62"; +my $instr = vxi_open(address => $ip_addr); -is($instr->vxi_lock(0), 1, "Lock"); +is($instr->vxi_lock(), 1, "Lock"); ok($instr->vxi_write("*idn?") > 0, "Write"); my ($bytes, $buff, $reason) = $instr->vxi_read(); print "got " . $bytes . ";" . $buff . "\n"; ok($bytes > 0, "Read"); -my ($error, $statusbyte) = $instr->vxi_readstatusbyte(0); +my ($error, $statusbyte) = $instr->vxi_readstatusbyte(); is($error,0, "Read status byte"); is($instr->vxi_create_intr_chan(), 1, "Create intr channel"); is($instr->vxi_enable_srq("myhandle"), 1, "Enable interrupts"); -#is(&VXI11::Client::vxi_wait_for_interrupt, "myhandle", "Wait for interrupt"); +#is(vxi_wait_for_interrupt, "myhandle", "Wait for interrupt"); is($instr->vxi_disable_srq(), 1, "Disable interrupts"); is($instr->vxi_destroy_intr_chan(), 1, "Destroy intr channel"); is($instr->vxi_abort(), 1, "Abort"); @@ -41,10 +41,10 @@ is($instr->vxi_clear(), 1, "Clear"); is($instr->vxi_trigger(), -8, "Trigger"); #Not supported by the bb is($instr->vxi_local(), 1, "Local"); is($instr->vxi_remote(), 1, "Remote"); -my ($ret, $dataout, $dataoutlen) = $instr->vxi_docmd(1); +my ($ret, $dataout, $dataoutlen) = $instr->vxi_docmd(""); ok($ret < 1, "docmd"); #this should fail on the bb server is($instr->vxi_unlock(), 1, "Unlock"); is($instr->vxi_close(), 1, "Close"); -&VXI11::Client::vxi_stopinterruptserver(); +vxi_stopinterruptserver(); diff --git a/libvxi11client/perlbits/testscript.pl b/libvxi11client/perlbits/testscript.pl index ac7dd3f..b564977 100755 --- a/libvxi11client/perlbits/testscript.pl +++ b/libvxi11client/perlbits/testscript.pl @@ -7,14 +7,14 @@ use VXI11::Client; vxi_startinterruptserver(); -my $instr = vxi_open("roi", 0); +my $instr = vxi_open("myipaddr"); -$instr->vxi_lock(0); +$instr->vxi_lock(); $instr->vxi_write("*idn?"); my ($bytes, $buff, $reason) = $instr->vxi_read(); print "got " . $bytes . ";" . $buff . " reason " . $reason ."\n"; -my ($error, $statusbyte) = $instr->vxi_readstatusbyte(0); +my ($error, $statusbyte) = $instr->vxi_readstatusbyte(); printf "status byte is " . $statusbyte . "\n"; $instr->vxi_create_intr_chan(); @@ -26,10 +26,10 @@ for (my $i = 0; $i < 10000; $i++) { $instr->vxi_disable_srq(); $instr->vxi_destroy_intr_chan(); $instr->vxi_abort(); -$instr->vxi_clear(0); -$instr->vxi_trigger(0); -$instr->vxi_local(0); -$instr->vxi_remote(0); +$instr->vxi_clear(); +$instr->vxi_trigger(); +$instr->vxi_local(); +$instr->vxi_remote(); $instr->vxi_unlock(); $instr->vxi_close(); -- cgit