Using Events

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
Using Events

Event objects can be used to automatically notify a client on reception of a CAN message. This has following advantages:

  • The client program doesn't need to check periodically for received messages any longer.
  • The response time on received messages is reduced.

To use events, the client application must call the CAN_SetValue (class-method: SetValue) function to set the parameter PCAN_RECEIVE_EVENT. This parameter sets the handle for the event object. When receiving a message, the driver sets this event to the "Signaled" state. 

Another thread must be started in the client application, which waits for the event to be signaled, using one of the Win32 synchronization functions (e.g. WaitForSingleObject) without increasing the processor load. After the event is signaled, the receive buffer of the client can be read with the CAN_Read (class method: Read) function, and the CAN messages can be processed.

Tips for the creation of the event object:

  • Creation of the event as "auto-reset"
    • Trigger mode "set" (default): After the first waiting thread has been released, the event object's state changes to non-signaled. Other waiting threads are not released. If no threads are waiting, the event object's state remains signaled.
    • Trigger mode "pulse": After the first waiting thread has been released, the event object's state changes to non-signaled. Other waiting threads are not released. If no threads are waiting, or if no thread can be released immediately, the event object's state is simply set to non-signaled.
  • Creation of the event as "manual-reset"
    • Trigger mode "set" (default): The state of the event object remains signaled until it is set explicitly to the non-signaled state by the Win32 ResetEvent function. Any number of waiting threads, or threads that subsequently begin wait operations, can be released while the object's state remains signaled.
    • Trigger mode "pulse": All waiting threads that can be released immediately are released. The event object's state is then reset to the non-signaled state. If no threads are waiting, or if no thread can be released immediately, the event object's state is simply set to non-signaled.

CAN_SetValue (class-method: SetValue

CAN_Read (class-method: Read

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