WorkerTransmit(PcanMessage, PcanStatus) Method

Places a CAN message into the transmit queue of the device driver to be written as soon as possible.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public bool Transmit(
	PcanMessage message,
	out PcanStatus error
)

Parameters

message  PcanMessage
The CAN message to be written.
error  PcanStatus
In case of failure, the PcanStatus error code resulting when trying to send the message.

Return Value

Boolean
A PcanStatus value as result of the write operation

Remarks

The driver's transmit queue is 1 MB in size, which is enough to allocate up to 32.768 classic CAN messages or 13.000 CAN FD messages. This queue is constantly monitored so that any new message is processed and physically sent as fast as possible.

Example

The following example shows how to send a CAN message.

In case of failure, an error messages is written to the console output using English as output language.

C#
// Create the object using the default configuration
//
Worker myWorker = new Worker();

try
{ 
    // Activate the worker object
    //
    myWorker.Start();
    Console.WriteLine("The Worker object was activated successfully.");

    // Create a CAN message and send it
    //
    PcanMessage message = new PcanMessage(0x100, MessageType.Standard, 3, new byte[] { 1, 2, 3 }, false);
    if (myWorker.Transmit(message, out var error))
        Console.WriteLine("The message was successfully sent.");
    else
        Console.WriteLine($"The message couldn't be sent: {error}.");

    // Deactivate the worker object, when it is no longer needed
    //
    myWorker.Stop();
    Console.WriteLine("The Worker object was deactivated.");
}
catch(Exception ex)
{
    Console.WriteLine($"An exception occurred by activating the Worker object. {ex.Message}");
}

Exceptions

DllNotFoundExceptionThe underlying PCANBasic.dll library could not be found.
PcanBasicExceptionThe execution of a PCAN-Basic related check operation ended with an unexpected result. Typically, this exception is triggered when a device driver is not installed or is not up to date.

See Also