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 (All), and to store the log file on the desktop of an user called "admin".

C#
// Configures the data in the log file.
//
PcanStatus result = Api.SetValue(PcanChannel.None, PcanParameter.LogConfigure, ParameterValue.Log.All);
if (result != PcanStatus.OK)
{
    // An error occurred, get a text describing the error and show it
    //
    string strMsg;
    Api.GetErrorText(result, out strMsg);
    Console.WriteLine(strMsg.ToString());
}

// Configures the path of the log file.
//
result = Api.SetValue(PcanChannel.None, PcanParameter.LogLocation, "C:\\users\\admin\\desktop");
if (result != PcanStatus.OK)
{
    // An error occurred, get a text describing the error and show it
    //
    string strMsg;
    Api.GetErrorText(result, out strMsg);
    Console.WriteLine(strMsg.ToString());
}

// Configures the status of the log file
//
result = Api.SetValue(PcanChannel.None, PcanParameter.LogStatus, ParameterValue.Activation.On);
if (result != PcanStatus.OK)
{
    // An error occurred, get a text describing the error and show it
    //
    string strMsg;
    Api.GetErrorText(result, out 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 LogStatus 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 LogLocation , and LogConfigure are used. 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 ParameterValueLog values, that are wanted to be included within the logging data. The value 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

Reference

Other Resources