SetValue(TPCANHandle, TPCANParameter, String, UInt32)

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
SetValue(TPCANHandle, TPCANParameter, String, UInt32)

Sets a configuration or information string value within a PCAN Channel.

Syntax
class function SetValue(
    Channel: TPCANHandle;
    Parameter: TPCANParameter;
    StringBuffer: PChar;
    BufferLength: LongWord
    ): TPCANStatus; overload;
[DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")]
public static extern TPCANStatus SetValue(
    [MarshalAs(UnmanagedType.U1)]
    TPCANHandle Channel,
    [MarshalAs(UnmanagedType.U1)]
    TPCANParameter Parameter,
    [MarshalAs(UnmanagedType.LPStr,SizeParamIndex=3)]
    string StringBuffer,
    UInt32 BufferLength);
[DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")]
static TPCANStatus SetValue(
    [MarshalAs(UnmanagedType::U1)]
    TPCANHandle Channel,
    [MarshalAs(UnmanagedType::U1)]
    TPCANParameter Parameter,
    [MarshalAs(UnmanagedType::LPStr,SizeParamIndex=3)]
    String^ StringBuffer,
    UInt32 BufferLength);
<DllImport("PCANBasic.dll", EntryPoint:="CAN_SetValue")> _
Public Shared Function SetValue( _
    <MarshalAs(UnmanagedType.U1)> _
    ByVal Channel As TPCANHandle, _
    <MarshalAs(UnmanagedType.U1)> _
    ByVal Parameter As TPCANParameter, _
    <MarshalAs(UnmanagedType.LPStr, SizeParamIndex:=3)> _
    ByVal StringBuffer As String, _
    ByVal BufferLength As UInt32) As TPCANStatus
End Function
Parameters 
Description 
Channel 
The handle of a PCAN Channel (see TPCANHandle). 
Parameter 
The code of the value to be set (see TPCANParameter). 
StringBuffer 
The buffer containing the string value to be set. 
BufferLength 
The length in bytes of the given buffer. 

The return value is a TPCANStatus code. PCAN_ERROR_OK is returned on success. The typical errors in case of failure are:

PCAN_ERROR_ILLPARAMVAL: 
Indicates that the parameters passed to the method are invalid. Check the parameter 'StringBuffer'; it should point to a valid null-terminated string buffer. 
PCAN_ERROR_CAUTION: 
The configuration of a parameter failed due to a no more existing channel. The parameter has been reset on all existing channels. 
PCAN_ERROR_INITIALIZE: 
Indicates that the given PCAN channel was not found in the list of initialized channels of the calling application. 
PCAN_ERROR_ILLPARAMTYPE: 
Indicates that the requested information is not available for the given PCAN Channel. Check the value of 'Parameter'; some values are not available for all PCAN-Channels or cannot be set. 
PCAN_ERROR_ILLOPERATION: 
An underlying process that is generated by a call to this method with the current parameters, is temporarily not allowed. The configuration in relation to the used TPCANParameter must be checked. 

Use the method SetValue to set configuration information or environment values of a PCAN Channel as parameters like the Message Filter and values like a custom entry in the log file of PCAN-Basic. Take in account that not all parameters are supported for all PCAN-Channels. The access's type of the parameters can also be different. 

More information about the parameters and values that can be set can be found in Parameter Value Definitions.

The following example shows the use of the method SetValue on the channel PCAN_NONEBUS to set (and activate) the path for the log file of a PCAN-Basic's debug session. In case of failure, the returned code will be translated to a text (according with the operating system language) in English, German, Italian, French or Spanish, and it will be shown to the user. 

Note: It is not needed to have an initialized PCAN channel for using the Log functionality. 

C#:  

TPCANStatus result;
StringBuilder strMsg;
string strBuffer;

strMsg = new StringBuilder(256);

// The path for the Log file is set.
// Note that this parameter is set using the
// default Channel (PCAN_NONEBUS)
//
strBuffer = "C:\\Users\\Admin\\Desktop";
result = PCANBasic.SetValue(PCANBasic.PCAN_NONEBUS, TPCANParameter.PCAN_LOG_LOCATION, strBuffer, (UInt32)strBuffer.Length);
if (result != TPCANStatus.PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic.GetErrorText(result, 0, strMsg);
    MessageBox.Show(strMsg.ToString());
}
else
    MessageBox.Show("Log path was successfully set");

C++/CLR:

TPCANStatus result;
StringBuilder^ strMsg;
String^ strBuffer;

strMsg = gcnew StringBuilder(256);

// The path for the Log file is set.
// Note that this parameter is set using the
// default Channel (PCAN_NONEBUS)
//
strBuffer = "C:\\Users\\Admin\\Desktop";
result = PCANBasic::SetValue(PCANBasic::PCAN_NONEBUS, TPCANParameter::PCAN_LOG_LOCATION, strBuffer, strBuffer->Length);
if (result != TPCANStatus::PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic::GetErrorText(result, 0, strMsg);
    MessageBox::Show(strMsg->ToString());
}
else
    MessageBox::Show("Log path was successfully set");

Visual Basic:

Dim result As TPCANStatus
Dim strMsg As StringBuilder
Dim strBuffer As String

strMsg = New StringBuilder(256)

' The path for the Log file is set.
' Note that this parameter is set using the
' default Channel (PCAN_NONEBUS)
'
strBuffer = "C:\Users\Admin\Desktop"
result = PCANBasic.SetValue(PCANBasic.PCAN_NONEBUS, TPCANParameter.PCAN_LOG_LOCATION, strBuffer, CType(System.Runtime.InteropServices.Marshal.SizeOf(i64Buffer), UInteger))
If result <> TPCANStatus.PCAN_ERROR_OK Then
    ' An error occurred, get a text describing the error and show it
    '
    PCANBasic.GetErrorText(result, 0, strMsg)
    MessageBox.Show(strMsg.ToString())
Else
    MessageBox.Show("Log path was successfully set")
End If

Pascal OO:

var
    result : TPCANStatus;
    strMsg: array [0..256] of Char;
    strBuffer: string;
begin
    // The path for the Log file is set.
    // Note that this parameter is set using the
    // default Channel (PCAN_NONEBUS)
    //
    strBuffer := 'C:\\Users\Keneth\Desktop';
    result := TPCANBasic.SetValue(TPCANBasic.PCAN_NONEBUS, PCAN_LOG_LOCATION, PChar(strBuffer), Length(strBuffer));
    If (result <> PCAN_ERROR_OK) Then
    begin
        // An error occurred, get a text describing the error and show it
        //
        TPCANBasic.GetErrorText(result, 0, strMsg);
        MessageBox(0, strMsg, 'Error',MB_OK);
    end
    else
        MessageBox(0, 'Log path was successfully set', 'Success',MB_OK);
Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
Send feedback to this documentation