CAN_WriteFD

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
CAN_WriteFD

Transmits a CAN message using a connected FD capable PCAN Channel.

Syntax
TPCANStatus __stdcall CAN_WriteFD(
    TPCANHandle Channel,
    TPCANMsgFD* MessageBuffer);
Parameters 
Description 
Channel 
The handle of a FD capable PCAN Channel (see TPCANHandle). 
MessageBuffer 
A TPCANMsgFD buffer containing the CAN message to be sent. 

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 function are invalid. Check the value of the MessageBuffer; it should point to a TPCANMsgFD structure. 
PCAN_ERROR_ILLOPERATION: 
Indicates that the PCAN Channel passed to the function was not initialized using CAN_InitializeFD (class-method: InitializeFD). 
PCAN_ERROR_INITIALIZE: 
Indicates that the given PCAN channel was not found in the list of initialized channels of the calling application. 
PCAN_ERROR_BUSOFF: 
Indicates a bus error within the given PCAN Channel. The hardware is in bus-off status. 
PCAN_ERROR_QXMTFULL: 
Indicates that the transmit queue of the Channel is full. 

The use of CAN_Write and CAN_WriteFD are mutually exclusive. The PCAN Channel passed to this function must be initialized using CAN_InitializeFD (class-method: InitializeFD). Otherwise the error PCAN_ERROR_ILLOPERATION is returned. 

If a bus-off error occur, an application cannot use the channel to communicate anymore, until the CAN controller is reset. With PCAN-Basic it is not possible to reset the CAN controller through a function directly. Consider using the PCAN-Basic property PCAN_BUSOFF_AUTORESET which instructs the API to automatically reset the CAN controller when a bus-off state is detected. 

Another way to reset errors like BUSOFF, BUSWARNING, and BUSPASSIVE, is to uninitialize and initialise again the channel used. This causes a hardware reset.

The following example shows the use of CAN_WriteFD on the channel PCAN_USBBUS1. 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 assumed that the channel was already initialized using CAN_InitializeFD

C++:  

TPCANMsgFD msg;
TPCANStatus result;
char strMsg[256];

// A CAN FD message is configured
//
msg.ID = 0x100;
msg.MSGTYPE = PCAN_MESSAGE_STANDARD | PCAN_MESSAGE_FD;

// DLC 9 means 12 data bytes
//
msg.DLC = 9;
for(int i=0; i < 12; i++)
    msg.DATA[i] = i;

// The message is sent using the PCAN-USB Channel 1
//
result = CAN_WriteFD(PCAN_USBBUS1, &msg);
if(result != PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    CAN_GetErrorText(result, 0, strMsg);
    MessageBox(strMsg);
}
else
    MessageBox("Message sent successfully");

CAN_InitializeFD 

CAN_ReadFD 

 

Class-method Version: WriteFD

Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
Send feedback to this documentation