Python scripts can gain control
PIXCI® frame grabbers and access image data
via the XCLIB SDK/Library
(.so
file), a Python XCLIB module
(.py
file), and a wrapper
(.so
file) connecting them.
A Python script to snap and save an image can be as simple as:
although, a few additions to check for errors are encouraged.import xclib xclib.pxd_PIXCIopen("", "", "videosetup.fmt") xclib.pxd_doSnap(1, 1, 0); xclib.pxd_saveTiff(1, "saved.tif", 1, 0, 0, -1, -1, 0, 0) xclib.pxd_PIXCIclose();
The XCLIB C/C++ library, such as:
should be copied toxclib_x86_64.so (XCLIB) xclib_i386.so (XCLIB) xclib_aarch64.so (XCLIB) xclib_armv7l.so (XCLIB)
/usr/lib
,
or other location as specified
by
''LD_LIBRARY_PATH''.
See Linux documentation regarding searches for shared libraries
''LD_LIBRARY_PATH''.
The corresponding XCLIB Python wrapper, such as:
should copied to the same directory as the Python script, but as file namexclib_py_wrap_x86_64.so xclib_py_wrap_i386.so xclib_py_wrap_aarch64.so xclib_py_wrap_armv7l.so
_xclib.so
.
The XCLIB Python module:
should copied to the same directory as the Python script.xclib.py
Several XCLIB functions pass pixel data or serial data using a ''char'', ''uchar'', or ''ushort'' array and a cnt array dimension, such as:
orpxd_serialRead(int unitmap, int rsvd0, char buf[], int cnt);
Use a common Python:pxd_readuchar(int unitmap,pxbuffer_t framebuf, pxcoord_t ulx,pxcoord_t uly,pxcoord_t lrx,pxcoord_t lry, uchar *membuf,size_t cnt,const char *colorspace);
for uchar or char array parameters, use the common Python:bytearray(...) array.array('b', ...) array.array('B', ...)
for ''ushort'' parameters. Do not pass the cnt array dimension, it is implied from the Python array; thus, one fewer parameter is coded via Python than described elsewhere.array.array('H', ...) # 'H' for 2 byte unsigned integer, # Python implementation dependent
The XCLIB functions
allow use of a ''NULL'' buf and/or cnt=0; in that mode they return the number of byte available to be read, or the number of bytes than can be added to the queue, respectively. Using:pxd_serialRead(int unitmap, int rsvd0, char buf[], int cnt); pxd_serialWrite(int unitmap, int rsvd0, char buf[], int cnt);
is suggested; regardless of whether the value of buf, appears as a ''NULL'', the (implied) cnt will be 0.bytearray(0)
The XCLIB functions pxd_infoSysTicksUnits, pxd_infoSysTicks, and pxd_buffersSysTicks2 pass values using an undimensioned ''uint32'' array and are not supported via the XCLIB Python wrapper. Use alternative function pxd_infoSysTicksUnits2 which returns a floating point value. Use alternative functions pxd_infoSysTicks2 and pxd_buffersSysTicks3 along with a common Python
array; do not pass the cnt array dimension.array.array('L' ...) # 'L' for 4 byte unsigned integer, # Python implementation dependent
Several XCLIB functions use a ''double'' array parameter, such as
for passing a set of values to, or from, the XCLIB function. Use the XCLIB wrapper specific ''doubleArray'', such as:double gains[4]
As always when invoking C/C++ functions with an array parameter, an array smaller than the expected by the function may result in faults and/or crashes; Python will not detect or prevent such misuse.gains = xclib.doubleArray(4) pxd_getAdcGainsA(1, gains) print(gains[0]) ... print(gains[3])
Several XCLIB functions use a string parameter, i.e. ''const char *'', for a file path name or color space. A Python string can be passed and will be converted to ''utf-8'' encoding; an explicit
is not required when using the XCLIB Python wrapper."camera.fmt".encode('utf-8')
Deprecated XCLIB functions
are not supported via the XCLIB Python wrapper; use thepxd_SV2112_* pxd_SV1310_* pxd_SV1281_* pxd_SV9M001_* pxd_SV642_* pxd_SV643_*
functions.pxd_SILICONVIDEO_*
The
xclibel1.py
example script is provided with XCLIB.
Support
The XCLIB Python module and wrapper was developed and tested with Python 3. Earlier versions of Python are neither tested nor supported.
The ''structured'' XCLIB functions are not currently supported via the XCLIB Python wrapper.
Use of the PXIPL library with the XCLIB Python module and wrapper is not currently supported.
Use of the XCLIB Python module and wrapper under Windows
is not currently supported.
Alternatives
The XCLIB Python module and wrapper was created using ''SWIG'' (Simple Wrapper and Interface Generator) along with XCLIB's .h files.
The Python community offers other tools and methods for developers to use, such as ''ctypes'', ''SIP'', and others.
Of particular note, the Python ''ctypes'' module may allow interfacing to XCLIB with a smaller ''footprint''. Note that any any strings passed from Python (using Unicode) to XCLIB (using ASCII) must be converted with, for example:
"camera.fmt".encode('utf-8')
Copyright (C) EPIX, Inc. All Rights Reserved
Updated: 10-Sep-2024