LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an Array of Clusters from LabVIEW to a DLL.

Solved!
Go to solution

I can't add padding to the cluster definition because in our data structure it may have utpo 4128 bytes of data.

Data lenght will be decided by the user.

 

When I tried to pass array of U8 as an ARRAY then exception has come.If i change it to U32 array then it will work(single message).But the header bytes will be interchanged.If i pass 2 messages with U32 array the exception has come. 

 

0 Kudos
Message 11 of 43
(3,167 Views)

I think I see the problem here... what is the value of PASSTHRU_MSG_DATA_SIZE?  It is not variable; it is most likely defined in the header file.  If you can have up to 4128 bytes of data, then you need the ucData cluster to be large enough to accomodate that.  You cannot have variable-sized data; each message must have the same data length allocated even if it is not all used.

0 Kudos
Message 12 of 43
(3,159 Views)

Yes PASSTHRU_MSG_DATA_SIZE is defined in header file.Its size is 4128.I a not finding set dimension size option in my version of labview.I am downloading a newer version of labview once its done will check with that and i will post you updates.Thanks for the information.

 

0 Kudos
Message 13 of 43
(3,151 Views)

No need for a new version of LabVIEW.  Inside your for loop, you need to set the "Array to Cluster" function to generate a cluster of PASSTHRU_MSG_DATA_SIZE elements.  I'm not sure why you picked 6 since you tell me that PASSTHRU_MSG_DATA_SIZE is 4128, but that may be your problem.

0 Kudos
Message 14 of 43
(3,145 Views)

But in "Array to cluster" function we can set cluster size upto 256.

0 Kudos
Message 15 of 43
(3,130 Views)

In that case, you could generate a cluster of 129 elements, build that into an array, and then do array to cluster on that with the size set to 32, giving you 32*129=4128 bytes.  The layout in memory will be the same.  Admittedly it's a bit of a pain to work with, but you can generate your data as an array, then typecast it to this enormous cluster of clusters.  Bundle that 4128-byte cluster of clusters into the PASSTHRU_MSG cluster, typecast to a U8 array and pass that to the DLL and it might work.

 

Do you understand why your code isn't working for multiple messages?  As far as I can tell, if your DLL expects that a message will have a total length of 6 (longs) * 4 (bytes/long) + 4128 bytes = 4152 bytes, but each of your messages is only 30 bytes long (as you're doing), then the remaining messages will end up within the extra data space of the first message and the DLL will never see them as separate messages.

0 Kudos
Message 16 of 43
(3,125 Views)

I think i should fix the problem of creating fixed size array and then i will look into multiple messages.

I tried creating array like what u said but doing like that it will end up with array of 32 size.

For second cluster when we fix cluster size to 32 it will build cluster of 32 bytes size not 32*129=4128 bytes.

hence i cant set array size like this.

 

I should be able to set initial array size only that option i dont have in my labview version and when i browse for it

i found that "LabVIEW supports fixed-size arrays in FPGA VIs only. In LabVIEW 7.1 and earlier, you could create a fixed-size array outside of an FPGA VI, if you had the LabVIEW FPGA Module installed."

What is FPGA? below is the link

http://digital.ni.com/public.nsf/allkb/79DFFB71C734771C8625711C0059FA0E

 

Please tell mewhat is FPGA ,i need to istall this to create fixed size array??

 

0 Kudos
Message 17 of 43
(3,088 Views)

The problem with your array of clusters is that the cluster has an array in it.  LabVIEW by default (there's no way to change this) makes that a pointer.  What everyone else is saying to turn it into an array of U8s is correct.

 

Using your pasted typedef, of 6 longs, and an array of PASSTHRU_MSG_DATA_SIZE, you can figure out your data size for one element of the array, I think pulNumMessages is the size of the array you are passing in, your U8 array size should be

 

( pulNumMessages * ( 4 * 6(longs are 32 bits, there are 6 of them) + PASSTHRU_MSG_DATA_SIZE ) )

 

That should get it to stop crashing.

 

 

Once that's done, you will have to convert it back to your data, which may be tricky, but it's not too bad, mostly because it's not crashing every other run.

0 Kudos
Message 18 of 43
(3,081 Views)
Solution
Accepted by topic author 22445466

This image demonstrates what I suggested about using a cluster of clusters to get a fixed-size item of 4128 bytes (32 clusters each containing 129 elements).  Then, swap the bytes and words to get the byte ordering that most Windows DLLs expect, Type Cast to an array of U8, and pass that to the DLL as an array, configured to be passed as an array data pointer.

array of clusters to DLL.PNG

0 Kudos
Message 19 of 43
(3,074 Views)

Thank you very.

It has solved all my problem.Its working fine now.

 

I am facing problem in the below vi.

 

I have 2 structeres like this,

typedef struct

{

unsigned long ulNumOfParams;

SCONFIG *pConfigPtr; // array of SCONFIG

}SCONFIG_LIST;

 

typedef struct

{

J2534_IOCTLPARAMID Parameter;

unsigned long ulValue;

}SCONFIG;

 

I am passing this kind of variable to dll, just check attached vi.

function prototype is 

PassThruIoctl(unsigned long ulChannelID,J2534IOCTLID enumIoctlID,void *pInput,void *pOutput);

 

Her also i am getting same problem.

since SCONFIG_LIST contains array of SCONFIG its taking those parameters as pointers instead of actual values.

I tried like how i was using with previous message but not successful.

 

0 Kudos
Message 20 of 43
(3,059 Views)