ReceiveEvent

This parameter passes a thread synchronization event handle to the underlying API. This event is fired (its state is set to “signaled”) when CAN data is placed into the receive queue of a PCAN Channel.

Events are typically used when an application separates tasks into different threads. A thread, which waits for an event to occur, does not affect the normal execution of an application.

  Note

The event is fired when its state is “unsignaled” and data is received and placed in the Channel's receive queue. After an application is notified about new data, it must read the receive queue until it is empty, and finally reset the event (if using a manual reset event).

Availability

It is available since PCAN-Basic version 1.0.0.

Supported By

Access Mode

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

Linux: This parameter can only be read. It cannot be modified.

  Important

Attempting to set this parameter on Linux results in an error. Due to differences between the two platforms, the event object for use under Linux must be created and configured at initialization time by the API. To use ReceiveEvent under Linux, the event handle must simply be retrieved by calling GetValue with this parameter.

Possible Values

This parameter can be enabled/disabled by using numeric value in the range of [0...MaxValue]), that represents a pointer to a synchronization object.

Status

Value

Enabled

A 32-bit unsigned integer value representing an EventWaitHandle (AutoResetEvent or ManualResetEvent).

Disabled

The value 0.

Default Value

Windows: The default state is disabled (0).

Linux: The handle to a valid synchronization object.

Initialization Status

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

Set:

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

  • Linux: This value is read-only.

Example

The following code shows how to configure a receive event for a USB Channel on Windows and Linux systems:

C#
PcanChannel channelUsed = PcanChannel.Usb01;
System.Threading.EventWaitHandle receiveEvent = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);

if (Api.Initialize(channelUsed, Bitrate.Pcan500) == PcanStatus.OK)
{
    if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
    {

        if (Api.SetValue(channelUsed, PcanParameter.ReceiveEvent, (uint)receiveEvent.SafeWaitHandle.DangerousGetHandle().ToInt32()) == PcanStatus.OK)
        {
            Console.WriteLine($"A receive event was configured for {channelUsed}.");
        }
        else
        {
            Console.WriteLine($"Error configuring a receive event on channel {channelUsed}.");
        }
    }
    else
    {
        uint eventHandle;
        if (Api.GetValue(channelUsed, PcanParameter.ReceiveEvent, out eventHandle) == PcanStatus.OK)
        {
            receiveEvent.SafeWaitHandle.Close();
            receiveEvent.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(new IntPtr(eventHandle), false);
            Console.WriteLine($"A receive event was configured for {channelUsed}.");
        }
        else
        {
            Console.WriteLine($"Error retrieving the receive event on channel {channelUsed}.");
        }
    }

    Api.Uninitialize(channelUsed);
}

See Also