LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PostLVUserEvent and Embarcadero (C Builder)

Well yes there is. It's the Abort() callback function. However you will have to create some extra logic somehow. The configured Abort() function is called by LabVIEW whenever the VI hierarchy that contains a Call Library Node with such a configured function is aborted. But it won't be as easy as just having the Abort(0 function magically do what you intend to do. One way would be to allocate some structure in the Preprare() function, fill in the task name you have created in the Run() function, then delete that task name in the Abort() function if it is still there, and last but not least free all resources in the Unprepare() function.

 

If this explanation is not clear enough then I'm afraid you are trying to play in a league that is at least a class to high.

Rolf Kalbermatter
My Blog
0 Kudos
Message 21 of 30
(946 Views)

Coming back to this topic.

Everything was OK with the 2013 code, but i have now to deal with a new application and a problem arose.

The novelty is that i wish to pass array data with the event ( just like in pure LV),(and not with a callback fonction where i have other problems), and i found now way to do it, exept the one that works in the vi (in which i have replace the array by a cluster of exactly the same binary image. but it would be difficult to do this with a greater array )

In all other tries, either i cannot make a fonctionnal vi, or  i get an error pop window (LV generated, i guess) during execution when firing the event (-> violation access in tdcore_13_0.dll, ....). On OK clic, vi and Borland dll form most of the time  still works, but i get no data.

I have tried all the ways i imagine to configure the dll forth parameter of " OuvreFiche" function (EvntRef_Tab, sequence 1 in the vi), with adequate modifictions on C code. Nothing works.

 

Have you an idea

 

Zip file attachment (  test vi with LV2013, C dll code with embarcadero 2010)

 

The array to pass is on line 96 of OSP_traite.h.

test function to fire event on line 141 of  OSP_traite.cpp

function on line 28.

in the vi ,data acq. sequence 2, condition 6 (TabG)

 

0 Kudos
Message 22 of 30
(854 Views)

Not sure I understand everything you said and looking through your code is hard for me because of the French language and my working with Pascal is more than 20 years ago, but your FireTab() can never going to work if you intend to use arrays. If you want to pass arrays (or strings) to LabVIEW though a user event it has to be in LabVIEW native format. And the LabVIEW native format for these are LabVIEW handles. These handels MUST be allocated, resized and deallocated through LabVIEW memory manager functions or LabVIEW is going to be VERY unhappy about you.

 

But since your Drops structure contains really a fixed size array, you should not convert that into a LabVIEW variable sized array handle but treat it as a cluster with that many elements instead as  you seem to have already found as a possible solution.

Rolf Kalbermatter
My Blog
Message 23 of 30
(843 Views)

Well, first of all great thanks for giving me an answer on sunday, i did'nt expected it so quickly.

 

Next time (if is), i shall take care to write at least all comments in english. Also i don't understand where you saw Pascal, but nether mind.

 

You really understood my problem and your answer reinforces my vision of what i previously guessed => ( it has to be in LabVIEW native format. And the LabVIEW native format for these are LabVIEW handles)

and give me good clues on what i didn't understood. =>"These handels MUST be allocated, resized and deallocated through LabVIEW memory manager functions".

 

So, it is clear and i shall not continue to loose time searching in vain.

 

As i don't feel like being able do deal with memory manager functions in this code, i shall follow your advice and use the " cluster like " solution.

And if it appears that i need to pass more data and use array, i 'll try to do it with a call back function.

 

Thanks one more time

 

0 Kudos
Message 24 of 30
(823 Views)

gosaure wrote:

 

You really understood my problem and your answer reinforces my vision of what i previously guessed => ( it has to be in LabVIEW native format. And the LabVIEW native format for these are LabVIEW handles)

and give me good clues on what i didn't understood. =>"These handels MUST be allocated, resized and deallocated through LabVIEW memory manager functions".

 


Well the functions in question would be DSNewHClr(), DSSetHandleSize(), DSDisposeHandle() and NumericArrayResize() as documented here.

However you have to load them from the current LabVIEW runtime kernel, which can be a bit tricky to determine since it is LabVIEW.exe in the LabVIEW development system and lvrt.dll (and sometimes also other DLL names) in a built application. Also you load PosLVEvent from SendEventToLV.dll, but the real function is PostLVUserEvent() in one of the above DLLs.

Rolf Kalbermatter
My Blog
Message 25 of 30
(805 Views)

Hello

As i have to finish my application, (no more problems with passing data with events but there is still lots of things to do,)

i'm afraid i won't have  time  now to investigate the additionnal information you gave. But it looks interesting and i surely try this next time i get a little "free" time... and probably need of a little help one more time.

 

Thanks and regards

0 Kudos
Message 26 of 30
(805 Views)

I haven't looked at your code and I only briefly read through the messages here, but I wonder if you could pass the array from Embarcadero as a pointer (which would be the normal behavior), then in LabVIEW use MoveBlock to copy the data at that location into a LabVIEW array on a wire? The major problem is there's no easy way to make this work for both 32- and 64-bit operating systems; you'd need slightly different code to deal with the different pointer sizes.

 

Also, I assume you already know that if you need to create a huge cluster of identical elements, a quick way to do it is to wire an empty array to Array to Cluster, set the cluster size to the desired number of elements, and then create a constant, control, or indicator from the output.

0 Kudos
Message 27 of 30
(795 Views)

nathand a écrit :

I haven't looked at your code and I only briefly read through the messages here, but I wonder if you could pass the array from Embarcadero as a pointer (which would be the normal behavior),

>>Well i finally use  a specific dll fonction to pass the arrays (fixed size first created in LV) from C code to LV. the only point is to take care (in LV) to use this precise dll call function in only one place of the LV code, (otherwise LV makes copy of the arrays) and get the pointer adress at first call in the C code.

And take great care with the size of the array in C  too.

My first idea was to pass the array alongside with the event, but Rolk explained me why it was not possible.

So, When the C code as to pass data, it fires a event and the LV code  calls back the dll function in return.

 

then in LabVIEW use MoveBlock to copy the data at that location into a LabVIEW array on a wire? The major problem is there's no easy way to make this work for both 32- and 64-bit operating systems; you'd need slightly different code to deal with the different pointer sizes.

>>I have not this problem now, only 32 bits

 

 

Also, I assume you already know that if you need to create a huge cluster of identical elements, a quick way to do it is to wire an empty array to Array to Cluster, set the cluster size to the desired number of elements, and then create a constant, control, or indicator from the output..

>>I've tried things lke these last week, but from array to cluster, elements have no name and so can't be use as user event in a event structure. 

And from cluster to arrays, you finally get as much entry as elements in array in your event structure, and then should so be unusable with more than a few elements.


 

0 Kudos
Message 28 of 30
(786 Views)

@gosaure wrote:

My first idea was to pass the array alongside with the event, but Rolk explained me why it was not possible.

So, When the C code as to pass data, it fires a event and the LV code  calls back the dll function in return.


Just to make sure no misunderstandings are created here: It definitely is possible but you need to know the exact datatype LabVIEW expects and adhere to all rules that go with this. So while possible it is a major pita and I never spent much time in doing this.

Your solution of using a "callback" to retrieve the data from within an event handler is actually quite a good one.

Rolf Kalbermatter
My Blog
0 Kudos
Message 29 of 30
(771 Views)

@gosaure wrote:

My first idea was to pass the array alongside with the event, but Rolk explained me why it was not possible.

So, When the C code as to pass data, it fires a event and the LV code  calls back the dll function in return.


What Rolf wrote was that it would be difficult to pass the array as a LabVIEW array. You could instead pass it as a C array (as a pointer to the first item in the array). As far as LabVIEW is concerned, the event data would actually be a single U32 (or U64, on a 64-bit platform), which would be the pointer to the first array element. Then you would use MoveBlock to copy the array contents from that pointer into a LabVIEW array. There may be no advantage to this over what you're already doing, if what you have works.

 

If I understand correctly, you are creating an array in LabVIEW, then storing the address of that array in your DLL? This could be dangerous, if LabVIEW decides to move or dispose of that array, not knowing that your DLL is still using it. If this is the case, the MoveBlock approach is safer.

0 Kudos
Message 30 of 30
(764 Views)