LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pbyFwData - Pointer to the firmware binary data stream.

Hello,
I used labview to call a dll, but it have one parameter "pbyFwData" which Pointer to the firmware binary data stream.i don't understand what mean is "Pointer to the firmware binary data stream".I try to make this parameter point to the firmware path, but the program can't be run.the below is the .dll source code. who can tell you how to pass the value to the parameter "pbyFwData" by labview?
 

//------------------------------------------------------------------------------
// Purpose:      Public function to download the Flash Preloader.
// Parameter:
//   hZvDev    - Handle of the Zeevo Device.
//   pbyFwData - Pointer to the firmware binary data stream.
//   uFwLen    - The length of the preloader.
// Return value: SUCCESS if successful; Otherwise, the error code.
//------------------------------------------------------------------------------
ZEEVOPTU_API int ZV4301_SendPreLoader(HANDLE hZvDev,
                                      unsigned char *pbyFwData,
                                      unsigned long uFwLen)
{
   ZV4301 *pZvDev;
   COMM_DESC *pPort;
   int nResult, nTmOut;
   const unsigned long uBlkSize = 0x400;
   unsigned long uDummy, uCRC;
   unsigned char byDataBuf[32];
   unsigned char byData;
   if (!Validate(hZvDev))
      return ERR_BAD_HANDLE;
   pZvDev = (ZV4301 *)hZvDev;
   pPort = pZvDev->PortDesc;
   // Setup the Address and Length
   memset(byDataBuf, 0, sizeof(byDataBuf));
   LD_LoaderProgramAddr(byDataBuf) = LD_ZV4301_LOADER_ADDR;
   LD_LoaderProgramLengh(byDataBuf) = uFwLen;
   // Calculate the Header CRC
   uCRC= UT_CRCBuffer(byDataBuf+4, 8);
   LD_LoaderProgramHdrCRC(byDataBuf) = uCRC;
   // Calculate the Data CRC
   uCRC = CalculateCRC(pbyFwData, uFwLen);
   LD_LoaderProgramDataCRC(byDataBuf) = uCRC;
   // Detect target reset
   nResult = IsChipPwrOnReset(pZvDev, 10000);
   if (nResult != SUCCESS)
      return nResult;
   // send out header first
   nResult = WriteSerial(pZvDev, byDataBuf, LD_LOADER_PRGM_HDR_LEN);
   if (nResult != SUCCESS)
      return nResult;
   while (uFwLen > 0)
   {  // sending the preloader file
      if (uFwLen >= uBlkSize)
      {
         nResult = WriteSerial(pZvDev, pbyFwData, uBlkSize);
         pbyFwData += uBlkSize;
         uFwLen -= uBlkSize;
      }
      else
      {
         nResult = WriteSerial(pZvDev, pbyFwData, uFwLen);
         uFwLen = 0;
      }
      if (nResult != SUCCESS)
         return nResult;
   }
   nTmOut = 100;
   while (nTmOut > 0)
   {  // getting the respond 0xAA
      if (GetByte(pZvDev, &byData))
      {
         if (byData == 0xAA)
            break;
      }
      Sleep(10);
      nTmOut -= 10;
   }
   if (nTmOut == 0)
      return ERR_DOWNLD_PRELDR;
   nResult = SetCommBaud(pZvDev, FLOWCTRL_DIS, pPort->uBaud, &uDummy);
   return nResult;
}
 
0 Kudos
Message 1 of 6
(3,154 Views)
Hi,


The pointer is a U32 that points to a memory location where the data is. It is not clear from the prototype whether the pointer points to data that is feeded to the dll, or returned from the dll.


If data is feeded, wire an array to this parameter, and set uFwLen to it's length.


If data is returned, you need to use some other api calls to get the data from memory...


Regards,


Wiebe.


"Jimmy168" <x@no.email> wrote in message news:1146132611761-357678@exchange.ni.com...
Hello,I used labview to call a dll, but it have one parameter "pbyFwData" which Pointer to the firmware binary data stream.i don't understand what mean is "Pointer to the firmware binary data stream".I try to make this parameter point to the firmware path, but the program can't be run.the below is the .dll source code. who can tell you how to pass the value to the parameter "pbyFwData" by labview?
&nbsp;
//------------------------------------------------------------------------------// Purpose:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Public function to download the Flash Preloader.// Parameter://&nbsp;&nbsp; hZvDev&nbsp;&nbsp;&nbsp; - Handle of the Zeevo Device.//&nbsp;&nbsp; pbyFwData - Pointer to the firmware binary data stream.//&nbsp;&nbsp; uFwLen&nbsp;&nbsp;&nbsp; - The length of the preloader.// Return value: SUCCESS if successful; Otherwise, the error code.//------------------------------------------------------------------------------ZEEVOPTU_API int ZV4301_SendPreLoader(HANDLE hZvDev,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned char *pbyFwData,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long uFwLen){ &nbsp;&nbsp; ZV4301 *pZvDev;&nbsp;&nbsp; COMM_DESC *pPort;&nbsp;&nbsp; int nResult, nTmOut;&nbsp;&nbsp; const unsigned long uBlkSize = 0x400;&nbsp;&nbsp; unsigned long uDummy, uCRC;&nbsp;&nbsp; unsigned char byDataBuf[32];&nbsp;&nbsp; unsigned char byData;
&nbsp;&nbsp; if (!Validate(hZvDev))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ERR_BAD_HANDLE;&nbsp;&nbsp; pZvDev = (ZV4301 *)hZvDev;&nbsp;&nbsp; pPort = pZvDev-&gt;PortDesc;
&nbsp;&nbsp; // Setup the Address and Length&nbsp;&nbsp; memset(byDataBuf, 0, sizeof(byDataBuf));&nbsp;&nbsp; LD_LoaderProgramAddr(byDataBuf) = LD_ZV4301_LOADER_ADDR;&nbsp;&nbsp; LD_LoaderProgramLengh(byDataBuf) = uFwLen;&nbsp;&nbsp; // Calculate the Header CRC&nbsp;&nbsp; uCRC= UT_CRCBuffer(byDataBuf+4, 8);&nbsp;&nbsp; LD_LoaderProgramHdrCRC(byDataBuf) = uCRC;&nbsp;&nbsp; // Calculate the Data CRC&nbsp;&nbsp; uCRC = CalculateCRC(pbyFwData, uFwLen);&nbsp;&nbsp; LD_LoaderProgramDataCRC(byDataBuf) = uCRC;&nbsp;&nbsp; // Detect target reset&nbsp;&nbsp; nResult = IsChipPwrOnReset(pZvDev, 10000);&nbsp;&nbsp; if (nResult != SUCCESS)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return nResult;&nbsp;&nbsp; // send out header first&nbsp;&nbsp; nResult = WriteSerial(pZvDev, byDataBuf, LD_LOADER_PRGM_HDR_LEN);&nbsp;&nbsp; if (nResult != SUCCESS)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return nResult;
&nbsp;&nbsp; while (uFwLen &gt; 0)&nbsp;&nbsp; {&nbsp; // sending the preloader file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (uFwLen &gt;= uBlkSize)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nResult = WriteSerial(pZvDev, pbyFwData, uBlkSize);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pbyFwData += uBlkSize;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uFwLen -= uBlkSize;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nResult = WriteSerial(pZvDev, pb
0 Kudos
Message 2 of 6
(3,153 Views)
Hello Wiebe,
Thank you for your reply.I will try it today and tell you the result.
 
 
Best regards
Jimmy
0 Kudos
Message 3 of 6
(3,144 Views)
Hi wiebe,
I am very sorry for my late reply because I am very busy for these days.
i tried your method. i used "read from I16 file" to read the firmware binary data to a array, and then pass the array to the parameter "pbyFwData" and
pass the array size to the parameter "uFwLen". But unluckily, the program was still failed in reading the data into device. Attach one sub-function for 
your reference. As i am not good at VC language, hope you could help me. thanks a lot!
 
 
 
//------------------------------------------------------------------------------
// Purpose:      Local function to write one or more bytes to the COMM port.
// Parameter:
//   pZvDev    - Pointer to the Zeevo Device descriptor.
//   pszBuffer - Pointer to the data buffer.
//   uBufLen   - Length of buffer in byte.
// Return value: Number of bytes sent.
//------------------------------------------------------------------------------
int WriteSerial(ZV4301 *pZvDev, unsigned char *pszBuffer, unsigned long uBufLen)
{
   int nErrCode = ERR_DEV_IDLE;
   unsigned long uResult, uBytesWritten;
   OVERLAPPED osWrite;
   if (pZvDev == NULL)
      return ERR_PORT_NA;
   memset(&osWrite, 0, sizeof(OVERLAPPED));
   osWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
   if (osWrite.hEvent == NULL)
      return ERR_CREATE_EVENT;
   if (WriteFile(pZvDev->hCommPort,
                 pszBuffer,
                 uBufLen,
                 &uBytesWritten,
                 &osWrite))
   {
      if (uBytesWritten != uBufLen)
         nErrCode = ERR_IO_INCOMPLETE;
      else
         nErrCode = SUCCESS;
   }
   else
   {
      uResult = WaitForSingleObject(osWrite.hEvent, COMM_WR_TIMEOUT);
      switch (uResult)
      {
      case WAIT_OBJECT_0:
         if (!GetOverlappedResult(pZvDev->hCommPort,
                                  &osWrite,
                                  &uBytesWritten, FALSE))
         {
            unsigned long uError = GetLastError();
            if (uError == ERROR_IO_INCOMPLETE)
               nErrCode = ERR_IO_INCOMPLETE;
            else
            {
               COMSTAT comm_status;
               ClearCommError(pZvDev->hCommPort, &uError, &comm_status);
               nErrCode = ERR_SER_COMM;
            }
         }

      }
 
0 Kudos
Message 4 of 6
(3,135 Views)


@Jimmy168 wrote:
Hi wiebe,
I am very sorry for my late reply because I am very busy for these days.
i tried your method. i used "read from I16 file"


Stop right here! The function will return an array of I16 values. But your function expects an array of chars or in other words bytes. Now is the type of the pointer not really that important as no matter what LabVIEW passes to the DLL function it is just a pointer and the DLL is free to interpret it in any way it wants. The problem is that the size of the I16 array will be in number of I16 elements. Passing this as length to the DLL function will tell the function that you have placed x bytes in the buffer while in fact you have placed x words in there, but the function will only look at x bytes and ignore the remaining x bytes in the buffer.
There are two possibilities:

1) Read the file as array of U8 (there aren't any precanend functions but it should be VERY easy to create your own by taking the I16 version and make two small changes to it).

2) Use the Read from I16 file function and pass that array as I16 array to the function BUT multiply the number of elements by 2 before passing it to the DLL as length. This has one possible problem if the file contains an odd number of bytes and then you should really use approach 1) anyhow.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 6
(3,129 Views)
Hello, thank you for your help. I have solved the problem. I used the "Read Characters From File" function to read the firmware data, and then passed these datas to the parameter "pbyFwData" of dll function and passed these datas length to the parameter "uFwLen" of dll function.
0 Kudos
Message 6 of 6
(3,111 Views)