LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

COM/ActiveX Register Event Callback Problem

Hi Everyone,

 

 

I’m trying to develop a VI to control a programmable USB device (USBPGF-S1 USB Programmable Amplifier and Low-Pass Filter from Alligator Technologies). Alligator provided me with a dll file “USBPxxS1COM.dll” which can manage the USB device with two events (DeviceConnected and DeviceDisconnected) and one command (to control the parameters of the device). This is what I want to do: setting the parameteres of the device with a LabVIEW program.

 

In the attached VI (AlligatorMain.vi), you may see that I tried to communicate with the device using “Reg Event Callback” to handle the ActiveX events. Basically, I need to get a “handle” from the connection, and use it in the Invoke Node to write/read some values from the USB device. I have a few problems, and I was wondering if you could help me with them.

 

1. As I run the VI, nothing happens inside the Callback VI ("AlligatorCallback.vi"). At first, I thought LabVIEW doesn’t register the events from the device, but when I looked at one of NI’s examples, the same situation exists. For instance, when I run “ActiveX Event Callback for Excel VI: labview\examples\comm\axevent.llb”, I can see everything goes as the description, but nothing happens inside the NewWorkbookCallback.vi. I don’t know how to access the data inside the event. How do I extract info about the event and use it in the main VI ((AlligatorMain.vi")?

 

2. The dll that I mentioned before has a command for controlling the parameters of the USB device. This command has four arguments (Handle, CmdID, DataInPtr, DataOutPtr). Handle is an integer that is for the device connection. CmdID is an integer to read/write a variable on the device (e.g. to read the value of LPFc, CmdID=1). DataInPtr and DataOutPtr are pointers to a structure (cluster) of data that contains all the variables of the USB device (e.g. LPF, Gain, etc.). Question: How do I read from pointers in LabVIEW?

This is how this command is defined by Alligator Technologies:

USBPxxS1Command([in] LONG Handle, [in] LONG CmdID, [in] VARIANT* DataInPtr, [in] VARIANT* DataOutPtr);

 

 

Thank you very much,

Rooz

 

Alligator01.png

 

Alligator02.png

0 Kudos
Message 1 of 22
(4,464 Views)

See this thread: http://forums.ni.com/t5/LabVIEW/How-to-interaction-with-Main-VI-from-Net-event-callback

There are examples that show how to use a queue or a user event to pass data from a callback to the main VI. (Note that I posted the right images but the wrong VIs for the user event example; someone else posted corrected ones further down the thread.)

 

EDIT: Forgot to comment on the second half of your question. I have no idea how you would do anything with an input-only variant pointer. Is there any more documentation explaining what it's pointing at? Without knowing how much space should be allocated for the pointer, nor who is responsible for allocating it, I'm not sure what you can do.

0 Kudos
Message 2 of 22
(4,433 Views)

Hi Nathan,

 

Thank you very much for your help.  User Event and Event Structure seem very helpful.  I will try those.

As for the variant pointer, I know it points to a data structure (written in C++) in the form of the following:

 

Alligator03.png

0 Kudos
Message 3 of 22
(4,392 Views)

@Rooz wrote:

Hi Nathan,

 

Thank you very much for your help.  User Event and Event Structure seem very helpful.  I will try those.

As for the variant pointer, I know it points to a data structure (written in C++) in the form of the following:

 

Alligator03.png


From my reading of TestClientDIalog.h, Descritipn comes between ChannelNumber and LPFilterType.

 

Also, before you doing anything else, you need to send a CmdID of 0 to Initialize.

 

 

 

0 Kudos
Message 4 of 22
(4,379 Views)

You could certainly try allocating memory for a struct of that size and passing a pointer to it to the ActiveX node, but I have no idea if it will work. I'm not sure that ActiveX calls share the same address space with their callers, nor how the Cstring parameter will work. I'd try allocating the Cstring as a pointer-sized integer but wouldn't be surprised if it causes your code to crash (save often). To allocate memory, use Call Library Function Node with the library name set to "LabVIEW" and the function set to DSNewPtr, which is described in the help and also in posts on this forum. If you need to pre-fill values into the allocated memory, then you should create a matching cluster and use MoveBlock. After the ActiveX call completes, use MoveBlock again to get the data into a format LabVIEW can use. There are examples of this on this forum, although they generally deal with a call to a DLL and not ActiveX.

 

It's worth a try but may not work. If you do try it and fail, upload your code, along with a specific description of the error that occurs. Do you have any more documentation about the functions you're trying to call? Can you upload the manual? Do they provide sample code in any language?

0 Kudos
Message 5 of 22
(4,372 Views)

@nathand wrote:

You could certainly try allocating memory for a struct of that size and passing a pointer to it to the ActiveX node, but I have no idea if it will work. I'm not sure that ActiveX calls share the same address space with their callers, nor how the Cstring parameter will work. I'd try allocating the Cstring as a pointer-sized integer but wouldn't be surprised if it causes your code to crash (save often). To allocate memory, use Call Library Function Node with the library name set to "LabVIEW" and the function set to DSNewPtr, which is described in the help and also in posts on this forum. If you need to pre-fill values into the allocated memory, then you should create a matching cluster and use MoveBlock. After the ActiveX call completes, use MoveBlock again to get the data into a format LabVIEW can use. There are examples of this on this forum, although they generally deal with a call to a DLL and not ActiveX.

 

It's worth a try but may not work. If you do try it and fail, upload your code, along with a specific description of the error that occurs. Do you have any more documentation about the functions you're trying to call? Can you upload the manual? Do they provide sample code in any language?


The only example code they provide is a Visual Studio 2010 C++ example.

 

The Description length in the structure which may be able to ibe implemented as a LabVIEW cluster appears to have a maximum length of 30 characters.

 

 

0 Kudos
Message 6 of 22
(4,369 Views)

@nyc_(is_out_of_here) wrote:

The only example code they provide is a Visual Studio 2010 C++ example.

 

The Description length in the structure which may be able to ibe implemented as a LabVIEW cluster appears to have a maximum length of 30 characters.


Visual C++ is fine. Even if there's a maximum length for the description, there's still a question of who allocates it, and it still needs to be a pointer in the Variant structure. The question is whether LabVIEW allocates the destination of that pointer, or whether the ActiveX call handles that allocation and fills in the pointer value. Example code might help explain this.

0 Kudos
Message 7 of 22
(4,365 Views)

@nathand wrote:

@nyc_(is_out_of_here) wrote:

The only example code they provide is a Visual Studio 2010 C++ example.

 

The Description length in the structure which may be able to ibe implemented as a LabVIEW cluster appears to have a maximum length of 30 characters.


Visual C++ is fine. Even if there's a maximum length for the description, there's still a question of who allocates it, and it still needs to be a pointer in the Variant structure. The question is whether LabVIEW allocates the destination of that pointer, or whether the ActiveX call handles that allocation and fills in the pointer value. Example code might help explain this.


The example code can be downloaded from their website.

0 Kudos
Message 8 of 22
(4,363 Views)

@nyc_(is_out_of_here) wrote:

The example code can be downloaded from their website.


I only see a "Setup.exe" so I assume the sample code is part of their installer, and I try not to muck up my machine with random software installs that I don't actually need.

0 Kudos
Message 9 of 22
(4,359 Views)

@nathand wrote:

@nyc_(is_out_of_here) wrote:

The example code can be downloaded from their website.


I only see a "Setup.exe" so I assume the sample code is part of their installer, and I try not to muck up my machine with random software installs that I don't actually need.


Yes, but I just un-installed it. It is not a "heavy" program.

0 Kudos
Message 10 of 22
(4,356 Views)