Examples

<< Click to Display Table of Contents >>

Navigation:  Plug-ins > User Plug-ins > Create a User Plug-in >

Examples

 

The following examples only illustrate the implementation of specific functionalities and are not intended to provide a solution to implementing a complete user plug-in.
 

 

Response to change in data base

To respond to changes in the data base, a corresponding callback function (OnDatabaseChanged) must be registered, for example, in the export function DLL_vInit. Please note that this is not possible during simulation.

// Register OnDatabaseChanged.

if(CAND_enRegisterCallback(OnDatabaseChanged,

 CAND_enDBChanged,

 CAND_hNullHandle(),

 0)

 == CAND_nERR_OK)

{

  // Registration was successful.

}

 

Unregistration can be implemented in the export function DLL_vDeInit.

 

// Deregister OnDatabaseChanged.

if(CAND_enUnRegisterCallback(OnDatabaseChanged,

                            CAND_enDBChanged,

                            CAND_hNullHandle(),

                            0)

 == CAND_nERR_OK)

{

  // Deregistration was successful.

}

 

The callback function must have the following structure:

 

ANSI_C void USERDLL_CALL OnDatabaseChanged(CAND_tenDBChangedReason iReason,

                                          CAND_tHandle hObject)

{

  // Insert code here for response to change in database.

}

 

Each time the data base is changed, this function is called, e.g. if a new data base is loaded or a data base object is changed.
 

Example: Actions before sending a message

To generate notifications before a message is sent to the bus, a “pre-transmit” callback can be registered:

 

// Register OnPreTransmitMsg.

if(CAND_enRegisterCallback(OnPreTransmitMsg,

                          CAND_enPreTransmit,

                          m_hRegMsg,

                          0)

   == CAND_nERR_OK)

{

// Registration was successful.

}

 

If the callback is not used anymore, it must be unregistered:

if(CAND_enUnRegisterCallback(OnPreTransmitMsg,

                            CAND_enPreTransmit,

                            m_hRegMsg,

                            0)

  == CAND_nERR_OK)

{

  // Deregistration was successful.

}

 

The following implementation of the callback function causes the signal value of the signal NMOT to be incremented before sending the message MS_308h.

ANSI_C unsigned char USERDLL_CALL OnPreTransmitMsg(

                                       CAND_tHandle hMsg,

                                       CAND_tstCanMessage* pstMsg,

                                       DWORD dwUserData)

{

  // Call handle on message "MS_308h".

  CAND_tHandle hMs308h = CAND_hFindObject(NULL, NULL, "MS_308h",

                                          -1, NULL, CAND_hNullHandle());

 

  // Call handle for Signal from the message.

  CAND_tHandle hAliveCounter = CAND_hGetSignalByName(hMs308h, "NMOT");

 

  // Call Signal value

  QWORD qwSigVal = 0;

  if (CAND_enGetSigData(hAliveCounter, &qwSigVal, sizeof(qwSigVal)) == CAND_nERR_OK)

  {

     // Increase and rewrite Signal value

     qwSigVal++;

 

     if(CAND_enSetSigDataHex(hAliveCounter, qwSigVal) == CAND_nERR_OK)

     {

        // Signal value was set.

     }

  }

  return 1;

}