LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need advice on setting Call Library Function Parameters

Apologies if this may seem obvious but where should i place this function, after the system exec or call library function node. And what should be wired to 

 _In_ DWORD nStdHandle

 

0 Kudos
Message 11 of 17
(1,319 Views)

No, it's not obvious 🙂 I will try to build an example in some 5, 6 hours because currently I'm a little busy and I will send it to you 🙂

              

Think Dataflow - blog.mtapp.tech
0 Kudos
Message 12 of 17
(1,316 Views)

That would be great. In the mean time I will keep plugging away.

0 Kudos
Message 13 of 17
(1,313 Views)

Ok, there are many trouble and difficulties with trying to do this!!

 

1) A Windows HANDLE is really a pointer sized integer value. So make sure to use that. Otherwise you will get into trouble when you ever try to run the code in 64 Bit LabVIEW.

 

2) GetStdHandle() is a nice idea to get a handle to the standard output, but it doesn't work. LabVIEW is a GUI application and as such does not initialize a console and therefore doesn't end up having standard IO handles. And the function in question does require a console handle, not a standard IO handle. A console would contain several standard IO handles, but as already said, LabVIEW as a normal Windows GUI application does not initialize a console on startup.

 

3) Assuming you got a valid console handle from somewhere, calling the function GetConsoleScreenBufferInfo() is not a trivial exercise. The parameter lpConsoleScreenBufferInfo is a C structure, somewhat similar to a LabVIEW cluster. In this case it does not contain any pointers so it is relatively easy to do in LabVIEW with a cluster. The magic is to read the C specification for that structure and map it exactly into a LabVIEW structure.

typedef struct _CONSOLE_SCREEN_BUFFER_INFO {
  COORD      dwSize;
  COORD      dwCursorPosition;
  WORD       wAttributes;
  SMALL_RECT srWindow;
  COORD      dwMaximumWindowSize;
} CONSOLE_SCREEN_BUFFER_INFO;

 

First you have two COORD which is another cluster with two SHORT each. A SHORT is equivalent to a LabVIEW 16-bit integer. Then you have a WORD which is a LabVIEW unsigned 16-bit integer. Then a SMALL_RECT which is a structure with 4 SHORTs and last but not least another COORD.

 

Create a LabVIEW cluster with the embedded clusters for the COORD and SMALL_RECT, then configure the according function parameter in the Call Library Node to "Adapt to Type" and connect a constant of this cluster to the left side of that parameter and wire an indicator to the right side.

 

Alternatively since all the basic types in the structure are 16 bit integers you could just define the parameter as C Pointer to a 16 bit integer array. BUT in that case you have to make sure that you pass in an array which is allocated big enough so that the function can write its data into it. In this case you have to allocate an array of at least 11 16-bit integers on the diagram before passing that array to the function. Unlike in LabVIEW where a function usually allocates any array data at the moment it requires it, this doesn't work on the DLL interface like this. If a function expects a buffer to write data into (an array, a structure, or even a scalar passed as a pointer) the caller has to make sure that he passes a big enough memory buffer to the function that it can write into!!

 

Rolf Kalbermatter
My Blog
Message 14 of 17
(1,304 Views)

Thanks for the tips. There is a lot of freshening up of c code required and will be taken on board as no doubt this sort of problem will arise again in the future. The points you provided are the sort of things that are difficult to find. I have a good starting point to go from now.

 

Cheers.

 

Mark.

0 Kudos
Message 15 of 17
(1,296 Views)

Hi!

 

Rolfk, of course you are right, I was hoping it may be easier that it seems, but when I've started digging into this functions on MSDN I see it's not so straightforward.

 

What about, let's say workaround?

standard output.png

 

I know it is not perfect, but in some cases it may be enough to read the file - it should be possible to open the file in read mode even if there is continuous writing ongoing. Just an idea.

 

Marcin

              

Think Dataflow - blog.mtapp.tech
0 Kudos
Message 16 of 17
(1,293 Views)

The device I am communicating with I was initially going to have set up to write to a file constantly (as this is easily done within the script itself) and then read the file from Labview when needed. The main reason I wanted to move away from this is because if there was a device error the text file would still be there and provide old data. I may work around this by adding a time stamp with the data and getting Labview to check the time stamp to decide whether its the correct data.

0 Kudos
Message 17 of 17
(1,274 Views)