TraceLocation

This parameter is used to set the folder on a computer in where the PCAN-Trace files will be stored.

If a session is running (a PCAN-Trace file is being written), TraceLocation instructs the API to close the current PCAN-Trace file and to start the process again using the new location.

  Note

The name of the trace file cannot be freely specified. The base name of the trace file is always the name of the PCAN Channel being used, as specified in the native PCAN-Basic library (PCAN_USBBUS1.trc, for example). It is only possible to enhance the name with the date and/or time of creation of the file.

Availability

It is available since PCAN-Basic version 1.3.0.

Supported By

Access Mode

This parameter is read/write. It can be configured and retrieved.

Possible Values

This value is a string containing a fully qualified and valid path to an existing directory on the executing computer. To use the default path (calling process path) an empty string must be set.

Kind of Path

Value

Custom path

A valid directory string (see Files and Paths).

Default path (calling process folder)

An empty string.

Default Value

The default value is the path to the calling process folder.

Initialization Status

Get: The PCAN Channel must be initialized before using this parameter.

Set: The PCAN Channel must be initialized before using this parameter.

Example

The following code shows how to set the location of the trace file for a USB Channel:

C#
try
{
    PcanChannel channelUsed = PcanChannel.Usb01;

    if (Api.Initialize(channelUsed, Bitrate.Pcan500) == PcanStatus.OK)
    {
        System.IO.DirectoryInfo info = System.IO.Directory.CreateDirectory(System.IO.Path.GetTempPath() + "Tracing_" + DateTime.Now.Date.ToString("yyyy.mm.dd"));
        if (Api.SetValue(channelUsed, PcanParameter.TraceLocation, info.FullName) == PcanStatus.OK)
        {
            Console.WriteLine($"The folder for trace files was successfully set to:\n{info.FullName}");
        }
        else
        {
            Console.WriteLine("Error configuring the location of the trace files.");
        }
        Api.Uninitialize(channelUsed);
    }
}
catch (Exception ex)
{
    Console.WriteLine($"Error creating a folder: {ex.Message}.");
}

See Also