LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use Shared memory for clusters?

I am an old hand at LabVIEW, but a newbie to RT.

I have a 7041 RT plug-in board, having 512k of shared memory.

I want to transfer part of my program to the RT board, and use shared memory (rather than TCP, etc.) to communicate (for speed reasons).

My existing code, which works well in the Windows target, needs to move several clusters across the divide between targets.

The existing VIs handle the simple types, and arrays, but no clusters. I could convert my clusters to arrays, but I would lose clarity ("MaxSpeed" is more descriptive than index "16").

When you drill down far enough in the shared-memory VI code, you come to a DLL which has the following interface:
long PeekBlockByName(CStr deviceName unsigned lo
ng offset, char *data, unsigned long size);


Since the PEEK BYTE BY NAME and PEEK LONG BY NAME, etc., all use this same DLL function, I have to believe it's a generic function. Just pass it a pointer and a size, and data gets moved.

I am considering writing a READ and WRITE vi for each of my clusters (3 or 4 different types). Each VI would pass the appropriate arguments to the DLL.

Since my clusters might contain arrays, of variable length, the BYTE OFFSET is not known beforehand. So I would store the first cluster at byte offset 0, the next at byte offset 10,000 or something (way more than necessary), the third at offset 20,000, etc.
Since I have 512k available, the waste is not relevant.

I will of course have to implement my own handshake (the receiver should only perform the read if there is NEW data there, otherwise use the old value).

I will possibly have to include the array size, so the reader knows how many bytes to read.

Any flaws in my thinking?
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 1 of 6
(3,348 Views)
I have attached VIs illustrating how to use the block interface to the dll.
0 Kudos
Message 2 of 6
(3,348 Views)
I'm not sure how what you sent relates to my issue. Those VIs deal with an array of I8, array of DBL, etc., etc. I want to use a cluster of mixed types.

I don't understand the purpose of the RESHAPE ARRAY function - it converts a 1-D array into a 1-D array, what other purpose does it serve here?
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 6
(3,348 Views)
What I sent relates to your issue in that it shows how to use the block functions, about which you inquired.

Reshape array is used to convert an array of size x into an array of size y. Example: [1,1,1] -> reshape array -> [1,1]
0 Kudos
Message 4 of 6
(3,348 Views)
There appears to be no way to make this work, at least with this DLL.

The DLL requires a pointer to data, and does not understand labVIEW data types. Therefore, a cluster of simple types will work, but when an array is put into the cluster, it fails to go across the barrier.

If I flatten the cluster into a string, and tell the CALL LIBRARY node that it's a C STRING POINTER, then it is transferred correctly unless it contains a zero byte. In that case, the string is terminated prematurely. Since my data might contain a zero, that's no good.

Any other ideas, anyone?
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 6
(3,348 Views)
SUCCESS!

For the WRITE function:
1... FLATTEN the cluster to a string. This gets rid of all handles.
2... TYPECAST the string to an array of SGL.
3... Use the RT WRITE SGL ARRAY vi to write into the shared memory.

For the READ function:
1... Use RT READ SGL ARRAY to read the data.
2... TYPECAST the result to a string.
3... UNFLATTEN the string to the cluster type.


This works, even with arrays embedded in the cluster.

I suppose it involves the memory manager on the receiving side, since we create an array. That reduces determinism, but that's not an issue in my case.

Timing works out to 243 uSec for a cluster of 4 DBL + array of 4 DBL (72 bytes all told).

142 uSec for cluster of 4 DBL + empty array (40 bytes)

Those times includ
e the flatten + type cast + write + read + type cast + unflatten. CPU = P4 @ 1500 MHz.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 6 of 6
(3,348 Views)