LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calling CAT API from lavbiew

hello,
I have this CAT (CAN Analyzer Tool). (http://www.ime-actia.com/web_can/software/cat_api_driver.htm) and I using their API. I am having trouble with following API function. Can someone please help. I need to call this function from LV. Function is in their API dll.
I copy this from their VC++ code.
 
//////////////////////////////////////////////////////////////////////typedef started/////////////////////////////////////////////////////////////////////////////////////
typedef union {
  tCATOBJ_LogObj_Data Dat;
  tCATOBJ_LogObj_Error Err;
  tCATOBJ_LogObj_TriggerOnly TriggerOnly;
} tCATOBJ_LogObj,* PCATOBJ_LogObj;
 
typedef struct {
  unsigned char ChipStatus;
  unsigned char ChipErrorCodeCapture;
  unsigned char ChipRxErrorCounter;
  unsigned char ChipTxErrorCounter;
  unsigned short AccuRxErrorCounter;
  unsigned short AccuTxErrorCounter;
} tCATOBJ_ErrorInfo;
 
typedef struct {
  unsigned char Length;
  unsigned char ObjID;
  unsigned char ObjSubID;
  unsigned char EvenAddressFillupByte;
  unsigned char LogStatus;
  unsigned short LogNbrOfInBuffObjs;
  unsigned short LogOverflowCounter;
  unsigned short LogTriggerPoint;
  unsigned short DiagLogNbrOfInBuffObjs;
  unsigned short DiagLogOverflowCounter;
  tCATOBJ_LogObj LastTransferedObj;
  tCATOBJ_ErrorInfo ErrorInfo;
  unsigned short LogWritePointer;
  unsigned short DiagLogWritePointer;
} tCATOnlineData0,* PCATOBJ_GetOnlineData0;
///////////////////////////////////////////////////////////////////////////////////typedef finished////////////////////////////////////////////////////////////////////
unsigned char     *RecvBuffer;
 unsigned short nObj;
 tCATOnlineData0*   GetData0;
 
status = CATIDLL_ReceiveOnlineData(&RecvBuffer, &nObj);
GetData0 = (tCATOnlineData0*)RecvBuffer; 
GetData0->LastTransferedObj.Dat.FrameInfo;
 and so on.........
 
My question is how do I call this  CATIDLL_ReceiveOnlineData function in LV?
Is it possible to do in LV?
 
I have attached DLL and complete documentation for API. Please help.
 
 
Here is help from DLL************************************************

CATIDLL_ReceiveOnlineData

The CATIDLL_ReceiveOnlineData function receives the online data from the CAT hardware board.

int CATIDLL_ReceiveOnlineData(
  unsigned char** ppRecvBuffer,
  unsigned short* pObjNum
);

Parameter

ppRecvBuffer

[out] Specifies the buffer for receiving the online data. You have only to specify the pointer. The memory will be allocated in this function internally.

pObjNum

[out] Specifies the number of received communication objects (PCATOBJ_GetLogObjs)

Return Values

If the function succeeds, the return value is CATI_OK. If the function fails the return value is defined in CATIERR.H

Remarks

Before you call this function, you have to call CATIDLL_RequestOnlineData.
The buffer ppRecvBuffer will contain the communication objects if there are some data available in the online buffer on the CAT hardware board. The communication objects have a dynamic length and they are mapped one after the other in the buffer. The first byte of every communication object contains the length of the own object. So, if you want to get a pointer to the second communication object, you have to add the value of the first byte from the first communication object to the pointer of the first communication object. See 'CatiAPI DemoDlg.cpp' OnBUTTONGetOnlineData() for a reference implementation.

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 6
(4,038 Views)

Hey Sheetal,
    With LabVIEW, you can import dlls by using the Call Library Function Node VI.  Here is a link that describes its use.  Also, you can use the import dll wizard.  Here is a link describing that functionality.  There's also a good KnowledgeBase article about using external code in LabVIEW, and it includes other links that may be of use to you with this issue.

 
Brian B
Account Manager
National Instruments
0 Kudos
Message 2 of 6
(4,005 Views)

@brian B wrote:
Hey Sheetal,
    With LabVIEW, you can import dlls by using the Call Library Function Node VI.  Here is a link that describes its use.  Also, you can use the import dll wizard.  Here is a link describing that functionality.  There's also a good KnowledgeBase article about using external code in LabVIEW, and it includes other links that may be of use to you with this issue.
 



Yes but is that tool smart enough to handle this complex API? 🙂

This one is using double referenced pointers allocated in the function itself and I'm sure the person would very much like to reference the data in there too. This is going to be a pita to do all in LabVIEW and I doubt a tool will be able to handle that automatically. Personally I would write a C wrapper function to handle this translation into more LabVIEW friendly data structures.

And Sheetal, you miss important information in your documentation. It is quite some guesswork as to how that function will fill in the character buffer with the data structures (the definition of the elements of the Log structure are nowhere defined), and even more so what data alignment it will use.

It is certainly doable but with quite some work. You have to define both parameters as an uInt32 passed by reference and find out the exact byte length of the entire GetData0 structure (this is really handwork if you do not write some intermediate translation DLL) and then allocate a long enough byte buffer (IntializeArray function with type uInt8 and the length computed with the size of your data structure multiplied by the number returned in the second parameter of your function. The using MoveBlock as explained in some other threads copy the data from the first uInt32 that is really a pointer into the byte buffer you just allocated and then extract the data from the byte buffer.

You could make it all a bit simpler in the runtime part by instead creating a cluster resembling your data object. But watch out LabVIEW uses byte packing while most DLLs use 8 byte alignement so yuo will likely need to add padding bytes in your structure to match the actual memory layout. Once you have the correct cluster you can just allocate an array of those clusters with the size indicated by the second parameter of your function and copy the data from the pointer into that array cluster with MovBlock and the computed byte size. This will avoid typecasting into the cluster later on and all the necessary byte swapping. 

Rolf Kalbermatter

Message Edited by rolfk on 12-11-2006 12:36 PM

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 3 of 6
(4,001 Views)

Nice post Rolf.  LabVIEW cannot handle pointers to pointers, therefore in order to accomplish this behavior a C wrapper must be written to convert data types.  Check out this other discussion forum post on accomplishing char** within LabVIEW.

 
Brian B
Account Manager
National Instruments
0 Kudos
Message 4 of 6
(3,973 Views)
Thanks everybody. Thie really helps.
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 5 of 6
(3,960 Views)

Hello, Test_man,

 

Could you send me the package of CATiapi?

Here I only have the catiapi.com with the password protection.

 

I need this package urgently.

 

My email is jyangsz@gmail.com.

 

Thanks

LanckerYang

0 Kudos
Message 6 of 6
(3,678 Views)