LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

USBXpress : Use SiUSBXp.dll with LabVIEW

Solved!
Go to solution
Solution
Accepted by topic author PV51

Good to hear that it works.

 

The problem is the last parameter to the function. You configured it as a reference to an integer. In reality it is a reference to a much more complicated structure that some Windows APIs use for asynchronous operation. If this parameter is not a NULL pointer value, the function will then return immediately even-though the data transfer hasn't finished and the structure can contain a callback pointer for the underlying function to call when something has changed in the status of the call. Callback pointers are a no-go for direct interfacing with LabVIEW and only possible with a specific wrapper DLL that translates between the callback and something more LabVIEW friendly. Alternatively you can pass in a Windows event handle which will be signaled by the underlying function.

However if you do not want asynchronous operation you are supposed to pass in a NULL pointer here. That means that you need to set the pointer itself to 0, not the first 32 bit integer that pointer is pointing to. The way it is configured, LabVIEW will pass to the function a valid pointer that points to a 32 bit value. The function seeing that it is not a NULL pointer will think that it is an OVERLAPPED data structure and try to interpret it accordingly but only finding garbage in there. If you are lucky you get the observed system error as the function comes to the conclusion that something is truly wrong with it. If you are not so lucky the function will try to reference some data and simply crash. And if you are very unfortunate the function will do its thing thinking it is a valid structure, not crash but somehow corrupt memory anyhow and you end up crashing much later when some other function in LabVIEW tries to reference the now corrupted data.

 

The fix is to change this parameter to be passed by value instead of as a pointer to the value. And since we are at it, you also want to change the data type to be a pointer sized integer, in order to be correct independend if this is loaded in 32-bit or 64-bit LabVIEW. Same for the HANDLE parameter which is also a pointer sized value.

 

If you wanted to do asynchronous operation, things get a magnitude more complicated and I'm refraining from trying to explain the details here. It would be a post that gets several times longer and still only understandable for someone with some serious C programming knowledge.

 

Please feel free to use that driver. I did not work through all the functions but only the ones that are needed to communicate to the controller and some extra functions to query the installed device and its name and properties.

 

I work for an NI Alliance member and system integrator, which specializes in the construction of test and measurement systems for industrial applications. Our test stations are typically used in manufacturing lines for many modern electronic device. You can have a look at the link in my signature to see what kind of things we do at this company.

Rolf Kalbermatter
My Blog
0 Kudos
Message 11 of 11
(597 Views)