Event Classes
PySpin provides an event-driven interface for responding to camera and system
notifications asynchronously. Rather than polling for state changes, you
register a handler subclass with the relevant camera or system object and
override the appropriate callback method. The SDK will invoke your handler on
a dedicated internal thread whenever the corresponding event fires.
The available handler categories are:
Device events – camera-level hardware notifications (arrival, removal,
and device-specific GenICam events).
Image events – called each time a new image or image list is ready for
processing without calling GetNextImage().
Interface events – fired when a network or USB interface appears or
disappears on the host.
Logging events – route Spinnaker’s internal log messages to your own
handler for diagnostics or structured logging.
System events – top-level notifications dispatched by the
System singleton.
Usage pattern:
import PySpin
class MyImageHandler(PySpin.ImageEventHandler):
def OnImageEvent(self, image):
print(f"Received image {image.GetFrameID()}")
system = PySpin.System.GetInstance()
cam_list = system.GetCameras()
cam = cam_list[0]
cam.Init()
handler = MyImageHandler()
cam.RegisterEventHandler(handler)
cam.BeginAcquisition()
# ... handler fires automatically for each new image ...
cam.EndAcquisition()
cam.UnregisterEventHandler(handler)
cam.DeInit()
cam_list.Clear()
system.ReleaseInstance()
Note
Always call UnregisterEventHandler() before
DeInit() to avoid callbacks firing on a partially
torn-down camera object.
PySpin.DeviceArrivalEventHandler
-
class DeviceArrivalEventHandler
An event handler for capturing the device arrival event.
-
OnDeviceArrival(self, pCamera)
-
Parameters
pCamera: Spinnaker::CameraPtr
Callback to the device arrival event.
- param pCamera:
Reference tracked CameraPtr object of the camera attached to the system
PySpin.DeviceEventHandler
-
class DeviceEventHandler
A handler to device events.
Deprecated Use GenApi::Register() and GenApi::Unregister() for
handling device node callbacks instead.
-
GetDeviceEventId(self) → uint64_t
Get the ID of the device event.
The device event ID
-
GetDeviceEventName(self) → gcstring
Get the name of the device event.
The device event name
-
OnDeviceEvent(self, eventName)
-
Parameters
eventName: Spinnaker::GenICam::gcstring
Device event callback.
- param eventName:
The name of the event
PySpin.DeviceRemovalEventHandler
-
class DeviceRemovalEventHandler
An event handler for capturing the device removal event.
-
OnDeviceRemoval(self, pCamera)
-
Parameters
pCamera: Spinnaker::CameraPtr
Device removal event callback.
- param pCamera:
Reference tracked CameraPtr object of the camera removed from the system
PySpin.EventHandler
-
class EventHandler(*args, **kwargs)
The base class for all event handler types.
-
GetEventPayloadData(self) → PyObject *
Gets the event payload data
The event payload data
-
GetEventPayloadDataSize(self) → size_t const
Gets the event payload data size
The event payload data size
-
GetEventType(self) → Spinnaker::EventType
Gets the event type
The event type
-
SetEventType(self, eventType)
-
Parameters
eventType: enum Spinnaker::EventType
Sets the event type
- param eventType:
The event type
PySpin.ImageEventHandler
-
class ImageEventHandler
A handler for capturing image arrival events.
-
OnImageEvent(self, image)
-
Parameters
image: Spinnaker::ImagePtr
PySpin.ImageListEventHandler
-
class ImageListEventHandler
A handler for capturing image list arrival events.
-
OnImageListEvent(self, imageList)
-
Parameters
imageList: Spinnaker::ImageList
PySpin.InterfaceArrivalEventHandler
-
class InterfaceArrivalEventHandler
An event handler for capturing the interface arrival event. Note that
only GEV interface arrivals are currently handled.
-
OnInterfaceArrival(self, pInterface)
-
Parameters
pInterface: Spinnaker::InterfacePtr
Interface arrival event callback. Note that only GEV interface
arrivals are currently handled.
- param pInterface:
Reference tracked pointer to Interface object of the adapter attached to the system
PySpin.InterfaceEventHandler
-
class InterfaceEventHandler
A handler to device arrival and removal events on all interfaces.
-
OnDeviceArrival(self, pCamera)
-
Parameters
pCamera: Spinnaker::CameraPtr
Device arrival event callback.
- param pCamera:
Reference tracked pointer to Camera object of the device attached to the system
-
OnDeviceRemoval(self, pCamera)
-
Parameters
pCamera: Spinnaker::CameraPtr
Callback to the device removal event.
- param pCamera:
Reference tracked pointer to Camera object of the device removed from the system
PySpin.InterfaceRemovalEventHandler
-
class InterfaceRemovalEventHandler
An event handler for capturing the interface removal event. Note that
only GEV interface removals are currently handled.
-
OnInterfaceRemoval(self, pInterface)
-
Parameters
pInterface: Spinnaker::InterfacePtr
Interface removal event callback. Note that only GEV interface
removals are currently handled.
- param pInterface:
Reference tracked pointer to Interface object of the adapter removed from the system
PySpin.LoggingEventHandler
-
class LoggingEventHandler
An event handler for capturing the device logging event.
-
OnLogEvent(self, eventPtr)
-
Parameters
eventPtr: Spinnaker::LoggingEventDataPtr
The callback for the log event.
- param eventPtr:
The logging event pointer
PySpin.LoggingEventDataPtr
-
class LoggingEventDataPtr(*args)
A reference tracked pointer to the LoggingEvent object.
PySpin.SystemEventHandler
-
class SystemEventHandler
A handler to interface arrival and removal events on the system. Note
that only GEV interface arrivals and removals are currently handled.
-
OnInterfaceArrival(self, pInterface)
-
Parameters
pInterface: Spinnaker::InterfacePtr
Interface arrival event callback. Note that only GEV interface
arrivals are currently handled.
- param pInterface:
Reference tracked pointer to Interface object of the adapter attached to the system
-
OnInterfaceRemoval(self, pInterface)
-
Parameters
pInterface: Spinnaker::InterfacePtr
Interface removal event callback. Note that only GEV interface
removals are currently handled.
- param pInterface:
Reference tracked pointer to Interface object of the adapter removed from the system