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:
Using the API
Using the Windows Registry
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:
LogLocation, to set the location of the log file.
LogConfigure, to configure the content of the log file.
LogStatus, to enable/disable logging.
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".
// 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());
}' Configures the data in the log file.
'
Dim result As PcanStatus = Api.SetValue(PcanChannel.None, PcanParameter.LogConfigure, ParameterValue.Log.All)
If result <> PcanStatus.OK Then
' An error occurred, get a text describing the error And show it
'
Dim strMsg As String = Nothing
Api.GetErrorText(result, strMsg)
Console.WriteLine(strMsg.ToString())
End If
' Configures the path of the log file.
'
result = Api.SetValue(PcanChannel.None, PcanParameter.LogLocation, "C:\\users\\admin\\desktop")
If result <> PcanStatus.OK Then
' An error occurred, get a text describing the error And show it
'
Dim strMsg As String = Nothing
Api.GetErrorText(result, strMsg)
Console.WriteLine(strMsg.ToString())
End If
' Configures the status of the log file
'
result = Api.SetValue(PcanChannel.None, PcanParameter.LogStatus, ParameterValue.Activation.On)
If result <> TPCANStatus.PCAN_ERROR_OK Then
' An error occurred, get a text describing the error And show it
'
Dim strMsg As String = Nothing
Api.GetErrorText(result, strMsg)
Console.WriteLine(strMsg.ToString())
End If// 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, 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, 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, strMsg);
Console::WriteLine(strMsg->ToString());
}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.
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.
[HKEY_CURRENT_USER\SOFTWARE\PEAK-System\PCAN-Basic\Log]
"Flags"=dword:00000007
"Path"="C:\\Users\\admin\\desktop"
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.