LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Resetting a pointer in DLL node

Solved!
Go to solution

Hello Everybody,

 

I am learning how to use the shared library node in labview to access C files. I am new to writing dlls and I am stuck with a simple problem.  Let me explain the problems and requirements clearly.  In the attached C file, I have written a code to perform overflow correction to a 32 bit record returned by the instrument. a typical overflow record will have a hex value like "FE000001". This record in turn is separated by logical operations.

 

Capture.JPG

 

DESCRIPTION OF THE C CODE:

"oflcr" is the variable that will be calculated according to the expression inside the if condition, this variable will be accumulated through out the data acquisition time. Next, this dll code will be calledinto labview using the dll node. I have set  the function prototype exactly.  In the labview code the dll is placed in a for loop. My aim is to nitialize the ofl variable to zero whenever I run the code, for which I use a local variable and initialize it to zero. 

Capture2.JPG

In the labview code above, if I introduce the regular record (not an overflow and should be skipped) first then the clk (pointer that points to the ofl variable)data pointer always stores the previous value in the previous run of the program and adds to it any value that is obtained in the currently running program. on the other hand,  If I introduce the overflow record first then the pointer is initialized to zero and everything works fine. 

I cannot understand why this happens. 

Please have a look at the file and help me solving this error. I am stuck in this for  along time. 

 

thanks for any help!!

Regards

Pradeep

0 Kudos
Message 1 of 4
(2,519 Views)
Solution
Accepted by topic author pradeepK

Hi Pradeep,

 

THINK DATAFLOW!

Get rid of (possible) race conditions and replace your locals variables "clk" by a shift register of the loop!

 

Also:

You use an autoindexing input tunnel. So why do you limit the loop iterations by wiring a constant to N?

Do you know you can switch the display format of constants? No need to write an additional comment keeping the "hex representation"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(2,492 Views)
Solution
Accepted by topic author pradeepK

You haven't wired anything to the clk input, so what is LabVIEW de-referencing to get an address to pass as that parameter? What is the reason for having both the "oflcr" and "clk" inputs? Those should be a single input, passed by pointer. Inside the function, dereference the pointer and do the math:

*oflcr += (timestamp * clr);

No need for the clk input. See how the Call Library Function Node has corresponding inputs and outputs for every parameter (except the return value)? A parameter passed by reference can act as both an input and an output.

 

Also, adding to GerdW's comments: why are you building a 2-D array, when you really only want a 1-D array?

Message 3 of 4
(2,471 Views)

@nathand wrote:

You haven't wired anything to the clk input, so what is LabVIEW de-referencing to get an address to pass as that parameter? What is the reason for having both the "oflcr" and "clk" inputs? Those should be a single input, passed by pointer. Inside the function, dereference the pointer and do the math.


 

 

Actually LabVIEW is smart enough nowadays to allocate a (skalar) variable if the input side of a terminal is not wired. Obviously that doesn't hold true for arrays and strings as LabVIEW has no means to decide if allocating an array of 1 element is enough or if it needs to allocate 1 million elements instead to allow for the function to write something into it.

 

But your comment that the input clk and the output clk can be combined is absolutely true. Also there should be a shift register in the loop for the clk variable and the local variable can then go away altogether, avoiding any race conditions at the same time with initializing the terminal at the right time.

 

And also the comment about the 2D array is obviously very founded.

 

Rolf Kalbermatter
My Blog
Message 4 of 4
(2,433 Views)