LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Event handling using an active x server in Labwindows

Hi,
I have an insturment with which i received an Active X server (ocx. file).
Now using Visual studio .net VB i was able to reference this server and control the instrument.

The way it works is that i give it a command and wait for that command to finsih before telling it to do the next command.
The way it tells me it is finished - is an event is happens. actioniscompleted().

Now, my problem is i am trying to use this Active X server in Labwindows.
I have successfully imported the driver, and i can issue the instrument commands which it does.
But i have no way of telling when the instrument has finished the command.

How do i do events in labwindows?
Example code:
In Visual Basic - 2 functions (one to issue commands the other to handle the event).:
Private Function testplate(ByVal process_step As Short) As String
Select Case process_step
Case 0
comport = 1
AxactiveX.OpenComPort(comport)
AxactiveX.command1()
Case 1
AxactiveX.command2()
End Function

Private Sub AxactiveX_ActionIsCompleted(ByVal sender As Object, ByVal e As AxactiveXLib._DactiveXEvents_ActionIsCompletedEvent) Handles AxactiveX.ActionIsCompleted
process = process + 1
testplate(process)
End Sub

So what i am wondering is, how do i create a function in labwindows to handle the actioniscompleted function in the Active X?

Thansk very much,
Ross
0 Kudos
Message 1 of 6
(3,578 Views)
Hello toil

CVI will generate event registration functions for you that allow you to specify the function callbacks that should fire when an event is raised.

Open up the fp for the ActiveX server that was created for you by CVI and look for an item that says "Event Callback registration functions" or something like that.

I hope this helps
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(3,575 Views)
Hi bilalD,
thanks for the information.
I have not used an ActiveX component before in Labwindows.
Ok, i found the function you were on about:
ActiveXEventsRegOnActionIsCompleted

I filled in the information here (passed in the server object, callback function etc).
Now i have a breakpoint in the call back function but the code(event) never goes into this function. In my code i have :
hresult = BActiveXLib_New_DActiveX (NULL, 1, LOCALE_NEUTRAL, 0, &cviAutoObj);/* Newinstance */
BActiveXLib__DActiveXEventsRegOnActionIsCompleted (cviAutoObj, stacktest, &retVal, 1,&retVal2);

Where i have defined stacktest as a function of the type it tells me to in the .fp window (when i right click on the box).

What am i leaving out/not doing properly?
sorry, not very good description of the problem...

Thanks,
Ross
0 Kudos
Message 3 of 6
(3,568 Views)
First I would recommend initializing COM to STA using the following function

CA_InitActiveXThreadStyleForCurrentThread (0, COINIT_APARTMENTTHREADED);
This should happen before the very first call to any activex function.

Are you sure that the event is actually firing? Have you been able to map the function calls from VB to CVI and verified all other behavior? Is there a property of the same type you could poll to see whether the operation was completed? This way, you could check to see whether the event fired or not.

Hope this helps
Bilal Durrani
NI
0 Kudos
Message 4 of 6
(3,545 Views)
Ok, i put in this initializing the COM to STA function you said to. Now, i dont know what you mean by that (is there somewhere i can read up on this - activeX programming in Labwindows?)

Are you sure the event is firing up?
Not sure what you mean...is the system doing anything when i issue a command, yes the system does what i tell it to. But it never jumps onto the event handle. So, when the system finishes the command, labwindows is not raising this event (I have used this activeX server in VB and it works fine).

Have you been able to map the function calls from VB to CVI and verified all other behavior?
Do you mean have all the functions been transfered over to the .c and .h files of the .fp file, yes i am pretty sure they have - since i am able to issue the commands and the instrument does these commands.

Is there a property of the same type you could poll to see whether the operation was completed?
No, this is kind of my problem. The only way i can see if that an event is raised when the command is complete - there is no busy status i can check 😞


Thanks for the help, any ideas are really appreciated.

Thanks,
Ross
0 Kudos
Message 5 of 6
(3,540 Views)
STA stands for Single Threaded Apartment. This a commonly use ActiveX term that describes how COM library initializes the threads concurrency model. Sometimes, ActiveX components misbehave if the incorrect concurrency model is set because they were not designed for that kind of use. By initializing the COM run time to STA, we basically say that the control was not designed for multi-threaded access. You can find more information about that here.

Can you post a small working example and the activex control you are using so I can test it out here? If you are not comfortable with posting the activex control on a public forum, you can contact our Application's Engineers by going here. This will probably go faster if we could look at some code we could run.

Thanks
Bilal Durrani
NI
0 Kudos
Message 6 of 6
(3,533 Views)