LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library Function Node generates an exeption

Please have a look at the files attached. I am trying to communicate with WAGO PLC bus coupler, but when calling some functions from .dll (MBTReadRegisters and MBTWriteRegisters), Laview crashes. It seems that I do not understand completely the way to pass and recieve parameters from Call Library Function Node.vi. C++ program that uses this .dll works without problems.
 
Can anybody open my example program and say what I do wrong?
I think that it is impossible to run the program (get a valid hSocket) without hardware.
 
I work under Labview 8.2 Base.
 
Thanks in advance.
0 Kudos
Message 1 of 4
(2,656 Views)
I don't have 8.2, so I can't look at your code, but I would suggest considering using a Modbus implementation made in LabVIEW. There are several around the web, including one made by NI. You should be able to find it if you search the forums.

___________________
Try to take over the world!
0 Kudos
Message 2 of 4
(2,650 Views)
Also, don't forget about the example programs that ship with LabVIEW that show how to pass information to \ from dlls. Go to Help>>Find examples. Select the Search tab and search for dll. The vi you're looking for is called "Call dll.vi"
 
 
Chris C
 
0 Kudos
Message 3 of 4
(2,630 Views)


@maxmihan wrote:
Please have a look at the files attached. I am trying to communicate with WAGO PLC bus coupler, but when calling some functions from .dll (MBTReadRegisters and MBTWriteRegisters), Laview crashes. It seems that I do not understand completely the way to pass and recieve parameters from Call Library Function Node.vi. C++ program that uses this .dll works without problems.
 
Can anybody open my example program and say what I do wrong?
I think that it is impossible to run the program (get a valid hSocket) without hardware.
 
I work under Labview 8.2 Base.EN WRT
 
Thanks in advance.


You do the classical LabVIEW programmer error when using the Call Library Node. While you do not have to worry about proper memory allocation in LabVIEW, you do have to do that when calling external C fucntions.

1) When writing, change the NaN connected to the callback parameter to a NULL integer. NaN is a binary pattern that can not be represented as a 32 bit integer which the callback pointer really is. LabVIEW can not support callback pointers so passing in NULL (0) here tells the function to not try to do that.

Instead of wiring an explicite numWords constant use the Array Size primitive to determine the actual size of the passed in array.

2) In your Read example VI the same about callback applies.

Also you pass in an array that you get from reading the local of the output control. This control by default is an empty array and therefore the function gets passed an array pointer that points to a memory location of 0 bytes length. Your DLL happily writes to that pointer numWords 16bit values and -> crash.

Instead use the Initialize Array function node, connect a 16 bit integer to the element input, the same number you pass in as numWords parameter to the length input, et voila, your function should not crash anymore.

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(2,621 Views)