Log File Generation

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
Log File Generation

In order to support debugging of problems, that can arise during CAN communication, PCAN-Basic can generate a log file, containing a protocol of all API function calls. There are two different ways to configure and activate this logging functionality:

 

In order to configure the Log functionality, PCAN-Basic API provides 3 parameters that can be configured with the function CAN_SetValue (class-method: SetValue). These parameters are:

Example:

Within the following example, the PCAN-Basic is configured to log all possible information (LOG_FUNCTION_ALL = 0xFFFF), as well as to store the log file on the desktop of an user called "admin". 

C++:  

TPCANStatus result;
char strMsg[MAX_PATH];


// Configures the data in the log file.
//
iBuffer = LOG_FUNCTION_ALL;
result = CAN_SetValue(PCAN_NONEBUS, PCAN_LOG_CONFIGURE, (void*)&iBuffer, sizeof(iBuffer));
if(result != PCAN_ERROR_OK)
{
    CAN_GetErrorText(result, 0, strMsg);
    MessageBox(strMsg);
}

// Configures the path of the log file.
//
char *buffer = "C:\\users\\admin\\desktop";
result = CAN_SetValue(PCAN_NONEBUS, PCAN_LOG_LOCATION,buffer,strlen(buffer));
if(result != PCAN_ERROR_OK)
{
    CAN_GetErrorText(result, 0, strMsg);
    MessageBox(strMsg);
}

// Configures the status of the log file
//
int iBuffer = PCAN_PARAMETER_ON;
result = CAN_SetValue(PCAN_NONEBUS, PCAN_LOG_STATUS, (void*)&iBuffer, sizeof(iBuffer));
if(result != PCAN_ERROR_OK)
{
    CAN_GetErrorText(result, 0, strMsg);
    MessageBox(strMsg);
}

 

In order to enable the log file generation, the following registry key must be created:

HKEY_CURRENT_USER\SOFTWARE\PEAK-System\PCAN-Basic\Log

The existence of this key is analogous to use the function CAN_SetValue (class-method: SetValue) to set the parameter PCAN_LOG_STATUS to "on". If this key is not present, then no log file is generated.

Configuration:

If no further configuration is made, then the default values for PCAN_LOG_LOCATION, and PCAN_LOG_CONFIGURE are used. In order to configure the location and content of the log file, two registry values are used: 

Flags: This is a DWORD value, that represents a logical OR operation between the values LOG_FUNCTION_* that are wanted to be included within the logging data. The value LOG_FUNCTION_ALL causes logging all possible information. 

Path: This is a String value, that represents the path to a folder in the computer, where the log file will be created.

Example:

Within the following example, the PCAN-Basic is configured to log function entries (LOG_FUNCTION_ENTRY = 1), function parameters (LOG_FUNCTION_PARAMETERS = 2), and function outs (LOG_FUNCTION_LEAVE = 4), as well as to store the log file on the desktop of an user called "admin".

[HKEY_CURRENT_USER\SOFTWARE\PEAK-System\PCAN-Basic\Log]
"Flags"=dword:00000007
"Path"="C:\\Users\\admin\\desktop"
Remarks:

The registry key should be deleted (or renamed) after a debug session is done. If the key is leaved, all PCAN-Basic applications running under the same user account will remain writing data to their log files, generating in this way huge text files that consume hard-disk space unnecessarily.

Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
Send feedback to this documentation