LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the right function in Call Library Function Node

I am trying to communicate with a Picoscope 4262 from Picotechnology.  An SDK is available, which includes a dll with various functions to communicate with the scope.  These functions can be called using Call Library Function Node.  After selecting the library name, I am presented with a list of function names to select from.  Each function name seems to have two versions:  "Name" and "Name-2".  For example, there is the function "ps4000OpenUnitEx" and "ps4000OpenUnitEx-2".  I do not know what the difference between these two sets of functions is, and I'm not sure whether it is a LabVIEW issue that I can get help for here or if it is specific to the Picotechnology dll and I have to consult them. 

I have attached screen clips of the Call Library Function for both cases.  In the first case, the function prototype is "uint32_t _ps4000OpenUnitEx@8(int16_t *handle, CStr serial);" versus "uint32_t _ps4000OpenUnitEx(int16_t *handle, CStr serial);" for the second case.  There is an additional "@8" in the first case.  I'm wondering if this has something to do with compiler name mangling, which is something that I don't know much about.

Any insight on what the difference is between these two sets of functions and how to know which to use would be great!

cbfsystems_0-1664410782615.png

cbfsystems_1-1664410828917.png

 

 

0 Kudos
Message 1 of 10
(1,941 Views)

 

I hesitate to respond, but out of kindness for another human being I do.

 

PicoScope and LabVIEW is a mess.  (Their old vis don't work, now, incidentally.)  I had to figure it out, and I finally did -- NI helped, some -- Pico, not so much.  Their (OEM) software is intended for use with C or other, not LabVIEW.  It can be done, though.  Take a look into LabVIEW's memory manager functions; that's the key, or at least that's what got me going.  I needed pointers that worked, and that got me there.  The functions are the workalikes of the C malloc operations.

 

I am now able to do what I wanted to do.  But it wasn't a cakewalk.

 

 

0 Kudos
Message 2 of 10
(1,914 Views)

One other thing

 

It would appear that their PicoScope6 (or 7?) is based on their API and that if it, whatever it is, can be done there that you can do it via the dll and API functions.  I think I still agree with that.

0 Kudos
Message 3 of 10
(1,907 Views)

The DLL interface was designed by Microsoft around the premise that C programmers can use it to call functions located in external libraries to their own code. Nothing less and nothing more. LabVIEW provides the Call Library Node to access them but can’t change the fact that you need to know everything that a C programmer would need to know to call this DLL and even a little more.

 

That means that you need to know how to program in C to call that DLL, what functions a DLL exports, the signature (parameters and their types) each function has and any extras such as memory management requirements for any non scalar parameter. Aside from some solid C programming knowledge you do therefore need a documentation for the functions in that DLL that explains all these things and you need to be able to understand it. Otherwise starting to try to create VIs to call a DLL is in the best case guesswork that results in a VI interface library that may after much heartache eventually seem to work (not crash anymore) but still be very far from being reliable and not crash under different conditions and/or cause corrupted values in your application.

 

Picoscope used to provide a LabVIEW library for their DLL in the past. The programmer of that library obviously had access to the library documentation but they had absolutely no idea about what proper memory management would mean in a multithreaded environment such as what LabVIEW is. They assumed that LabVIEW only runs single threaded and totally unmanaged except that they didn’t care about allocating their memory buffers as would be necessary in an unmanaged environment but used LabVIEW managed memory buffers like they were theirs anyways. It only could work in trivial example applications that executed everything in a single diagram, thanks to LabVIEWs lazy memory deallocation for performance reason.

Rolf Kalbermatter
My Blog
Message 4 of 10
(1,879 Views)

What you said resonates with me.  It sounds like we have had a similar experience with the code for the Picoscopes.  It does seem like a bit of a "mess", but I mostly have it doing what I want.  I have used the LabVIEW memory manager functions to transfer the data between the dll code and LabVIEW.  Even though my code seems to be working, I have the sense that I don't completely understand what I am doing such as with the case of "ps4000OpenUnitEx" and "ps4000OpenUnitEx-2".

0 Kudos
Message 5 of 10
(1,834 Views)

I hear what you are saying, Rolf.  I have done some C programming in the past (not a lot), have the PicoScope 4000 Serious Programmers Guide, and have worked with the PicoScopes before, so I'm aware of many of the issues that you mentioned, including at least some of the memory management issues that your raised (I have used LabVIEWs memory management functions to do scope acquisitions where my code was split across multiple block diagrams).  Accessing the Picoscope through the dll is not simple.  I seem to have it mostly working, but I'm wondering what the purpose is of the two sets of similar functions in the dll is though.  I haven't found anything about this in the Picoscope documentation.

0 Kudos
Message 6 of 10
(1,825 Views)

@cbfsystems wrote:

What you said resonates with me.  It sounds like we have had a similar experience with the code for the Picoscopes.  It does seem like a bit of a "mess", but I mostly have it doing what I want.  I have used the LabVIEW memory manager functions to transfer the data between the dll code and LabVIEW.  Even though my code seems to be working, I have the sense that I don't completely understand what I am doing such as with the case of "ps4000OpenUnitEx" and "ps4000OpenUnitEx-2".


I don't use nor have a PicoScope. But I did look at their provided driver after users in the forum had troubles with it and almost threw up from that. It was horrible and violated pretty much every possible rule about properly handling managed memory buffers such as what LabVIEW arrays are. Also the VIs were a way to thin wrapper around the DLL functions to be safely usable for a LabVIEW programmer who isn't a real pro in C programming and read und understood  the according PicoScope Programming Manual too.

 

I didn't attempt to fix it, just commented on what would be needed to make it kind of work and some user seemed to get it so far that it actually started to work without continuously crashing. Unfortunately this is the state of many LabVIEW drivers out there that interface to shared libraries, except the ones from NI of course and a few others. Most LabVIEW users want to believe that the job is done as soon as it doesn't crash anymore and/or return error 1097. Some even believe that that 1097 error is just a stupid annoyance and can be safely ignored as long as the computer doesn't explode or otherwise goes into flames. In reality every 1097 error means, that something went wrong, either the code caused an exception, or some memory was corrupted, no matter that everything still seems to work. And even if it doesn't crash and there is no 1097 error, this is absolutely no guarantee that the code is fully correct. The Call Library Node does all kinds of safety nets such as stack alignment correction, memory trampolines around buffers to detect buffer overflows and exception handling. Anytime it detects one of these things it generates this 1097 error and that simply means something got seriously wrong and it is basically not safe anymore to continue with anything in LabVIEW if you do not want to risk corrupted programs, data or even hardware problems.

 

But LabVIEW has only so many ways to detect that something went wrong during the Call Library call. There is an indefinite amount of possibilities that a DLL can create problems that LabVIEW simply can't even possibly detect, so even if all seems well it may still be a time bomb that will go off one day, unless you are able to review every single Call Library Node and verify that it actually does everything right, from correct calling convention, to correct parameter types, and correct memory buffer sizes and several more things.

Rolf Kalbermatter
My Blog
Message 7 of 10
(1,805 Views)

Of that -2 function-naming thing I have no clue.  Sorry.  ...and that's some of why I hesitated as I wasn't really answering your question.  But still that PicoScope-LabVIEW interface is no cakewalk, and I felt it wrong, by another fellow human being and LabVIEW fan, to remain silent.  I needed to do what I needed to do and there was tons of empirical work involved to get my "system" to work.  I at times purposely crashed things just to figure out how to get from point A to point B with their dll.  Start simple stupid and build from there is my best advice. ...time con sume ing!

0 Kudos
Message 8 of 10
(1,764 Views)

"And even if it doesn't crash and there is no 1097 error, this is absolutely no guarantee that the code is fully correct. The Call Library Node does all kinds of safety nets such as stack alignment correction, memory trampolines around buffers to detect buffer overflows and exception handling. Anytime it detects one of these things it generates this 1097 error and that simply means something got seriously wrong and it is basically not safe anymore to continue with anything in LabVIEW if you do not want to risk corrupted programs, data or even hardware problems."

 

Hear hear!  There is much under the hood and when the platform you're standing on starts to shake... "How in the world did that happen?"  Ah, the PicoScope!  Nevermind.  Try to shutdown and restart.  End it all and then come back to where I know/believe things worked. Hear hear!  I swear there's something up with their USB connection, too.

0 Kudos
Message 9 of 10
(1,761 Views)

"or some memory was corrupted,"

 

I really should've quoted that line too. Hear hear hear hear!

 

Strange things happen has been my experience.  One sign I have found is when you close, try to leave, and you get that there are objects leaks.  I only wonder just how much has really been damaged behind the scenes.  It's downright scary.  As far as I know, killing all NI applications that are running via Task Manager is a safe exit, but I'm still paranoid enough to just kill it all and start from an off PC, without saving anything prior to doing such.  Thus far just having LabVIEW tell me it wants to recover things after the restart (from off), as much as I cringe seeing it and doing it, hasn't been a truly negative experience.  Welcome to PicoScope and LabVIEW is what I say in my mind.  

0 Kudos
Message 10 of 10
(1,695 Views)