05-24-2012 10:47 PM
I'm looking toconvert this C code into LabVIEW. I'm a bit confused on how to load the SendData into my .so or .dll (for windows). The CPCI75C3_SER_TransmitBuffer function provided takes in a string. How do I convert this array of unsigned char to a string?
unsigned char SendData[8];
...
for (i=0; i < 8; i++)
SendData[i] = (unsigned char)i; /* incremental data */
/* Add a delay here for receiver to be ready */
nai_msDelay(500);
nNumWordsSend = i;
printf ("\nSending %d words ...", nNumWordsSend);
status = CPCI75C3_SER_TransmitBuffer(Card, nMod, nChan, SendData, &nNumWordsSend); /* send data */
Solved! Go to Solution.
05-25-2012 12:52 AM
What is the function prototype for the CPCI75C3_SER_TransmitBuffer function?
You can build a standard LabVIEW string and configure the Call Library Function Node to pass it as a C string, or you can use the "String to Byte Array" function to convert the LabVIEW string into an array of U8 (unsigned char) and pass that array to the function. Either should work. Alternatively, if in your LabVIEW code you already generate an array of U8, then there is no need to do anything - just pass the array directly.
If you're still confused, please upload your VI showing how you have configured the Call Library Function Node.
05-25-2012 01:41 PM - edited 05-25-2012 01:44 PM
Here is the function name and variables. Attached it my VI to handle this transmitbuffer.
_75C3FUNC int CPCI75C3_SER_TransmitBuffer(
int Card,
int Module,
int Channel,
unsigned char* Buffer,
int* Length
)
My guess is that I can use the byte array to string function. Will that fit my need? Is my understanding a unsigned char a unsigned byte (u8)?
05-25-2012 01:46 PM - edited 05-25-2012 01:49 PM
Looks to me like the Call Library Function Node is properly configured.
EDIT: you updated your post after I replied. An unsigned char is the same as an unsigned byte (U8) but the way you have it configured now is fine, no need to change it to a byte array unless I've misunderstood what you're asking.
05-27-2012 09:23 PM
thanks, looks to me I will create my array values and convert them to u8 and then convert them to strings.
05-28-2012 01:42 AM
Actually, from the C code in the first post it seems the data are supposed to be truely binary bytes, since the first character is sent as NULL byte. So using a string is not an ideal way. It should work for sending data to the C function, with a minor issue, as LabVIEW will actually append a NULL byte to the end of the string before sending it to the function. But since the data is binary and therefore the function will need to go with the extra length parameter anyhow to know how many bytes are to be transmitted, that extra appended byte is only a cosmetic issue and also causes a minor performance hit, as LabVIEW needs to append the NULL byte first.
It would be totally unsuitable for binary buffer parameters that return data from the function. The LabVIEW Call Library Node will scan C string pointers on return and cut them off at the first NULL character. So if your binary buffer contains a NULL byte, LabVIEW will never see anything behind the first NULL byte.
The right solution for binary byte buffers to be passed to an external C function is to configure the parameter as array of unsigned 8 bit integers.
05-29-2012 01:23 PM
Thanks Rolf for pointing out the null byte ending a C string, I had forgotten about that.
@thomassster wrote:
thanks, looks to me I will create my array values and convert them to u8 and then convert them to strings.
If you have an array of u8, pass that. There is no reason to convert it to a string, as Rolf explained.
05-06-2015 03:44 AM - edited 05-06-2015 03:45 AM
Thanks for this info.
This also helped me solving the problems I was having.