07-31-2012 01:17 AM
Hi
I'm developping some labview files to communicate with a usb to I2C Converter form coptonix.
The communication from PC to converter works fine, but in the opposite direction I have a "little" problem, because I don't know how to access the data.
I need to program the following sequence in LabView: Stri := Stri + '['+IntToHex(GetByte(PData,i),2)+'] '; // PData is the pointer, that points to an array of byte (1024 bytes)
I tried it with some ideas of other questions in the discussion forum, but I couldn't solve my problem.
Many thanks in advance!
07-31-2012 01:21 AM
@sly21 wrote:
Hi
I'm developping some labview files to communicate with a usb to I2C Converter form coptonix.
The communication from PC to converter works fine, but in the opposite direction I have a "little" problem, because I don't know how to access the data.
I need to program the following sequence in LabView: Stri := Stri + '['+IntToHex(GetByte(PData,i),2)+'] '; // PData is the pointer, that points to an array of byte (1024 bytes)
I tried it with some ideas of other questions in the discussion forum, but I couldn't solve my problem.
Many thanks in advance!
You mention a DLL, but do not give any information as to how the interface to that DLL should look like.
Do you have a problem interfacing to the DLL, or do you have a problem implementing that specific sequence of code, which would have nothing to do with DLLs, I would think.
07-31-2012 01:39 AM
You're right Rolf. The problem isn't to interface the dll, but to get the data out of the pointer array according to the sequence code!
07-31-2012 02:01 AM - edited 07-31-2012 02:08 AM
And how did you get that pointer array? LabVIEW does not know anything like pointer arrays, so this code is obviously not directly applicable. Give us some more context if you want us to help you.
What datatype is Stri, where did you get PData from and how is it represented in LabVIEW? All these kind of things are pretty fundamental to be able to even guess where a solution might lead to.
If this is what I guess it is, you will most likely have a Byte Array in LabVIEW and using a loop, and a Format into String with a %02x format code inside the loop, convert this array into a string of hex values.
07-31-2012 02:43 AM
Well, it's quite a bit complicated...
The whole communication deals with windows messaging. When I send a message from my device under test to the USB to I2C converter, the windows messaging sees this and then I should be able to read the pointer array.
In the attachment ypu see the Vi for the direction from computer to device under test (COD01.0420-PP_Test17_I2C_Version_03_Write: the one that works)
and the Vi for the direction from the device under test to the computer (COD01.0420-PP_Test17_I2C_Version_03_Read: I can't get the data out of the pointer array).
Maybe, it's now easier to understand
07-31-2012 03:09 AM - edited 07-31-2012 03:10 AM
Slightly!
The PData is not a pointer array but a byte array!
How did you initialize the PData global? You better pass it a large enough buffer or the C function will perform an access violation.
What is the prototype and parameter description of the C function called by the CLN?
How is the CLN configured? In order for the C function to return any data in your second parameter it needs to be passed a valid buffer. Unless you specify a minimum size for that parameter in the CLN configuration, it will get passed an array with 0 bytes and cause an access violation when trying to write anything into it.
07-31-2012 03:31 AM
Attached you see the definition/creation of the dll-access
1. File is the LabVIEW-Code
2. File is the definition of the PData-Array
07-31-2012 04:02 AM - edited 07-31-2012 04:03 AM
But that is not the same CLN that you showed in the previous post in the second picture. That one had two array parameters and this one has only one.
It seems you try to pass an array to your DLL to be used later with this create call. This is a complete NO GO in LabVIEW. LabVIEW arrays are only guaranteed to stay valid for the duration of the DLL call, and LabVIEW reserves all the rights for itself, to reuse that array after the DLL call for whatever it deems necessary including resizing it, reusing it for something entirely different or even completely deallocating it, so that the pointer passed to the DLL can not be relied upon to stay valid after the function returns to the LabVIEW diagram.
To be able to do what you want you need to create a memory pointer yourself, by executing an according non LabVIEW memory allocation routine, such as the Windows API HeapAlloc(). Alternatively you can also call the LabVIEW memory manager function DSNewPtr() through the CLN. Search for this function name in this forum to see how this can be done. Now as you created that pointer yourself you are not only fully entitled to use it to your liking, but you are even obligated to manage it's lifetime by deallocating the pointer after use properly with the correct memory free method.
BTW: All by all, sending pictures is somewhat helpful, but seeing the actual VI is a lot more meaningful as there are many informations that might be important to see and doing the post and ask for more information game several times itereatively is a bit tedious. Also there are various informations in a VI that are not easily conveyed through pictures.