07-30-2005 06:26 PM - edited 07-30-2005 06:26 PM
HERE is my erase code:
DWORD iBytesWritten;
DWORD iBytesRead;
BOOL bWriteRC;
BOOL bReadRC;
char *sBuffer;
bWriteRC = WriteFile(a,"E\r",2,&iBytesWritten,NULL);
if (bWriteRC){
; //do nothing
}
else
return "Cannot Erase the Flash";
bReadRC = ReadFile(a,&sBuffer,20,&iBytesRead,NULL);
if (bReadRC){
return sBuffer; //do nothing
}
else
return "Cannot Read the Flash";
Message Edited by Newguy100 on 07-30-2005 06:30 PM
Message Edited by Newguy100 on 07-30-2005 06:31 PM
07-31-2005 10:23 AM
08-01-2005 03:01 PM
Hi,
When writing a dll in C++ for calling from LabVIEW, you need to wrap your function declaration in extern C clause so that the C++ compiler would not decorate the function name in the object code (see page 30 of 'Using External Code with LabVIEW' manual) . Also fro exporting the DLL functions you would need to use _declspec(dllexport).
Here is an example for serial communication using C++.
Hope this helps.
Ankita
08-01-2005 04:49 PM - edited 08-01-2005 04:49 PM
Message Edited by Newguy100 on 08-01-2005 04:50 PM
08-02-2005 04:08 AM
What about spending like 10min to read 'Using External Code with LabVIEW'. 😉
cheers
Pawel
08-02-2005 08:07 AM
08-02-2005 08:08 AM
return "Cannot Erase the Flash"
is a really bad idea. Strings (or, more specifically string pointers) are almost never returned in the return value of a function in C/C++. It's even worse when you try to return this to LabVIEW, since LabVIEW can't handle strings as return function. This is because LabVIEW must manage the memory associated with any string data it manipulates.
Instead, you should consider writing a function like this:
int FillString(char* pBuffer, int* pLen)
{
const char* kTest="Hello, world.";
int retval=0;
//If the length is zero, or the buffer is NULL, just return the necessary length
if(*pLen==0 || pBuffer==NULL)
{
*pLen=strlen(kTest)+1;
return 0;
}
//If the buffer is too small, return an error after copying everything we can.
if(*pLen-1 < strlen(kTest)
retval=1;
*pLen=min(*pLen-1,strlen(kTest))
strncpy(pBuffer, kTest, *pLen);
//strncpy doesn't append a null terminator, do so now.
pBuffer[*pLen]=0;
return retval;
}
This code allows LabVIEW to manage the buffer. Make sure in your VI that you initialize the string to a certain length and then pass it to the DLL by pointer. I believe that the External Code Reference Manual discusses this. Also configure the call to pass the string length by pointer. This code is robust in that it allows for error checking and also allows the function to return the necessary buffer size so that the caller can allocate it and then call the function again. Depending on your application, you may not need all the complication of this (for instance, if your strings are guaranteed to be a certain maximum length).
08-02-2005 08:50 AM
Here is my function declaration:
_declspec(dllexport) char* EraseCmd(void){
What i was thinking about doing was returning a statement in labview. I wanted to compare the statement in labview to what was read in the serial port and if they match they should move on,otherwise they should stop. I guess I could do the same thing in C using a strcmp and have it return a specific integer if they match or not.
08-12-2005 04:38 PM - edited 08-12-2005 04:38 PM
Message Edited by Newguy100 on 08-12-2005 04:41 PM
08-15-2005 07:11 AM