07-28-2011 06:27 AM
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
07-28-2011 08:20 AM
ucaDefVal is defined as an array of 8 char values, and you are passing in an array of 9 elements.
07-28-2011 10:52 AM
@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.
07-28-2011 11:20 AM
I've got to stop jumping back and forth between LabVIEW, Excel, Matlab, C#, C, etc.. My brain is officially liquified this morning.
07-29-2011 03:25 PM
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.
07-30-2011 07:14 AM
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 ??
07-31-2011 09:14 PM
I'm not sure exactly what you tried, so I'm posting what I'm pretty sure it should look like:
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?
07-31-2011 09:37 PM - edited 07-31-2011 09:41 PM
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.
08-01-2011 05:41 AM
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
08-01-2011 11:33 AM
@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.