LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing DLL buffer data after receiving Windows Message

Hi,

 

I am programming MS4404 bar code scanner using LabVIEW. This is a miniscan and does not have trigger button. So we need to trigger it using Software. 

 

Could communicates with scanner to enable. disable, beep, etc....issue is with the decoded data.

 

DLL put data in the allocated buffer, and send a windows message WM_XXXX to application. Problem is to check these windows messages and copy the buffer data into application..............struck up here..........There was an example for this scanner but that is in VC and it is using ON_MESSAGE function to catch windows message and memcpy() to copy buffer data into local.........................Not sure how to go ahead in LabVIEW

 

Appreciate any help from fellow members...........

 

Thanks in advance

 

 

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 1 of 44
(5,455 Views)

 

Little advancement in the issue......

 

I am able to capture windows messages using Windows messages queue library (found on ni.com), Now the issue is with creating buffer for DLL and pulling data from that DLL on successfull Decode of data from scanner.

 

I think I am going wrong in giving cirrect data type while creating buffer here.

 

Below is the description of the function from manual

 

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

 

I am sure I am going wrong about the pData parameter.

 

I need to create this buffer before decoding, so the scanner fills this buffer with decoded data.

 

Thanks in advance for your help.

 

 

 

 

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 2 of 44
(5,425 Views)
You can use initialize array to create an array of U8.  Configure the Call Library Node with your U8 array as the pData parameter.  Set the array format to "Array Data Pointer."  Also wire the length of your array to the max_length parameter.
Message 3 of 44
(5,419 Views)

Hey Nathan,

 

that worked. DLL is allocating buffer and it seems that scanner is filling data in the buffer (I am reading windows message to know if any error in filling data).........I am trying to retrieve data from this buffer, how do we copy data into application from this buffer????

 

 

 

Thanks

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 4 of 44
(5,412 Views)
Just wire the array output from the call library node, across from the corresponding input.  That output should contain your data after the DLL call executes.
0 Kudos
Message 5 of 44
(5,404 Views)

Anil Reddy wrote:

Hey Nathan,

 

that worked. DLL is allocating buffer and it seems that scanner is filling data in the buffer (I am reading windows message to know if any error in filling data).........I am trying to retrieve data from this buffer, how do we copy data into application from this buffer????


Hold on, who's supposed to be allocating the buffer - you or the DLL? If you're supposed to allocate a large enough buffer and pass it to the DLL so it can fill in the values, what nathan suggested is fine. On the other hand, if it's the DLL that's allocating the buffer you've got a different issue. In this case you need to be able to deallocate the buffer (probably through another function), or you will have a memory leak. 

Message 6 of 44
(5,399 Views)

 

Hey......

 

Here my DLL works in bit different way......

 

I need to create buffer first (Using set buffer function in DLL).......After that I call another function Read Parameters (one of the functions), using another DLL call.....That is where the link is missing. It is easy in C# and C++ just copy the variable into local variable........I am just checking out here.....and I need to read the data after receiving WM_XXX message from scanner........

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 7 of 44
(5,398 Views)

 

well..Am initializing an array and giving it to DLL using Call Lib Function. DLL allocates buffer for the data coming from scanner. Then I send a command to scanner to read parameters or decode bar code. Then scanner fills data into buffer and sends a windows message. We should be able to access that buffer immediately after getting windows message. then DLL will clear that buffer

Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 8 of 44
(5,393 Views)

So, if I'm understanding correctly, your DLL expects that your (LabVIEW) code will allocate the buffer.  In one call, you provide the address of that buffer.  In a different call, the DLL fills data into that buffer.  So, you need a way to tell LabVIEW to allocate a non-moveable block of memory, so that you can pass its address to the DLL.  You also need a way to copy the data from that buffer onto a LabVIEW wire.  We're outside my area of experience here, but I think you need to look at the memory management functions LabVIEW provides for writing CINs.  These same functions can be called from a Call Library Node by setting the DLL name to "LabVIEW."  Help for those functions is available inside the help directory in your LabVIEW installation, take a look at lvexcode.chm and lvexcodeconcepts.chm.  Also, search through the forum posts here, rolfk has written many, many helpful comments about using those functions.

 

I think you can do what you want by calling DSNewPtr to get your block of memory.  This will return a pointer that you can pass to SetDecodeBuffer.  Then, when you need to retrieve the data from that pointer, call MoveBlock.  The source is your pointer and the destination should be a LabVIEW array.  When your code terminates, call DSDisposePtr to release the memory for the buffer.

Message 9 of 44
(5,357 Views)

Hi Nathan,

 

What you understood is correct.........

 

I will start looking into CINs..never worked with them......I worked mostly with API calls to DLLs using Call Library Functions only..............I thought this scanner programming would not be a big issue...but this only driving us crazy..................

 

Thank you for your help..............Will update with result after trying with CINs...........

 

 

Message Edited by Anil Reddy on 12-11-2009 09:47 PM
Anil Punnam
CLD
LV 2012, TestStand 4.2..........
0 Kudos
Message 10 of 44
(5,342 Views)