LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a C Struct from a LV CallLibrary Function.

Thanks nathand.

 

Now the function call CMA_GetVersion is working. But the other function CMA_InstallPDO_E still throws a fault. Herewith Im attaching the debugging of dll's snapshot for reference with COBID of 202,  as you can see the COBID entry is garbled. Could you please look into it and clarify where the code is went wrong?

 

Thanks

 

Kousy

0 Kudos
Message 11 of 36
(1,014 Views)

ucaDefVal is defined as an array of 8 char values, and you are passing in an array of 9 elements.

0 Kudos
Message 12 of 36
(1,008 Views)

@smercurio_fc wrote:

ucaDefVal is defined as an array of 8 char values, and you are passing in an array of 9 elements.


I'm certain that this is not the problem.  LabVIEW will pass a native array by pointer, so the number of elements in it is irrelevant.  The C struct defines a fixed-size array and it is being passed by value.  Using a LabVIEW array is not an option at all, regardless of the number of elements in it.

0 Kudos
Message 13 of 36
(1,000 Views)

I've got to stop jumping back and forth between LabVIEW, Excel, Matlab, C#, C, etc.. My brain is officially liquified this morning.

0 Kudos
Message 14 of 36
(994 Views)

Kousy wrote:

Now the function call CMA_GetVersion is working. But the other function CMA_InstallPDO_E still throws a fault. Herewith Im attaching the debugging of dll's snapshot for reference with COBID of 202,  as you can see the COBID entry is garbled. Could you please look into it and clarify where the code is went wrong?


It looks to me like you need to pass an additional 3 bytes of padding between ucPDOType and ulCOBID to maintain alignment.  This would be necessary if you were passing the cluster by reference so I wouldn't be surprised if it's required for passing by value as well.  The reason is that in C at least, a long needs to be aligned on a 4-byte boundary, whereas LabVIEW always packs structures as tightly as possible.  The first value in the cluster, ucPDOType, will be properly aligned because it starts the structure.  Another 3 bytes are then necessary to reach the next 4-byte boundary on which the unsigned long ulCOBID can start.  You can just add two dummy parameters - a U8 and a U16 - and pass null values to them.

 

You also need to pass 8 separate U8 (char) values for ucaDefVal (again, due to passing by value) instead of passing an array by reference.

0 Kudos
Message 15 of 36
(979 Views)

Nathand !

 

Thanks for your continued support. We have tried all methods as suggested and still the CMA_Install PDO_E throws the same fault. While reading the device manual this is what it says about calling functions from Labview :

 

The parameter structures must be defined as arrays and need

to be evaluated by bytes. The array size must fit or exceed the

size of the parameter structure. Otherwise, access violations

during operation may occur.

 

Does this throw any additonal light on the problem ??

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 16 of 36
(970 Views)

I'm not sure exactly what you tried, so I'm posting what I'm pretty sure it should look like:

 

CMA_InstallPDO_E.png

 

Note the addition of 4 bytes of padding: 3 bytes (one U8 and one U16) before ulCOBID, and 1 byte before usEventTimer.  The snippet creation seems to mess up cluster images; the ucaDefVal cluster is of course 8 U8 elements.

If this is what you already tried, and you're still getting an error, please specify exactly what the error is and whether it's an error from LabVIEW or from your DLL.  Also, in the Call Library Node, try setting debugging to maximum.

 

Are you and Kousy working on the same team, or just coincidentally trying to use the same DLL at the same time?

0 Kudos
Message 17 of 36
(943 Views)

Nathan,

 

Don't use the snippeet creator built into LabVIEW.  Download the Code Capture Tool.  It works much better.  It also doesn't break property nodes the way the LabVIEW version does.

 

Community nugget: Code Capture Tool 2.0

 

0 Kudos
Message 18 of 36
(940 Views)

Nathand,

 

Tried as you suggested. Its not working out. And Im getting the same dll error.


Just to make matter simple we are trying another functionality called ConfigSyncMan. We tried to send the syncID(0x80) as simple U32 datatype as well as in both endian formats , neither worked out.

 

Raghunathan and self are working on the same project.

 

What else can I try?

 

Thanks.

 

Kousy

0 Kudos
Message 19 of 36
(924 Views)

@Kousy wrote:

 

Tried as you suggested. Its not working out. And Im getting the same dll error.


Could you be more specific - is the error that you're getting a LabVIEW error, or an error from the DLL?  If from LabVIEW, is it 1097 or something else?  If from the DLL, consult the DLL documentation for the meaning of the error code - I can't help debug that.

 

If you run the Install_PDO_E call exactly as I suggested and then watch the call in the debugger, like the screenshot you posted, do the right values go to the right places?

 

What is the prototype of the ConfigSyncMan function?  If this is another case of passing a struct by value, then you probably need two bytes of padding to align ulSyncID.  There is no need to flatten and unflatten your parameters - LabVIEW will take care of the endianness.

0 Kudos
Message 20 of 36
(909 Views)