PDA

View Full Version : Can I reading a C-Structure data type into PV WAVE



srini_31
12-27-2008, 02:07 PM
I am trying to call a c program from PV Wave and I want to return a structure data type to PV Wave. I am using PV Wave 8.0 on windows.
The programmers manual explicitly says that PV Wave will read only one dimensional arrays. Is there a workaround available in this version 8.0 or in future versions.

Thanks a lot.

donb
12-27-2008, 07:51 PM
What connection method are you using; WAVECMD, SPAWN?

PV-WAVE can transfer data to and from a C program using all supported PV-WAVE data types - including structures. The mechansim used to do this is known as Wave Handles which is part of the Interapplication Communication functionality, specifically available in LINKNLOAD and cwavec.

This has been available for many years on all supported platforms so the version of PV-WAVE your using shouldn't have much bearing on this question.

Cheers, Don B.

srini_31
01-13-2009, 08:14 AM
Hello Don,
I am using OPI(opicwin32.c) to create a PV Wave structure dynamically from C. I have a C Structure of the form

typedef struct {
char *Channelname;
Char *Unit;
double *IndepVec; /*pointer to a double array*/
double *DepVec;
float Min;
float Max;
}test_Struct;

I am storing all the data in the test struct and then calling the function

long opistruct(int argc, void ** argv ) in "opicwin32.c"


This is what happens inside "opistruct"

test_Struct temp_pvwave_ptr, *temp_pvwave_ptr_new;

temp_pvwave_ptr = *(test_Struct*)(argv[1]);


ret = wave_execute( "temppv = {struct_in_c, Channelname :'', Unit :'', IndepVec BLARR(10), DepVec BLARR(10), Min :0.D, Max :0.D} ");

get_wave_var_info( "temppv", &wvi );

ret = wave_wsdh_from_name( "test_in_c", &sdhandle );

if ( sdhandle != wvi.wsdh )
printf(" ***wsdh_from_name != wsdh_from_wvh, %d, %d\n", (int)sdhandle, (int) vi.wsdh);

wave_free_WSDH( &(sdhandle) );

/*Assign the struct*/
ret = wave_get_WVH( "temppv", &wvh );
if ( ret != OPI_SUCCESS )
printf(" ***wave_get_WVH() returned %d\n", ret);

ret = wave_wsdh_from_wvh( wvh, &wsdh );
if ( ret != OPI_SUCCESS )
printf(" ***wave_wsdh_from_wvh() returned %d\n", ret);

ret = wave_assign_struct( wvh, (long)0, (long *)NULL,
wsdh, &temp_pvwave_ptr, (long)1 );

print_wave_struct_value( wvi.wvh, wvi.dataptr );

I am not sure if the IndepVec, DepVec arrays are assigned properly as these are pointers to arrays. I am getting some junk values when I try to print data from these arrays.

But if I print the data from the input pointer to this function, it shows that data properly. Here is the code.

temp_pvwave_ptr_new = (DATKMatlabStruct *)wvi.dataptr;

printf(" temp_pvwave_ptr_new.chname = %s\n, .chunit = %s\n, .indep = %f\n, .min = %f\n, .max = %f\n",
temp_pvwave_ptr_new->Channelname
, temp_pvwave_ptr_new->Unit
, temp_pvwave_ptr_new->IndepVec[0]
, temp_pvwave_ptr_new->Min
, temp_pvwave_ptr_new->Max);


Can I assign an array pointer using assignstruct or is there any other function for that. Am I using the right parameters for the function. In my scenario I have an array of structures that should be passed to PV Wave for further processing. So I need to find a way to get this working.

Also can I create an PV Wave array dynamically using a variable value as the array size given below.
---------------------------------------
#define array_size 100

ret = wave_execute( "temppv = {struct_in_c, Channelname :'', Unit :'', IndepVec BLARR(array_size), DepVec BLARR(10), Min :0.D, Max :0.D} ");
---------------------------------------

Please let me know if you need any more details.
I would really appreciate your help.

- Srini.

srini_31
01-13-2009, 08:15 AM
Any updates on this issue please, Can someone let me know how wave_assign_struct works. Does the C structure need to have tags like
int array[LEN];
instead of
int *array;



Thanks,
Srini.

rwagner
01-28-2009, 12:36 PM
Hi Srini,
Just as a follow up to our phone conversation I'd like to point you in the direction of some code examples. As I mentioned there are two parts to a program that passes nested structures from C into WAVE: C code and WAVE code.

For the C code, consider the file I emailed to you: deconstruct.c

For the WAVE code, please look at the following files in your 9.0 distribution:
C:\VNI\stat-6_0\lib\mlf_network.pro
C:\VNI\stat-6_0\lib\mlff_pack_newtwork_structure.pro

You can see that the C code takes a nested structure and returns (by reference) all the parts of the structure independently to mlff_network.pro. mlff_network then passes all the parts into pack_structure which returns a nested structure.

-Ryan