apeks_okad has asked for the wisdom of the Perl Monks concerning the following question:
I am working on a hardware test automation, The interface to hardware is Automotive Interface 4 (AI4 : USB to SENT) and the H/W manufacturer has provided a C DLL which exports set of functions to communicate with the hardware.
I am trying to import the C DLL via Win32::API module so i can automate the communication via perl.
I have a problem with one API ,KSENT_TX. This function requires a pointer to an array of unsigned char as one of its arguments.
The header file extern declarations(provided by the manufacturer) looks as follows:
MOD_EXTERN unsigned char _stdcall KSENT_TX(unsigned char channel, unsigned char *data, unsigned long cyclic);I have problems passing the right values to this function. Perl.exe crashes every time I try executing my code.
my $Tx = Win32::API::More->new( 'AID.dll', 'KSENT_TX', 'CPN', 'C'); #### $^E is non-Cygwin only die "Error: $^E" if ! $Tx; #### or on Cygwin and non-Cygwin die "Error: ".(Win32::FormatMessage(Win32::GetLastError())) if ! $Tx; my $rettx = $Tx->Call(0, $data_ref, 1);
I tried various methods to pass the array reference
my $data_ref = [0x81 , 0x55, 0x00, 0xE0];or
my @data = (129,85,0,224); my $data_ref = \@data;
also
my $data_ref = pack ('C*', (0x81 , 0x55, 0x00, 0xE0));All of it leads to the same PERL crash. I am a novice to PERL development so maybe I am missing something really basic here. Can you please help me with this problem
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to pass a pointer to an array of 'unsigned char' C data type with Win32::API ("U0")
by tye (Sage) on Jul 27, 2016 at 16:39 UTC | |
by apeks_okad (Novice) on Jul 28, 2016 at 11:08 UTC | |
by syphilis (Archbishop) on Jul 28, 2016 at 14:04 UTC | |
by tye (Sage) on Jul 28, 2016 at 14:07 UTC | |
by apeks_okad (Novice) on Jul 28, 2016 at 15:52 UTC | |
by tye (Sage) on Jul 28, 2016 at 17:21 UTC | |
|