Log File Generation

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:

Log configuration using API

In order to configure the log functionality, the PCAN-Basic API provides 3 parameters that can be configured using the SetValue method. These parameters are:

Example

The following example shows how the PCAN-Basic is configured to log all possible information (LOG_FUNCTION_ALL), and to store the log file on the desktop of an user called "admin".

C#
TPCANStatus result;
System.Text.StringBuilder strMsg;

strMsg = new System.Text.StringBuilder(256);

// Configures the data in the log file.
//
uint iBuffer = PCANBasic.LOG_FUNCTION_ALL;
result = PCANBasic.SetValue(PCANBasic.PCAN_NONEBUS, TPCANParameter.PCAN_LOG_CONFIGURE, ref iBuffer, sizeof(UInt32));
if (result != TPCANStatus.PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic.GetErrorText(result, 0, strMsg);
    Console.WriteLine(strMsg.ToString());
}

// Configures the path of the log file.
//
string buffer = "C:\\users\\admin\\desktop";
result = PCANBasic.SetValue(PCANBasic.PCAN_NONEBUS, TPCANParameter.PCAN_LOG_LOCATION, buffer, (UInt32)buffer.Length);
if (result != TPCANStatus.PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic.GetErrorText(result, 0, strMsg);
    Console.WriteLine(strMsg.ToString());
}

// Configures the status of the log file
//
iBuffer = PCANBasic.PCAN_PARAMETER_ON;
result = PCANBasic.SetValue(PCANBasic.PCAN_NONEBUS, TPCANParameter.PCAN_LOG_STATUS, ref iBuffer, sizeof(UInt32));
if (result != TPCANStatus.PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic.GetErrorText(result, 0, strMsg);
    Console.WriteLine(strMsg.ToString());
}

Log configuration using Windows Registry

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 SetValue method to set the PCAN_LOG_STATUS parameter 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 UInt32 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

[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.

See Also