in reply to Win32::API cant define function

The reference to the integer is actually the reference to the first integer in an integer array, with the subsequent 3 array values also being used to store analogue results.

For functions that require blocks of memory, use a string of the appropriate size.

my $read_inputs = Win32::API->new("wsp", "ReadInputs", "P", "I"); sub ReadInputs { my $buf = "\x00" x (4 * 32/8); my $rv = $read_inputs->Call($buf); return ($rv, unpack('l4', $buf)); }

Update: Fixed name of function. Changed "->()" to "->Call()"

Replies are listed 'Best First'.
Re^2: Win32::API cant define function
by BarneySimpson (Initiate) on Mar 29, 2010 at 00:51 UTC

    Thank you for your feed back but I still can not get it to work. I am kind of a nubie when it comes to Perl. The function that reads in is actually called ReadInputs not SetOutputs but I guess that was just a typo.

    I have pasted the code I am trying to get to work below. The code is suppost to print out what ReadInputs has read every second. The error that I am getting in command prompt is "Not a Code reference at line 20" and it's talking about "my $rv = $read_inputs->($buf);"

    use strict; use Win32::API; Win32::API->Import("wsp", "int InitWasp()"); my $read_inputs = Win32::API->new("wsp", "ReadInputs", "P", "I"); InitWasp(); #connect to WASP USB board #constant input read in # while(1){ print ReadInputs()."\n"; sleep(1); } #Subroutines # sub ReadInputs{ my $buf = "\x00" x (4 * 32/8); my $rv = $read_inputs->($buf); return ($rv, unpack('l4', $buf)); }

      Try:

      my $rv = $read_inputs->Call ($buf);

      Oh, and note that ReadInputs returns a list of values so print will print them concatenated together without any white space. You could:

      my @values = ReadInputs(); print "@values\n";

      to at least get a space between each value. Note that the first value is the 'bool' result of the call and that the following values are the ADC input values.


      True laziness is hard work