Showing results for 
Search instead for 
Did you mean: 

How to use Win32 API winbase.h functions

Is there any way of calling functions regarding System Services directly from LV using call library function node? I'm interested in flushing communication buffers using PurgeComm function inside of a winbase.h Win32 API:



0 Kudos
Message 1 of 3

What communication buffers are you trying to flush? LabVIEW has native functions to do this. For example:


It's certainly possible to call that function, but it doesn't seem like something you should need to do.

0 Kudos
Message 2 of 3

Jim already basically answered you.


Technically it is possible to call pretty much every Windows API by using the Call Library Node. But just because you can, doesn't mean you should.


For the function you propose you can see that the first parameter is a HANDLE. This must be a handle opened by calling CreateFile(). CreateFile is a general purpose function to open both files and also devices and a few other things under Windows. For PurgeComm() to be able to do its thing you need to have opened a COMM device with CreateFile(). 


You can of course do all that and start interfacing to the entire Windows COMM API to do your own serial port handling but in 99.9% of the cases this is wasted energy since LabVIEW comes with the VISA functions that let you control serial ports just fine and offers many many other functionality including a Flush function that basically does the same as the function you show.


And no you can not take a VISA handle and just pass it to PurgeComm(). While VISA does under the hood eventually call the Windows COMM API for serial port resources, the handle to do that is a private property of the VISA session that you can not access. That's because it is buried in a layered VISA driver architecture that clearly isolates things between the different layers and that is good software design.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 3