LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help inserting ActiveX Control

We provide an ActiveX control to talk to an instrument. We sell very few of these but nonetheless I've been asked to upgrade the LabVIEW sample (even though it only accounts for 10% of our few sales). I did make a sample a long time ago for labiew 5.1 but was going to make a new one for labview 2011 (as its too difficult to import the sample from 5.1).

 

For testing (and that I'm not releasing any proprietary stuff) I wrote a simple ActiveX control that contains some of the features of the instrument control. This includes going to a particular position, scanning between two positions and receiving events (data, message and status). I was very easily able to write a quick demo in VB6 and C#2010 but I've forgotten everything about labview (except I remember it was relatively complicated for a non-graphical programmer like myself to use an activex control back in the 5.1 days).

 

I would like to make a simple demo (like the one for C#)

  • On a button press it starts a collect, first taking the two values from the appropriate inputs as the range (sets the StartPos and StopPos properties) then calls BeginRun.
  • On another button press it "goes to" a position (calls GoToPos with a parameter from another numeric input).
  • Receives OnStateChanged events and displays the enumerated type in a string indicator. This event is fired when the state is changed (eg. by calling BeginRun).
  • Receives OnData events and displayes the position and value from the event in an indicator. This event is fired during a run for each sample.
  • Receives OnMessage events and displays the message string in an indicator. This event can occur any time - in this sample I'm firing it randomly about once per second and its just sending the time as a string.

Events are asynchronous - calling BeginRun returns immediately but events will follow later.

 

Can anyone help me build this simple example - I've forgotten all the (little) labview I did back in 2003. I've attached the ActiveX control (XTestControl.ocx) a very simple VB6 sample, a better compiled C#2010 sample and my fiddling, far-from-complete LabVIEW 2011 sample. Everything is 32-bit (although I'm running on 64-bit Win7).

 

There's a lot I don't understand about LabVIEW and the time I've already spent on this so far probably means several years ROI for the small company I work for because of the low volumes. 😞

 

TIA

0 Kudos
Message 1 of 8
(3,454 Views)

Hi RAU, since you have the code running in a different environment I can suggest taking a look at this: Calling External Code From LabVIEW.

 

If you really need the code to be built entirely in LabVIEW, then please specify what is the instrument that you are talking to? Are you using a PCI, PXI or a USB device to communicate with it? If that's the case then add the model to the description. It would be great if you can provide a flow chart of the program logic.

Alejandro C. | National Instruments
0 Kudos
Message 2 of 8
(3,435 Views)

I'd be happy to help answer questions, but given how little is in the VI that you provided you're pretty much asking someone to write the whole thing for you.  It would be a good start to add an event structure and all of the buttons you expect to need, and create the callback functions for your events (those will need to be separate VIs; you can right-click on the VI Ref terminal of Register Event Callback to create the VIs automatically, but you'll want to wire the User Parameter first.  ActiveX events are not for LabVIEW beginners.  That said, I've worked with a number of ActiveX components and I've never seen one (unfortunately) that came with a LabVIEW example using events, so congratulations to you and your company for supporting this.  Often vendors provide very basic sample LabVIEW code, and documentation about the events their component provides, apparently assuming that any user who needs to use them will know enough to do so. 

 

Also, if you only have the basic version of LabVIEW, you won't have the event structure, which will make this pretty much impossible.

0 Kudos
Message 3 of 8
(3,428 Views)

Thanks for your reply nathand and taking the time to look at my sample.

 

Yes, it is a very ligh VI because it doesn't have to do much. I want to numeric inputs that set the StartPos and StopPos properties of the ActiveX control and then call the BeginRun method (ie. 3 controls). Data is returned in the OnData event asynchronously and displayed (ie. 1 numeric display). I'me used to programming with the likes of VB and C# where events are a matter of course and you just select the event you want to code for and write the code so all this talk of "separate VIs" and "User Parameter List" is all confusing to me. The VB and C# samples I provided literally took me 15 minutes to write both and I won't tell you how embarrassingly long I spent playing with labview. From memory in (HP) VEE it was relatively easy to make a basic demo using our ActiveX control but we won't be supplying a demo for that this time (or possibly the old demo still works). This is supposed to be such a basic labview sample being provided by the vendor (our small company) as you suggested.

 

I downloaded the 30-day LabVIEW 2011 trial, which I was assuming had proper "event structure" but its counter-intuitive to use.

 

I've modified the attached control slightly (put a Run button on and a CallBack VI thingy) but I don't know how to wire up the run button to do something when clicked nor the event output to the (string) display.

0 Kudos
Message 4 of 8
(3,402 Views)

Turns out I'm completely wrong about needing the event structure, sorry for misleading you... been a while since I used an ActiveX event.  Here's a modified version of your VI that appears to work.  I'm not sure what the string indicator was there for so I removed it.  It could be written somewhat more cleanly with an event structure, but this is simpler for a new LabVIEW user.  You create a queue and pass it a reference to it to the callback VI.  When the callback VI is called, it puts the event data into the queue.  The main loop polls that queue (every 100ms) and when there's new data in it, it displays it to the user.

Download All
Message 5 of 8
(3,400 Views)

Thanks heaps nathan for your quick reply.

 

I have today played with it again and almost been able to connect to an instrument (but that's another, non-related issue).

 

I had the string indicator I had for the status event, which the control may spit out at any time.

0 Kudos
Message 6 of 8
(3,386 Views)

I've still got problems. 😞

 

Apart from the control that actually connects to the instrument not receiving events I also can't seem to register additional events. When I add another Reg Event Callback control and run it I get "Error -2147220990 occurred at Register Event Callback in ControlTest.vi". I wanted to also add the status message event and display the status message in a text output.

0 Kudos
Message 7 of 8
(3,371 Views)

RAU wrote:

Apart from the control that actually connects to the instrument not receiving events I also can't seem to register additional events. When I add another Reg Event Callback control and run it I get "Error -2147220990 occurred at Register Event Callback in ControlTest.vi". I wanted to also add the status message event and display the status message in a text output.


The easiest way to add another event registration is to expand (pull down) the "Reg Event Callback" node to expose an additional event.

0 Kudos
Message 8 of 8
(3,351 Views)