LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with the Call Llibrary Function Node when a DLL returns a pointer to data buffer.


poethomer wrote:

Syntax

SSIDLL_API int __stdcall SetDecodeBuffer(int nComPort, unsigned char *pData, long

max_length);

where:

. nComPort is the COM port number used in the call to SSIConnect

. pData is a pointer to the destination buffer for decode data returned from the

scanner

. max_length is the size in bytes of the destination buffer



If this prototype is correct, the DLL function does NOT return a pointer. Instead it expects to be passed a memory pointer by the calling application, that is presumably supposed to be at least max_length bytes long. There is no other way!

 

However  the name of the function gives reasonable support to the assumption that it is just assigning a string pointer to some internal global variable that the DLL will then fill in AFTER that function has returned. This is a way of operation that is very special and assumes that the buffer that was passed to SetDecodeBuffer() stays valid AFTER the control returns back to LabVIEW from that function.This is not generally the case for LabVIEW variables that reside in a wire. Once a wire stops existing on the diagram, LabVIEW not only reserves the right to reuse its buffer but in general also does so. So you would have to make sure that the wire stays in the diagram without further wire branches until after you can be sure the buffer has been filled and after you have used the aforementioned memory copy function to copy out the now available information from it.

 

It is uttermost important to not branch the wire on its way to the copy memory function in any way, as this would cause LabVIEW to most likely create a copy of the memory buffer and it would be sheer luck if the original buffer is passed to you copy memory function or the other place you were branching of to.

 

Remember the second section is entirely based on assumptions because of the function name. What this function really does and how it is supposed to be used should be explained in detail in the according documentation to the DLL. If it isn't, that is a problem of the DLL creator or distributor, not LabVIEW. 

Message Edited by rolfk on 12-14-2009 10:28 AM
Rolf Kalbermatter
My Blog
Message 11 of 23
(1,422 Views)

Hi,

 

problem is solved using LabVIEW only. I tried using ActiveX Control. So I am bale to get the data from the scanner now.

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 12 of 23
(1,388 Views)

Anil,

 

Were you able to use the ActiveX Event Callback to get the scanned data? I cannot seem to get the callback to fire. Could you post an example of what you did?

 

Thanks,

John 

0 Kudos
Message 13 of 23
(1,290 Views)

Hi John,

 

I could get scanned data using ActivX events. We need to setup few parameters in the scanner before scanning.

 

connection flow goes like this....

 

Automation open (point this to ActiveX control)

Set baud rate, COM port number

connect com port

enable scanner (netter to use)

change parameter "decode data packet format" as "Packeted Decode Data"...This will not be selected by default withe the scanner, so you have to set this parameter

set trigger to host trigger mode

then send command to pull trigger

 

then  Use Reg Event Call back node and event "decode data available"

disconnect com port

unregister events

close automation

 

 

Let me know if you still have problem...

 

Regards

Anil

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 14 of 23
(1,266 Views)

Anil

 

I followed your program flow but I am still not getting the callback vi to execute. I'm at a loss for what the problem is. I've attached my vi and the callback if you could take a look and see if I'm missing something I'd greatly appreciate it.

 

Thanks,

John 

0 Kudos
Message 15 of 23
(1,259 Views)

few modifications in call back VI...........

 

remove case structure, feed SSI Code "0" (zero) and event type "8"...This is how I am using now........Lets see if that helps out........

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
Message 16 of 23
(1,241 Views)
That was the issue, I'm getting the data back from the scanner now. Thank you so much!
0 Kudos
Message 17 of 23
(1,238 Views)

wow thats great.......I am glad that it solved your problem......

 

 

you can improve this by adding event structure in the while loop..

remove all sequence structures

 

add event structure to while loop....add a STOP button and add event for that.

now bundle these data reference and stop button reference..then feed it to "user parameter" option in "reg event callback".

 

and in the call back VI, write True to Value (signalling) property of Stop button. Make sure it is Value (signalling) ..not just "value".......

 

this will make your program exit as soon as decode happens........otherwise you will have to wait for some time to read the data......

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
Message 18 of 23
(1,215 Views)

I have the same problem, im doing the same but my scanner does not retrieve anything. do you could advice.

0 Kudos
Message 19 of 23
(814 Views)

Hi Danaielt, 

 

Could you provide a little more information about your scenario? In order to see if I have any suggestions, I would like to know which one of the listed options you've tried so far. Enjoy the rest of your day.

 

Andres G
Applications Engineer
National Instruments
0 Kudos
Message 20 of 23
(773 Views)