-
-
Save xiaoqiangwang/671f4da4614e5b5024bc2fe4480d4283 to your computer and use it in GitHub Desktop.
import re | |
import sys | |
from cffi import FFI | |
ffi = FFI() | |
ffi.cdef(""" | |
typedef uint8_t bool8_t; | |
/* Errors */ | |
enum GC_ERROR_LIST | |
{ | |
GC_ERR_SUCCESS = 0, | |
GC_ERR_ERROR = -1001, | |
GC_ERR_NOT_INITIALIZED = -1002, | |
GC_ERR_NOT_IMPLEMENTED = -1003, | |
GC_ERR_RESOURCE_IN_USE = -1004, | |
GC_ERR_ACCESS_DENIED = -1005, | |
GC_ERR_INVALID_HANDLE = -1006, | |
GC_ERR_INVALID_ID = -1007, | |
GC_ERR_NO_DATA = -1008, | |
GC_ERR_INVALID_PARAMETER = -1009, | |
GC_ERR_IO = -1010, | |
GC_ERR_TIMEOUT = -1011, | |
GC_ERR_ABORT = -1012, /* GenTL v1.1 */ | |
GC_ERR_INVALID_BUFFER = -1013, /* GenTL v1.1 */ | |
GC_ERR_NOT_AVAILABLE = -1014, /* GenTL v1.2 */ | |
GC_ERR_INVALID_ADDRESS = -1015, /* GenTL v1.3 */ | |
GC_ERR_BUFFER_TOO_SMALL = -1016, /* GenTL v1.4 */ | |
GC_ERR_INVALID_INDEX = -1017, /* GenTL v1.4 */ | |
GC_ERR_PARSING_CHUNK_DATA = -1018, /* GenTL v1.4 */ | |
GC_ERR_INVALID_VALUE = -1019, /* GenTL v1.4 */ | |
GC_ERR_RESOURCE_EXHAUSTED = -1020, /* GenTL v1.4 */ | |
GC_ERR_OUT_OF_MEMORY = -1021, /* GenTL v1.4 */ | |
GC_ERR_BUSY = -1022, /* GenTL v1.5 */ | |
GC_ERR_CUSTOM_ID = -10000 | |
}; | |
typedef int32_t GC_ERROR; | |
/* Handles */ | |
typedef GC_ERROR * TL_HANDLE; /* Transport Layer handle, obtained through the TLOpen */ | |
typedef GC_ERROR * IF_HANDLE; /* Interface handle, obtained through ::TLOpenInterface */ | |
typedef GC_ERROR * DEV_HANDLE; /* Device Handle, obtained through the ::IFOpenDevice */ | |
typedef GC_ERROR * DS_HANDLE; /* Handle to an image stream object, obtained through DevOpenDataStream */ | |
typedef GC_ERROR * PORT_HANDLE; /* A Port handle is used to access the register space of a port */ | |
/* a PORT_HANDLE can be one of the following TL_HANDLE, IF_HANDLE, */ | |
/* DEV_HANDLE, handle to a device port, obtained through ::DevGetPort, */ | |
/* DS_HANDLE, BUFFER_HANDLE */ | |
typedef GC_ERROR * BUFFER_HANDLE; /* BufferHandle, obtained through the ::DSAnnounceBuffer function */ | |
typedef GC_ERROR * EVENTSRC_HANDLE; /* A Event source handle is used to register a OS Event and to retrieve a GenTL event handle */ | |
/* a EVENTSRC_HANDLE can be on of the following TL_HANDLE, */ | |
/* IF_HANDLE, DEV_HANDLE, A handle to a device port, obtained through ::DevGetPort */ | |
/* DS_HANDLE, BUFFER_HANDLE */ | |
typedef GC_ERROR * EVENT_HANDLE; /* Event Handle */ | |
/* Defines the data type possible for the various Info functions. */ | |
enum INFO_DATATYPE_LIST | |
{ | |
INFO_DATATYPE_UNKNOWN = 0, /* Unknown data type */ | |
INFO_DATATYPE_STRING = 1, /* NULL-terminated C string (ASCII encoded). */ | |
INFO_DATATYPE_STRINGLIST = 2, /* Concatenated INFO_DATATYPE_STRING list. End of list is signaled with an additional NULL. */ | |
INFO_DATATYPE_INT16 = 3, /* Signed 16 bit integer. */ | |
INFO_DATATYPE_UINT16 = 4, /* Unsigned 16 bit integer */ | |
INFO_DATATYPE_INT32 = 5, /* Signed 32 bit integer */ | |
INFO_DATATYPE_UINT32 = 6, /* Unsigned 32 bit integer */ | |
INFO_DATATYPE_INT64 = 7, /* Signed 64 bit integer */ | |
INFO_DATATYPE_UINT64 = 8, /* Unsigned 64 bit integer */ | |
INFO_DATATYPE_FLOAT64 = 9, /* Signed 64 bit floating point number. */ | |
INFO_DATATYPE_PTR = 10, /* Pointer type (GC_ERROR*). Size is platform dependent (32 bit on 32 bit platforms). */ | |
INFO_DATATYPE_BOOL8 = 11, /* Boolean value occupying 8 bit. 0 for false and anything for true. */ | |
INFO_DATATYPE_SIZET = 12, /* Platform dependent unsigned integer (32 bit on 32 bit platforms). */ | |
INFO_DATATYPE_BUFFER = 13, /* Like a INFO_DATATYPE_STRING but with arbitrary data and no NULL termination. */ | |
INFO_DATATYPE_PTRDIFF = 14, /* Platform dependent signed integer (32 bit on 32 bit platforms). GenTL v1.3 */ | |
INFO_DATATYPE_CUSTOM_ID = 1000 /* Starting value for custom IDs. */ | |
}; | |
typedef int32_t INFO_DATATYPE; | |
/* Defines char encoding schemes used by the producer, GenTL v1.4 */ | |
enum TL_CHAR_ENCODING_LIST | |
{ | |
TL_CHAR_ENCODING_ASCII = 0, | |
TL_CHAR_ENCODING_UTF8 = 1 | |
}; | |
typedef int32_t TL_CHAR_ENCODING; /* GenTL v1.4 */ | |
/* System module information commands for the GenICam::TL::Client::TLGetInfo and GenICam::TL::Client::GCGetInfo functions. */ | |
enum TL_INFO_CMD_LIST | |
{ | |
TL_INFO_ID = 0, /* STRING Transport layer ID. */ | |
TL_INFO_VENDOR = 1, /* STRING Transport layer vendor name. */ | |
TL_INFO_MODEL = 2, /* STRING Transport layer model name. */ | |
TL_INFO_VERSION = 3, /* STRING Transport layer version. */ | |
TL_INFO_TLTYPE = 4, /* STRING Transport layer technology that is supported. */ | |
TL_INFO_NAME = 5, /* STRING File name including extension of the library. */ | |
TL_INFO_PATHNAME = 6, /* STRING Full path including file name and extension of the library. */ | |
TL_INFO_DISPLAYNAME = 7, /* STRING User readable name of the device. If this is not defined in the device this should be VENDOR MODEL (ID). */ | |
TL_INFO_CHAR_ENCODING = 8, /* INT32 Reporting the char encoding used by this Producer, GenTL v1.4 */ | |
TL_INFO_GENTL_VER_MAJOR = 9, /* UINT32 Major number of the GenTL spec this producer complies with, GenTL v1.5 */ | |
TL_INFO_GENTL_VER_MINOR = 10, /* UINT32 Minor number of the GenTL spec this producer complies with, GenTL v1.5 */ | |
TL_INFO_CUSTOM_ID = 1000 /* Starting value for custom IDs. */ | |
}; | |
typedef int32_t TL_INFO_CMD; | |
/* This enumeration defines commands to retrieve information with the GenICam::TL::Client::IFGetInfo function from the Interface module. */ | |
enum INTERFACE_INFO_CMD_LIST | |
{ | |
INTERFACE_INFO_ID = 0, /* STRING Unique ID of the interface. */ | |
INTERFACE_INFO_DISPLAYNAME = 1, /* STRING User readable name of the interface. */ | |
INTERFACE_INFO_TLTYPE = 2, /* STRING Transport layer technology that is supported. */ | |
INTERFACE_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t INTERFACE_INFO_CMD; | |
/* This enumeration defines flags of how a device is to be opened with the GenICam::TL::Client::IFOpenDevice function. */ | |
enum DEVICE_ACCESS_FLAGS_LIST | |
{ | |
DEVICE_ACCESS_UNKNOWN = 0, /* Not used in a command. Can be used to initialize a variable to query that information. */ | |
DEVICE_ACCESS_NONE = 1, /* This either means that the device is not open because it was not opened before or the access to it was denied. */ | |
DEVICE_ACCESS_READONLY = 2, /* Open the device read only. All Port functions can only read from the device. */ | |
DEVICE_ACCESS_CONTROL = 3, /* Open the device in a way that other hosts/processes can have read only access to the device. Device access level is read/write for this process. */ | |
DEVICE_ACCESS_EXCLUSIVE = 4, /* Open the device in a way that only this host/process can have access to the device. Device access level is read/write for this process. */ | |
DEVICE_ACCESS_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t DEVICE_ACCESS_FLAGS; | |
/* This enumeration defines values for the accessibility of the device to be returned in the GenICam::TL::Client::DevGetInfo function on a device handle. */ | |
enum DEVICE_ACCESS_STATUS_LIST | |
{ | |
DEVICE_ACCESS_STATUS_UNKNOWN = 0, /* The device accessibility is not known. */ | |
DEVICE_ACCESS_STATUS_READWRITE = 1, /* The device is available for read/write access. */ | |
DEVICE_ACCESS_STATUS_READONLY = 2, /* The device is available for read only access. */ | |
DEVICE_ACCESS_STATUS_NOACCESS = 3, /* The device is not accessible. */ | |
DEVICE_ACCESS_STATUS_BUSY = 4, /* The device has already been opened by another process/host. GenTL v1.5 */ | |
DEVICE_ACCESS_STATUS_OPEN_READWRITE = 5, /* The device has already been opened by this process. GenTL v1.5 */ | |
DEVICE_ACCESS_STATUS_OPEN_READONLY = 6, /* The device has already been opened by this process. GenTL v1.5 */ | |
DEVICE_ACCESS_STATUS_CUSTOM_ID = 1000 /* Starting value for custom IDs. */ | |
}; | |
typedef int32_t DEVICE_ACCESS_STATUS; | |
/* This enumeration defines commands to retrieve information with the GenICam::TL::Client::DevGetInfo function on a device handle. */ | |
enum DEVICE_INFO_CMD_LIST | |
{ | |
DEVICE_INFO_ID = 0, /* STRING Unique ID of the device. */ | |
DEVICE_INFO_VENDOR = 1, /* STRING Device vendor name. */ | |
DEVICE_INFO_MODEL = 2, /* STRING Device model name. */ | |
DEVICE_INFO_TLTYPE = 3, /* STRING Transport layer technology that is supported. */ | |
DEVICE_INFO_DISPLAYNAME = 4, /* STRING String containing a display name for the device ( including a unique id ) */ | |
DEVICE_INFO_ACCESS_STATUS = 5, /* INT32 Gets the access mode the GenTL Producer has on the opened device. (DEVICE_ACCESS_STATUS enumeration value). */ | |
DEVICE_INFO_USER_DEFINED_NAME = 6, /* STRING String containing the user defined name, GenTL v1.4 */ | |
DEVICE_INFO_SERIAL_NUMBER = 7, /* STRING String containing the device's serial number, GenTL v1.4 */ | |
DEVICE_INFO_VERSION = 8, /* STRING String containing the device version, GenTL v1.4 */ | |
DEVICE_INFO_TIMESTAMP_FREQUENCY = 9, /* UINT64 Tick-frequency of the time stamp clock, GenTL v1.4 */ | |
DEVICE_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t DEVICE_INFO_CMD; | |
/* This enumeration defines special stop flags for the acquisition engine. The function used is GenICam::TL::Client::DSStopAcquisition. */ | |
enum ACQ_STOP_FLAGS_LIST | |
{ | |
ACQ_STOP_FLAGS_DEFAULT = 0, /* Stop the acquisition engine when the currently running tasks like filling a buffer are completed (default behavior). */ | |
ACQ_STOP_FLAGS_KILL = 1, /* Stop the acquisition engine immediately and leave buffers currently being filled in the Input Buffer Pool. */ | |
ACQ_STOP_FLAGS_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t ACQ_STOP_FLAGS; | |
/* This enumeration defines special start flags for the acquisition engine. The function used is GenICam::TL::Client::DSStartAcquisition. */ | |
enum ACQ_START_FLAGS_LIST | |
{ | |
ACQ_START_FLAGS_DEFAULT = 0, /* Default behavior. */ | |
ACQ_START_FLAGS_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t ACQ_START_FLAGS; | |
/* This enumeration commands from which to which queue/pool buffers are flushed with the GenICam::TL::Client::DSFlushQueue function. */ | |
enum ACQ_QUEUE_TYPE_LIST | |
{ | |
ACQ_QUEUE_INPUT_TO_OUTPUT = 0, /* Flushes the input pool to the output queue and if necessary adds entries in the New Buffer event data queue. */ | |
ACQ_QUEUE_OUTPUT_DISCARD = 1, /* Discards all buffers in the output queue and if necessary remove the entries from the event data queue. */ | |
ACQ_QUEUE_ALL_TO_INPUT = 2, /* Puts all buffers in the input pool. Even those in the output queue and discard entries in the event data queue. */ | |
ACQ_QUEUE_UNQUEUED_TO_INPUT = 3, /* Puts all buffers that are not in the input pool or the output queue in the input pool. */ | |
ACQ_QUEUE_ALL_DISCARD = 4, /* Discards all buffers in the input pool and output queue. */ | |
ACQ_QUEUE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t ACQ_QUEUE_TYPE; | |
/* This enumeration defines commands to retrieve information with the GenICam::TL::Client::DSGetInfo function on a data stream handle */ | |
enum STREAM_INFO_CMD_LIST | |
{ | |
STREAM_INFO_ID = 0, /* STRING Unique ID of the data stream. */ | |
STREAM_INFO_NUM_DELIVERED = 1, /* UINT64 Number of delivered buffers since last acquisition start. */ | |
STREAM_INFO_NUM_UNDERRUN = 2, /* UINT64 Number of lost buffers due to queue underrun. */ | |
STREAM_INFO_NUM_ANNOUNCED = 3, /* SIZET Number of announced buffers. */ | |
STREAM_INFO_NUM_QUEUED = 4, /* SIZET Number of buffers in the input pool. */ | |
STREAM_INFO_NUM_AWAIT_DELIVERY = 5, /* SIZET Number of buffers in the output queue. */ | |
STREAM_INFO_NUM_STARTED = 6, /* UINT64 Number of buffers started in the acquisition engine. */ | |
STREAM_INFO_PAYLOAD_SIZE = 7, /* SIZET Size of the expected data in bytes. */ | |
STREAM_INFO_IS_GRABBING = 8, /* BOOL8 Flag indicating whether the acquisition engine is started or not. */ | |
STREAM_INFO_DEFINES_PAYLOADSIZE = 9, /* BOOL8 Flag that indicated that this data stream defines a payload size independent from the remote device. */ | |
STREAM_INFO_TLTYPE = 10, /* STRING Transport layer technology that is supported. */ | |
STREAM_INFO_NUM_CHUNKS_MAX = 11, /* SIZET Max number of chunks in a buffer, if known. GenTL v1.3 */ | |
STREAM_INFO_BUF_ANNOUNCE_MIN = 12, /* SIZET Min number of buffers to announce before acq can start, if known. GenTL v1.3 */ | |
STREAM_INFO_BUF_ALIGNMENT = 13, /* SIZET Buffer alignment in bytes. GenTL v1.3 */ | |
STREAM_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t STREAM_INFO_CMD; | |
/* This enumeration defines commands to retrieve information with the GenICam::TL::Client::DSGetBufferInfo function on a buffer handle. */ | |
enum BUFFER_INFO_CMD_LIST | |
{ | |
BUFFER_INFO_BASE = 0, /* PTR Base address of the buffer memory. */ | |
BUFFER_INFO_SIZE = 1, /* SIZET Size of the buffer in bytes. */ | |
BUFFER_INFO_USER_PTR = 2, /* PTR Private data pointer of the GenTL Consumer. */ | |
BUFFER_INFO_TIMESTAMP = 3, /* UINT64 Timestamp the buffer was acquired. */ | |
BUFFER_INFO_NEW_DATA = 4, /* BOOL8 Flag to indicate that the buffer contains new data since the last call. */ | |
BUFFER_INFO_IS_QUEUED = 5, /* BOOL8 Flag to indicate if the buffer is in the input pool or output queue. */ | |
BUFFER_INFO_IS_ACQUIRING = 6, /* BOOL8 Flag to indicate that the buffer is currently being filled with data. */ | |
BUFFER_INFO_IS_INCOMPLETE = 7, /* BOOL8 Flag to indicate that a buffer was filled but an error occurred during that process. */ | |
BUFFER_INFO_TLTYPE = 8, /* STRING Transport layer technology that is supported. */ | |
BUFFER_INFO_SIZE_FILLED = 9, /* SIZET Number of bytes written into the buffer last time it has been filled. This value is reset to 0 when the buffer is placed into the Input Buffer Pool. */ | |
BUFFER_INFO_WIDTH = 10, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_HEIGHT = 11, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_XOFFSET = 12, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_YOFFSET = 13, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_XPADDING = 14, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_YPADDING = 15, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_FRAMEID = 16, /* UINT64 GenTL v1.2 */ | |
BUFFER_INFO_IMAGEPRESENT = 17, /* BOOL8 GenTL v1.2 */ | |
BUFFER_INFO_IMAGEOFFSET = 18, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_PAYLOADTYPE = 19, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_PIXELFORMAT = 20, /* UINT64 GenTL v1.2 */ | |
BUFFER_INFO_PIXELFORMAT_NAMESPACE = 21, /* UINT64 GenTL v1.2 */ | |
BUFFER_INFO_DELIVERED_IMAGEHEIGHT = 22, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_DELIVERED_CHUNKPAYLOADSIZE = 23, /* SIZET GenTL v1.2 */ | |
BUFFER_INFO_CHUNKLAYOUTID = 24, /* UINT64 GenTL v1.2 */ | |
BUFFER_INFO_FILENAME = 25, /* STRING GenTL v1.2 */ | |
BUFFER_INFO_PIXEL_ENDIANNESS = 26, /* INT32 GenTL v1.4 */ | |
BUFFER_INFO_DATA_SIZE = 27, /* SIZET GenTL v1.4 */ | |
BUFFER_INFO_TIMESTAMP_NS = 28, /* UINT64 GenTL v1.4 */ | |
BUFFER_INFO_DATA_LARGER_THAN_BUFFER = 29, /* BOOL8 GenTL v1.4 */ | |
BUFFER_INFO_CONTAINS_CHUNKDATA = 30, /* BOOL8 GenTL v1.4 */ | |
BUFFER_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t BUFFER_INFO_CMD; | |
/* This enumeration defines commands to retrieve information about individual data parts in a multi-part buffer | |
using the GenICam::TL::Client::DSGetBufferPartInfo function. Introduced in GenTL v1.5. */ | |
enum BUFFER_PART_INFO_CMD_LIST | |
{ | |
BUFFER_PART_INFO_BASE = 0, /* PTR Base address of the buffer part memory. */ | |
BUFFER_PART_INFO_DATA_SIZE = 1, /* SIZET Size of the buffer part in bytes. */ | |
BUFFER_PART_INFO_DATA_TYPE = 2, /* SIZET Type of the data in given part (PARTDATATYPE_ID enumeration value). */ | |
BUFFER_PART_INFO_DATA_FORMAT = 3, /* UINT64 Format of individual items (such as pixels) in the buffer part. */ | |
BUFFER_PART_INFO_DATA_FORMAT_NAMESPACE = 4, /* UINT64 Allows interpretation of BUFFER_PART_INFO_DATA_FORMAT (PIXELFORMAT_NAMESPACE_ID enumeration value). */ | |
BUFFER_PART_INFO_WIDTH = 5, /* SIZET Width of data in the buffer part in pixels. */ | |
BUFFER_PART_INFO_HEIGHT = 6, /* SIZET Expected height of data in the buffer part in pixels . */ | |
BUFFER_PART_INFO_XOFFSET = 7, /* SIZET Horizontal offset of data in the buffer part in pixels. */ | |
BUFFER_PART_INFO_YOFFSET = 8, /* SIZET Vertical offset of data in the buffer part in pixels. */ | |
BUFFER_PART_INFO_XPADDING = 9, /* SIZET Horizontal padding of data in the buffer part in pixels. */ | |
BUFFER_PART_INFO_SOURCE_ID = 10, /* UINT64 Identifier allowing to group data parts belonging to the same source. */ | |
BUFFER_PART_INFO_DELIVERED_IMAGEHEIGHT = 11, /* SIZET Height of the data currently in the buffer part in pixels*/ | |
BUFFER_PART_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t BUFFER_PART_INFO_CMD; /* GenTL v1.5 */ | |
/* Enumeration of TLType dependent payload types. Introduced in GenTL v1.2 */ | |
enum PAYLOADTYPE_INFO_IDS | |
{ | |
PAYLOAD_TYPE_UNKNOWN = 0, /* GenTL v1.2 */ | |
PAYLOAD_TYPE_IMAGE = 1, /* GenTL v1.2 */ | |
PAYLOAD_TYPE_RAW_DATA = 2, /* GenTL v1.2 */ | |
PAYLOAD_TYPE_FILE = 3, /* GenTL v1.2 */ | |
PAYLOAD_TYPE_CHUNK_DATA = 4, /* GenTL v1.2, Deprecated in GenTL 1.5*/ | |
PAYLOAD_TYPE_JPEG = 5, /* GenTL v1.4 */ | |
PAYLOAD_TYPE_JPEG2000 = 6, /* GenTL v1.4 */ | |
PAYLOAD_TYPE_H264 = 7, /* GenTL v1.4 */ | |
PAYLOAD_TYPE_CHUNK_ONLY = 8, /* GenTL v1.4 */ | |
PAYLOAD_TYPE_DEVICE_SPECIFIC = 9, /* GenTL v1.4 */ | |
PAYLOAD_TYPE_MULTI_PART = 10, /* GenTL v1.5 */ | |
PAYLOAD_TYPE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t PAYLOADTYPE_INFO_ID; | |
/* Enumeration of TLType dependent pixel format namespaces introduced GenTL v1.2 */ | |
enum PIXELFORMAT_NAMESPACE_IDS | |
{ | |
PIXELFORMAT_NAMESPACE_UNKNOWN = 0, /* GenTL v1.2 */ | |
PIXELFORMAT_NAMESPACE_GEV = 1, /* GenTL v1.2 */ | |
PIXELFORMAT_NAMESPACE_IIDC = 2, /* GenTL v1.2 */ | |
PIXELFORMAT_NAMESPACE_PFNC_16BIT = 3, /* GenTL v1.4 */ | |
PIXELFORMAT_NAMESPACE_PFNC_32BIT = 4, /* GenTL v1.4 */ | |
PIXELFORMAT_NAMESPACE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t PIXELFORMAT_NAMESPACE_ID; /* GenTL v1.2 */ | |
/* Enumeration of pixel endianness values. Introduced in GenTL v1.4 */ | |
enum PIXELENDIANNESS_IDS | |
{ | |
PIXELENDIANNESS_UNKNOWN = 0, /* Unknown pixel endianness. GenTL v1.4 */ | |
PIXELENDIANNESS_LITTLE = 1, /* Little endian pixel data. GenTL v1.4 */ | |
PIXELENDIANNESS_BIG = 2 /* Big endian pixel data. GenTL v1.4 */ | |
}; | |
typedef int32_t PIXELENDIANNESS_ID; /* GenTL v1.4*/ | |
/* Enumeration describing which data type is present in given buffer part. Introduced in GenTL v1.5 */ | |
enum PARTDATATYPE_IDS | |
{ | |
PART_DATATYPE_UNKNOWN = 0, /* Unknown data type */ | |
PART_DATATYPE_2D_IMAGE = 1, /* Color or monochrome 2D image. */ | |
PART_DATATYPE_2D_PLANE_BIPLANAR = 2, /* Single color plane of a planar 2D image consisting of 2 planes. */ | |
PART_DATATYPE_2D_PLANE_TRIPLANAR = 3, /* Single color plane of a planar 2D image consisting of 3 planes. */ | |
PART_DATATYPE_2D_PLANE_QUADPLANAR = 4, /* Single color plane of a planar 2D image consisting of 4 planes. */ | |
PART_DATATYPE_3D_IMAGE = 5, /* 3D image (pixel coordinates). */ | |
PART_DATATYPE_3D_PLANE_BIPLANAR = 6, /* Single plane of a planar 3D image consisting of 2 planes. */ | |
PART_DATATYPE_3D_PLANE_TRIPLANAR = 7, /* Single plane of a planar 3D image consisting of 3 planes. */ | |
PART_DATATYPE_3D_PLANE_QUADPLANAR = 8, /* Single plane of a planar 3D image consisting of 4 planes. */ | |
PART_DATATYPE_CONFIDENCE_MAP = 9, /* Confidence of the individual pixel values. */ | |
PART_DATATYPE_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t PARTDATATYPE_ID; /* GenTL v1.5*/ | |
/* This enumeration defines commands to retrieve information with the GenICam::TL::Client::GCGetPortInfo function on a module or remote device handle. */ | |
enum PORT_INFO_CMD_LIST | |
{ | |
PORT_INFO_ID = 0, /* STRING Unique ID of the port. */ | |
PORT_INFO_VENDOR = 1, /* STRING Port vendor name. */ | |
PORT_INFO_MODEL = 2, /* STRING Port model name. */ | |
PORT_INFO_TLTYPE = 3, /* STRING Transport layer technology that is supported. */ | |
PORT_INFO_MODULE = 4, /* STRING GenTL Module the port refers to. */ | |
PORT_INFO_LITTLE_ENDIAN = 5, /* BOOL8 Flag indicating that the port data is little endian. */ | |
PORT_INFO_BIG_ENDIAN = 6, /* BOOL8 Flag indicating that the port data is big endian. */ | |
PORT_INFO_ACCESS_READ = 7, /* BOOL8 Port has read access. */ | |
PORT_INFO_ACCESS_WRITE = 8, /* BOOL8 Port has write access. */ | |
PORT_INFO_ACCESS_NA = 9, /* BOOL8 Port is not accessible. */ | |
PORT_INFO_ACCESS_NI = 10, /* BOOL8 Port is not implemented. */ | |
PORT_INFO_VERSION = 11, /* STRING Version of the port. */ | |
PORT_INFO_PORTNAME = 12, /* STRING Name of the port as referenced in the XML description. */ | |
PORT_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t PORT_INFO_CMD; | |
/* This enumeration defines enum values returned by the URL_INFO_SCHEME command. | |
introduced in GenTL v1.5 */ | |
enum URL_SCHEME_IDS | |
{ | |
URL_SCHEME_LOCAL = 0, /* The XML can be read from the local register map */ | |
URL_SCHEME_HTTP = 1, /* The XML can be downloaded from a http server */ | |
URL_SCHEME_FILE = 2, /* The XML can be read from the local hard drive */ | |
URL_SCHEME_CUSTOM_ID = 1000 /* Starting value for custom scheme locations */ | |
}; | |
typedef int32_t URL_SCHEME_ID; | |
/* This enumeration defines commands to retrieve information with the GenICam::TL::Client::GCGetPortURLInfo | |
function on a module or remote device handle. Introduced in GenTL v1.1 */ | |
enum URL_INFO_CMD_LIST | |
{ | |
URL_INFO_URL = 0, /* STRING URL as defined in chapter 4.1.2 GenTL v1.1 */ | |
URL_INFO_SCHEMA_VER_MAJOR = 1, /* INT32 Major version of the schema this URL refers to. GenTL v1.1 */ | |
URL_INFO_SCHEMA_VER_MINOR = 2, /* INT32 Minor version of the schema this URL refers to. GenTL v1.1 */ | |
URL_INFO_FILE_VER_MAJOR = 3, /* INT32 Major version of the XML-file this URL refers to. GenTL v1.1 */ | |
URL_INFO_FILE_VER_MINOR = 4, /* INT32 Minor version of the XML-file this URL refers to. GenTL v1.1 */ | |
URL_INFO_FILE_VER_SUBMINOR = 5, /* INT32 Subminor version of the XML-file this URL refers to. GenTL v1.1 */ | |
URL_INFO_FILE_SHA1_HASH = 6, /* BUFFER 160-bit SHA1 Hash code of XML-file. GenTL v1.4 */ | |
URL_INFO_FILE_REGISTER_ADDRESS = 7, /* UINT64 Register address in the device's register map. GenTL v1.5 */ | |
URL_INFO_FILE_SIZE = 8, /* UINT64 File size in bytes. GenTL v1.5 */ | |
URL_INFO_SCHEME = 9, /* INT32 Scheme of the URL as defined in URL_SCHEME_IDS. GenTL v1.5 */ | |
URL_INFO_FILENAME = 10, /* STRING File name if the scheme of the URL is file. GenTL v1.5 */ | |
URL_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t URL_INFO_CMD; /* GenTL v1.1 */ | |
/* Known event types that can be registered on certain modules with the GenICam::TL::Client::GCRegisterEvent function. */ | |
enum EVENT_TYPE_LIST | |
{ | |
EVENT_ERROR = 0, /* Notification on module errors. */ | |
EVENT_NEW_BUFFER = 1, /* Notification on newly filled buffers. */ | |
EVENT_FEATURE_INVALIDATE = 2, /* Notification if a feature was changed by the GenTL Producer library and thus needs to be invalidated in the GenICam GenApi instance using the module. */ | |
EVENT_FEATURE_CHANGE = 3, /* Notification if the GenTL Producer library wants to manually set a feature in the GenICam GenApi instance using the module. */ | |
EVENT_REMOTE_DEVICE = 4, /* Notification if the GenTL Producer wants to inform the GenICam GenApi instance of the remote device that a GenApi compatible event was fired. */ | |
EVENT_MODULE = 5, /* Notification if the GenTL Producer wants to inform the GenICam GenApi instance of the module that a GenApi compatible event was fired. GenTL v1.4 */ | |
EVENT_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t EVENT_TYPE; | |
/* Event info command */ | |
enum EVENT_INFO_CMD_LIST | |
{ | |
EVENT_EVENT_TYPE = 0, /* INT32 The event type of the event handle (EVENT_TYPE enum value). */ | |
EVENT_NUM_IN_QUEUE = 1, /* SIZET Number of events in the event data queue. */ | |
EVENT_NUM_FIRED = 2, /* UINT64 Number of events that were fired since the creation of the module. */ | |
EVENT_SIZE_MAX = 3, /* SIZET Max size of data carried with an event in bytes. GenTL v1.2 */ | |
EVENT_INFO_DATA_SIZE_MAX = 4, /* SIZET Max size of data provided through EventGetDataInfo in bytes. GenTL v1.2 */ | |
EVENT_INFO_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t EVENT_INFO_CMD; | |
/* Event data info command */ | |
enum EVENT_DATA_INFO_CMD_LIST | |
{ | |
EVENT_DATA_ID = 0, /* Event specific Unique Event ID (String or Number)*/ | |
EVENT_DATA_VALUE = 1, /* Event specific Data */ | |
EVENT_DATA_NUMID = 2, /* UINT64 Numeric representation of the unique Event ID, GenTL v1.3. */ | |
EVENT_DATA_CUSTOM_ID = 1000 /* Starting value for GenTL Producer custom IDs. */ | |
}; | |
typedef int32_t EVENT_DATA_INFO_CMD; | |
/* Structure of the data returned from a signaled "New Buffer" event. */ | |
typedef struct S_EVENT_NEW_BUFFER | |
{ | |
BUFFER_HANDLE BufferHandle; /* Buffer handle which contains new data. */ | |
GC_ERROR* pUserPointer; /* User pointer provided at announcement of the buffer. */ | |
} EVENT_NEW_BUFFER_DATA; | |
/* Structure to be use with GCWritePortStacked and GCReadPortStacked. */ | |
typedef struct S_PORT_REGISTER_STACK_ENTRY | |
{ | |
uint64_t Address; /* Address of the register. */ | |
GC_ERROR* pBuffer; /* Pointer to the buffer containing the data. */ | |
size_t Size; /* Number of bytes to read write. */ | |
} PORT_REGISTER_STACK_ENTRY; | |
/* Structure carrying information about a single chunk in the buffer, V1.3 */ | |
typedef struct S_SINGLE_CHUNK_DATA | |
{ | |
uint64_t ChunkID; /* Numeric representation of ChunkID */ | |
ptrdiff_t ChunkOffset; /* Chunk offset in the buffer */ | |
size_t ChunkLength; /* Size of the chunk data */ | |
} SINGLE_CHUNK_DATA; | |
GC_ERROR GCGetInfo ( TL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR GCGetLastError ( GC_ERROR *piErrorCode, char *sErrText, size_t *piSize ); | |
GC_ERROR GCInitLib ( GC_ERROR ); | |
GC_ERROR GCCloseLib ( GC_ERROR ); | |
GC_ERROR GCReadPort ( PORT_HANDLE hPort, uint64_t iAddress, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR GCWritePort ( PORT_HANDLE hPort, uint64_t iAddress, const GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR GCGetPortURL ( PORT_HANDLE hPort, char *sURL, size_t *piSize ); | |
GC_ERROR GCGetPortInfo ( PORT_HANDLE hPort, PORT_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR GCRegisterEvent ( EVENTSRC_HANDLE hEventSrc, EVENT_TYPE iEventID, EVENT_HANDLE *phEvent ); | |
GC_ERROR GCUnregisterEvent ( EVENTSRC_HANDLE hEventSrc, EVENT_TYPE iEventID ); | |
GC_ERROR EventGetData ( EVENT_HANDLE hEvent, GC_ERROR *pBuffer, size_t *piSize, uint64_t iTimeout ); | |
GC_ERROR EventGetDataInfo ( EVENT_HANDLE hEvent, const GC_ERROR *pInBuffer, size_t iInSize, EVENT_DATA_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pOutBuffer, size_t *piOutSize ); | |
GC_ERROR EventGetInfo ( EVENT_HANDLE hEvent, EVENT_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR EventFlush ( EVENT_HANDLE hEvent ); | |
GC_ERROR EventKill ( EVENT_HANDLE hEvent ); | |
GC_ERROR TLOpen ( TL_HANDLE *phTL ); | |
GC_ERROR TLClose ( TL_HANDLE hTL ); | |
GC_ERROR TLGetInfo ( TL_HANDLE hTL, TL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR TLGetNumInterfaces ( TL_HANDLE hTL, uint32_t *piNumIfaces ); | |
GC_ERROR TLGetInterfaceID ( TL_HANDLE hTL, uint32_t iIndex, char *sID, size_t *piSize ); | |
GC_ERROR TLGetInterfaceInfo ( TL_HANDLE hTL, const char *sIfaceID, INTERFACE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR TLOpenInterface ( TL_HANDLE hTL, const char *sIfaceID, IF_HANDLE *phIface ); | |
GC_ERROR TLUpdateInterfaceList ( TL_HANDLE hTL, bool8_t *pbChanged, uint64_t iTimeout ); | |
GC_ERROR IFClose ( IF_HANDLE hIface ); | |
GC_ERROR IFGetInfo ( IF_HANDLE hIface, INTERFACE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR IFGetNumDevices ( IF_HANDLE hIface, uint32_t *piNumDevices ); | |
GC_ERROR IFGetDeviceID ( IF_HANDLE hIface, uint32_t iIndex, char *sIDeviceID, size_t *piSize ); | |
GC_ERROR IFUpdateDeviceList ( IF_HANDLE hIface, bool8_t *pbChanged, uint64_t iTimeout ); | |
GC_ERROR IFGetDeviceInfo ( IF_HANDLE hIface, const char *sDeviceID, DEVICE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR IFOpenDevice ( IF_HANDLE hIface, const char *sDeviceID, DEVICE_ACCESS_FLAGS iOpenFlags, DEV_HANDLE *phDevice ); | |
GC_ERROR DevGetPort ( DEV_HANDLE hDevice, PORT_HANDLE *phRemoteDevice ); | |
GC_ERROR DevGetNumDataStreams ( DEV_HANDLE hDevice, uint32_t *piNumDataStreams ); | |
GC_ERROR DevGetDataStreamID ( DEV_HANDLE hDevice, uint32_t iIndex, char *sDataStreamID, size_t *piSize ); | |
GC_ERROR DevOpenDataStream ( DEV_HANDLE hDevice, const char *sDataStreamID, DS_HANDLE *phDataStream ); | |
GC_ERROR DevGetInfo ( DEV_HANDLE hDevice, DEVICE_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR DevClose ( DEV_HANDLE hDevice ); | |
GC_ERROR DSAnnounceBuffer ( DS_HANDLE hDataStream, GC_ERROR *pBuffer, size_t iSize, GC_ERROR *pPrivate, BUFFER_HANDLE *phBuffer ); | |
GC_ERROR DSAllocAndAnnounceBuffer( DS_HANDLE hDataStream, size_t iSize, GC_ERROR *pPrivate, BUFFER_HANDLE *phBuffer ); | |
GC_ERROR DSFlushQueue ( DS_HANDLE hDataStream, ACQ_QUEUE_TYPE iOperation ); | |
GC_ERROR DSStartAcquisition ( DS_HANDLE hDataStream, ACQ_START_FLAGS iStartFlags, uint64_t iNumToAcquire ); | |
GC_ERROR DSStopAcquisition ( DS_HANDLE hDataStream, ACQ_STOP_FLAGS iStopFlags ); | |
GC_ERROR DSGetInfo ( DS_HANDLE hDataStream, STREAM_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR DSGetBufferID ( DS_HANDLE hDataStream, uint32_t iIndex, BUFFER_HANDLE *phBuffer ); | |
GC_ERROR DSClose ( DS_HANDLE hDataStream ); | |
GC_ERROR DSRevokeBuffer ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, GC_ERROR **pBuffer, GC_ERROR **pPrivate ); | |
GC_ERROR DSQueueBuffer ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer ); | |
GC_ERROR DSGetBufferInfo ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, BUFFER_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
/* GenTL v1.1 */ | |
GC_ERROR GCGetNumPortURLs ( PORT_HANDLE hPort, uint32_t *piNumURLs ); | |
GC_ERROR GCGetPortURLInfo ( PORT_HANDLE hPort, uint32_t iURLIndex, URL_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
GC_ERROR GCReadPortStacked ( PORT_HANDLE hPort, PORT_REGISTER_STACK_ENTRY *pEntries, size_t *piNumEntries ); | |
GC_ERROR GCWritePortStacked ( PORT_HANDLE hPort, PORT_REGISTER_STACK_ENTRY *pEntries, size_t *piNumEntries ); | |
/* GenTL v1.3 */ | |
GC_ERROR DSGetBufferChunkData ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, SINGLE_CHUNK_DATA *pChunkData, size_t *piNumChunks ); | |
/* GenTL v1.4 */ | |
GC_ERROR IFGetParentTL ( IF_HANDLE hIface, TL_HANDLE *phSystem ); | |
GC_ERROR DevGetParentIF ( DEV_HANDLE hDevice, IF_HANDLE *phIface ); | |
GC_ERROR DSGetParentDev ( DS_HANDLE hDataStream, DEV_HANDLE *phDevice ); | |
/* GenTL v1.5 */ | |
GC_ERROR DSGetNumBufferParts ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, uint32_t *piNumParts ); | |
GC_ERROR DSGetBufferPartInfo ( DS_HANDLE hDataStream, BUFFER_HANDLE hBuffer, uint32_t iPartIndex, BUFFER_PART_INFO_CMD iInfoCmd, INFO_DATATYPE *piType, GC_ERROR *pBuffer, size_t *piSize ); | |
""", packed=True) | |
def get_string_info (func, *args): | |
# get the buffer size | |
buffer_size = ffi.new('size_t *') | |
error = func(*args, ffi.NULL, buffer_size) | |
if error != 0: | |
raise RuntimeError('Error getting string info: %d' % error) | |
# get the buffer content | |
buffer = ffi.new('char [%d]' % buffer_size[0]) | |
error = func(*args, ffi.cast('void *', buffer), buffer_size) | |
if error != 0: | |
raise RuntimeError('Error getting string info: %d' % error) | |
return ffi.string(buffer).decode('utf-8') | |
class GenSystem: | |
def __init__(self, module): | |
self.module = module | |
def open(self): | |
error = self.module.GCInitLib(0) | |
if error: | |
raise RuntimeError('Error initializing GenTL library: %d' % error) | |
def close(self): | |
error = self.module.GCCloseLib(0) | |
if error: | |
raise RuntimeError('Error closing GenTL library: %d' % error) | |
def open_tl(self): | |
phandle_tl = ffi.new('TL_HANDLE *') | |
error = self.module.TLOpen(phandle_tl) | |
if error: | |
raise RuntimeError('Error opening GenTL system: %d' % error) | |
return GenTL(self.module, phandle_tl[0]) | |
class GenTL: | |
def __init__(self, module, handle_tl): | |
self.module = module | |
self.handle_tl = handle_tl | |
def close(self): | |
error = self.module.TLClose(self.handle_tl) | |
if error: | |
raise RuntimeError('Error closing GenTL system: %d' % error) | |
def get_info(self, cmd): | |
pass | |
def get_num_interfaces(self): | |
uint32 = ffi.new('uint32_t *') | |
error = self.module.TLGetNumInterfaces(self.handle_tl, uint32) | |
if error: | |
raise RuntimeError('Error getting number of interfaces: %d' % error) | |
return uint32[0] | |
def get_interface_id(self, index): | |
return get_string_info(self.module.TLGetInterfaceID, self.handle_tl, index) | |
def open_interface(self, interface_id): | |
phandle_if = ffi.new('IF_HANDLE *') | |
error = self.module.TLOpenInterface(self.handle_tl, bytes(interface_id,'utf-8'), phandle_if) | |
if error: | |
raise RuntimeError('Error opening GenTL interface: %d' % error) | |
return GenIF(self.module, phandle_if[0]) | |
def update_interface_list(self, timeout=1000): | |
error = self.module.TLUpdateInterfaceList(self.handle_tl, ffi.NULL, ffi.cast('uint64_t', timeout)) | |
if error: | |
raise Exception('TLUpdateInterfaceList failed with error %d' % error) | |
class GenIF: | |
def __init__(self, module, handle_if): | |
self.module = module | |
self.handle_if = handle_if | |
def close(self): | |
error = self.module.IFClose(self.handle_if) | |
if error: | |
raise Exception('IFClose failed with error %d' % error) | |
def get_info(self): | |
int32 = ffi.new('int32_t *', self.module.INFO_DATATYPE_STRING) | |
return get_string_info(self.module.IFGetInfo, self.handle_if, self.module.INTERFACE_INFO_ID, int32) | |
def update_device_list(self, timeout=1000): | |
error = self.module.IFUpdateDeviceList(self.handle_if, ffi.NULL, ffi.cast('uint64_t', timeout)) | |
if error: | |
raise Exception('IFUpdateDeviceList failed with error %d' % error) | |
def get_num_devices(self): | |
uint32 = ffi.new('uint32_t *') | |
error = self.module.IFGetNumDevices(self.handle_if, uint32) | |
if error: | |
raise Exception('IFGetNumDevices failed with error %d' % error) | |
return uint32[0] | |
def get_device_id(self, index): | |
return get_string_info(self.module.IFGetDeviceID, self.handle_if, index) | |
def open_device(self, device_id, mode): | |
phandle_dev = ffi.new('DEV_HANDLE *') | |
error = self.module.IFOpenDevice(self.handle_if, bytes(device_id, 'utf-8'), mode, phandle_dev) | |
if error: | |
raise Exception('IFOpenDevice failed with error %d' % error) | |
return GenDev(self.module, phandle_dev[0]) | |
class GenDev: | |
def __init__(self, module, handle_dev): | |
self.module = module | |
self.handle_dev = handle_dev | |
def close(self): | |
error = self.module.DevClose(self.handle_dev) | |
if error: | |
raise Exception('DevClose failed with error %d' % error) | |
def get_num_data_streams(self): | |
uint32 = ffi.new('uint32_t *') | |
error = self.module.DevGetNumDataStreams(self.handle_dev, uint32) | |
if error: | |
raise Exception('DevGetNumDataStreams failed with error %d' % error) | |
return uint32[0] | |
def get_port(self): | |
phandle_port = ffi.new('PORT_HANDLE *') | |
error = self.module.DevGetPort(self.handle_dev, phandle_port) | |
if error: | |
raise Exception('DevGetPort failed with error %d' % error) | |
return GenPort(self.module, phandle_port[0]) | |
class GenPort: | |
def __init__(self, module, handle_port): | |
self.module = module | |
self.handle_port = handle_port | |
def get_num_urls(self): | |
uint32 = ffi.new('uint32_t *') | |
error = self.module.GCGetNumPortURLs(self.handle_port, uint32) | |
if error: | |
raise Exception('GCGetNumPortURLs failed with error %d' % error) | |
return uint32[0] | |
def get_url_info(self, index): | |
int32 = ffi.new('int32_t *', self.module.INFO_DATATYPE_STRING) | |
return get_string_info(self.module.GCGetPortURLInfo, self.handle_port, index, self.module.URL_INFO_URL, int32) | |
def get_xml_source(self, url): | |
content = b'' | |
if re.match('local:', url, re.IGNORECASE): | |
m = re.match('local:(?:///)?[^;]+;([0-9a-fA-F]+);([0-9a-fA-F]+)', url, re.IGNORECASE) | |
if not m: | |
raise Exception('Invalid URL %s' % url) | |
address = int(m.group(1), 16) | |
size = int(m.group(2), 16) | |
buffer = ffi.new('char[%d]'%size) | |
psize = ffi.new('size_t *', size) | |
error = self.module.GCReadPort(self.handle_port, ffi.cast('uint64_t', address), ffi.cast('void *', buffer), psize) | |
if error: | |
raise Exception('GCReadPort failed with error %d' % error) | |
content = ffi.unpack(buffer, psize[0]) | |
elif re.match('https?://', url, re.IGNORECASE): | |
import requests | |
content = requests.get(url).content | |
else: | |
raise Exception('Invalid URL %s' % url) | |
if content.startswith(b'PK'): | |
import io | |
import zipfile | |
zipfile.ZipInfo._decodeExtra = lambda self: None | |
with zipfile.ZipFile(io.BytesIO(content), 'r') as zf: | |
return zf.read(zf.namelist()[0]).decode() | |
if not content.startswith(b'<?xml'): | |
raise Exception('Invalid XML source: %s' % content) | |
return content.decode() | |
def get_all_cti_files(): | |
gentl_paths = os.environ.get('GENICAM_GENTL64_PATH') | |
if not gentl_paths: | |
return [] | |
files = [] | |
for p in gentl_paths.split(os.pathsep): | |
if os.path.isfile(p): | |
files.append(p) | |
else: | |
files.extend(glob.glob('%s/*.cti'%p)) | |
return files | |
def get_all_devices(): | |
files = get_all_cti_files() | |
devices = [] | |
for file in files: | |
print('Module', file) | |
module = ffi.dlopen(file, 0) | |
system = GenSystem(module) | |
system.open() | |
# list and cache all interfaces and devices | |
gentl = system.open_tl() | |
gentl.update_interface_list() | |
num_interfaces = gentl.get_num_interfaces() | |
for i in range(num_interfaces): | |
intf_id = gentl.get_interface_id(i) | |
print(' Interface', intf_id) | |
intf = gentl.open_interface(intf_id) | |
intf.update_device_list() | |
num_devices = intf.get_num_devices() | |
for n in range(num_devices): | |
device_id = intf.get_device_id(n) | |
print(' Device', device_id) | |
devices.append({ | |
'system': file, | |
'interface': intf_id, | |
'device': intf.get_device_id(n), | |
}) | |
intf.close() | |
gentl.close() | |
system.close() | |
ffi.dlclose(module) | |
return devices | |
if __name__ == '__main__': | |
import argparse | |
import os | |
import glob | |
import sys | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--cti', required=True, help='transport library') | |
parser.add_argument('--device', help='device name') | |
parser.add_argument('command', nargs='?', choices=['genicam']) | |
args = parser.parse_args(sys.argv[1:]) | |
module = ffi.dlopen(args.cti) | |
system = GenSystem(module) | |
system.open() | |
gentl = system.open_tl() | |
gentl.update_interface_list() | |
num_intf = gentl.get_num_interfaces() | |
for n in range(num_intf): | |
intf_id = gentl.get_interface_id(n) | |
if not args.command: | |
print('Interface:', intf_id) | |
intf = gentl.open_interface(intf_id) | |
intf.update_device_list() | |
num_devices = intf.get_num_devices() | |
for j in range(num_devices): | |
device_id = intf.get_device_id(j) | |
if not args.command: | |
print(' Device:', device_id) | |
continue | |
dev = intf.open_device(device_id, 2) | |
if args.device == device_id: | |
port = dev.get_port() | |
url = port.get_url_info(0) | |
xml = port.get_xml_source(url) | |
print(xml) | |
dev.close() | |
intf.close() | |
gentl.close() | |
system.close() | |
ffi.dlclose(module) |
thanks again. There is some response with the correct device name, though a different error occurred:
Precision-5860-Tower:/temp$ python3 gentl.py --cti /opt/pylon/lib/pylonCXP/bin/ProducerCXP.cti/temp$ python3 gentl.py --cti /opt/pylon/lib/pylonCXP/bin/ProducerCXP.cti --device '1200-21-067-Acq_DualCXP12Area-1' genicam
Interface: CXP12-IC-4C SN_b6400331
Device: 1200-21-067-Acq_DualCXP12Area-1
Precision-5860-Tower:
/home/mit/temp/gentl.py:541: UserWarning: implicit cast from 'char *' to a different pointer type: will be forbidden in the future (check that the types are as you expect; use an explicit ffi.cast() if they are correct)
error = func(*args, buffer, buffer_size)
Traceback (most recent call last):
File "/home/mit/temp/gentl.py", line 809, in
xml = port.get_xml_source(url)
File "/home/mit/temp/gentl.py", line 709, in get_xml_source
raise Exception('Invalid XML source: %s' % content)
Exception: Invalid XML source: b''
What if you insert a line "print(content)" at line 707, see what is the result like?
Typical usage