LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use a UI message from a Visual Studio C++ DLL

Using TestStand 4.0, LabVIEW 8.5 and Visual Studio 2003 C++
 
We are developing a test application with a custom LabView user interface. I am using the standard batch process model and in my TestStand sequences I use a number of C++ DLLs to communicate with the boards under test. During the test, communications between the user interface and TestStand are handled with UI messages. Several of my C++ DLLs accomplish lengthy tasks and I would like to be able to communicate status back to the user interface while still in the DLL. I'm using Thread.PostUIMessageEx in my TestStand sequence.
 
Is it possible to generate UI messages in my C++ code and, if so, can anyone point me to an example. BTW I'm no expert at either C++ or TestStand for sure but am usually able to muddle through ok.
 
Thanks,
Steve S.
Message 1 of 21
(4,318 Views)
Steve,

since you told us that you already use UI Messages, the mechanism is not alien to you 🙂

You can do the very same in your C++ code; all you need is the reference to the Thread, which is part of the SequenceContext. So you should pass the ThisContext as SequenceContext to your DLL and then call the PostUIMessageEx-command from the thread-class.
But be aware of possible issues occuring by multithreading...

hope this helps,
Norbert B.
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 21
(4,294 Views)

Norbert,

I am working with steve on this. Right now all of the UImessaging is done via LabVIEW and Teststand this works great. Now what we would like to do is use the ability of UI messages to communicate between LabVIEW and C++. The idea is to post and event in C++ and handle the event in LV. I have found a couple of examples and have shown them to Steve but they are not very clear on the way to do it properly in TS 4.0.

Could you post an example that uses TS 4.0 API to post a UImessage.

 

Thanks,




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 3 of 21
(4,282 Views)
Joe, Steve,

i am not sure if you can accomplish exactly what you like with UI Messages. UI Messages are designed to "tell the UI what to do" from a TestStand Sequence. You can, of course, post UI Messages from codemodules used in your sequence, but still, the UI Message is sent by TS and has to be caught by the UI....

Here is a excerp pseudocode which shows how you can post UI Messages in C(C#)-based codemodules:
int function(SequenceContext ThisContext)
{
Thread ThisThread = ThisContext.thread;
ThisThread.PostUIMessageEx(EventCode, numericDataParam, stringDataParam, activexDataParam, synchronous);
}

SequenceContext and Thread are object from the TS API of course....

hope this helps,
Norbert
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 21
(4,266 Views)
This is exactly what we want to do


i am not sure if you can accomplish exactly what you like with UI Messages. UI Messages are designed to "tell the UI what to do" from a TestStand Sequence. You can, of course, post UI Messages from codemodules used in your sequence, but still, the UI Message is sent by TS and has to be caught by the UI....

Here is a excerp pseudocode which shows how you can post UI Messages in C(C#)-based codemodules:
int function(SequenceContext ThisContext)
{
Thread ThisThread = ThisContext.thread;
ThisThread.PostUIMessageEx(EventCode, numericDataParam, stringDataParam, activexDataParam, synchronous);
}

SequenceContext and Thread are object from the TS API of course....

hope this helps,
Norbert

We want to use a dll code module that is used in a teststand sequence and update the UI with information as the dll is running. So the sequence will go something like this.
 
  1. Run Sequence
  2. call dll as a step in the sequence || Update UI from dll
  3. finish dll
  4. run other steps in the sequence.

The reason that we want to do this is so that when we are running long test the user has some indication that the program has not crashed. Can you point us to tutorials or to some examples that elaborate more on the details of what you said.

 

Thanks,




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 5 of 21
(4,257 Views)

Norbert,

Sorry for the delay. If you're still out there perhaps you can answer another question. I understand the pseudocode however I am having trouble finding the function PostUIMessageEx. Can you (or someone) point me to a source file/DLL and/or proper includes?

Thanks,

Steve S.

Message 6 of 21
(4,222 Views)
Catching UI messages in LabVIEW is possibly, but not very intuitive.

I'd rather choose to use PostLVUserEvent function (exported by LabVIEW.exe).
Using this function, you can catch messages with an event structure. It
takes a user event reference (casted to U32), and a pointer to the data.

However, you'll have to make sure the C code gets a user event reference,
and that the reference stays valied (in memory). A problem in TestExecutive
and TestStand used to be that VI's where closed after execution, and that
would mean all objects in the vi are removed. Guess you have more experiance
with TestStand, so yuo'll figure it out.

Regards,

Wiebe.


0 Kudos
Message 7 of 21
(4,205 Views)

Hi Wiebe,

Thanks for the input - I'll go over the PostLVUserEvent function with Joe - he's our LV expert.  Maybe we can use that method.

As far as the UI messages go, they are a challenge to get working but we're already using them to communicate between a LV user interface and the TestStand sequences. I'd just like to be able to post an async UI message (string) from inside some of my longer-running DLLs to update the user interface. I'm pretty new to C++ and am having trouble finding the UI messaging functions in the teststand files.

Thanks,

Steve S.

0 Kudos
Message 8 of 21
(4,198 Views)
I'd avoid sending a string if possible. If you want to send a status, send
an numeric. At least test with numerics, in general they are a lot easier.

The problem with strings is that you are passing a pointer. This pointer
lives in the memory of the sender, but the receivers wants to read it. The
sender should release the memory, but has no idea about when the reader is
done with it. So strings are very likelly to cause problems here. On the
other hand, there are some windows messages that pass strings, so it might
be handled internally.

Regards,

Wiebe.


0 Kudos
Message 9 of 21
(4,194 Views)

The only problem with using the LVevent is that the dll is called by teststand and not by labview. LV is just used as the UI for teststand so getting a valid reference into teststand will be the tricky part.

Any suggestions,

thanks for the answers wiebe




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 10 of 21
(4,189 Views)