BioImager  4.9.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
microscope.cameras.pvcam.PVParam Class Reference
Inheritance diagram for microscope.cameras.pvcam.PVParam:
microscope.cameras.pvcam.PVEnumParam microscope.cameras.pvcam.PVStringParam

Public Member Functions

 __init__ (self, camera, param_id)
 
 set_value (self, new_value)
 
 access (self)
 
 available (self)
 
 count (self)
 
 values (self)
 
 current (self)
 

Static Public Member Functions

 factory (camera, param_id)
 

Public Attributes

 cam = weakref.proxy(camera)
 
 param_id = param_id
 
str name = _param_to_name[param_id]
 
 dtype = _dtypemap[self._pvtype]
 
 available
 

Protected Member Functions

 _query (self, what=ATTR_CURRENT, force_query=False)
 

Protected Attributes

int _pvtype = param_id >> 24 & 255
 
 _ctype = _typemap[self._pvtype]
 

Detailed Description

A wrapper around PVCAM parameters.

Definition at line 1199 of file pvcam.py.

Constructor & Destructor Documentation

◆ __init__()

microscope.cameras.pvcam.PVParam.__init__ ( self,
camera,
param_id )

Definition at line 1224 of file pvcam.py.

1224 def __init__(self, camera, param_id):
1225 # Use a weakref back to the camera to avoid circular dependency.
1226 self.cam = weakref.proxy(camera)
1227 self.param_id = param_id
1228 self.name = _param_to_name[param_id]
1229 self._pvtype = param_id >> 24 & 255
1230 if self.name == "PARAM_READOUT_TIME":
1231 # Bugged. Here is what the SDK says: "The parameter type is
1232 # incorrectly defined. The actual type is TYPE_UNS32."
1233 self._pvtype = TYPE_UNS32
1234 self.dtype = _dtypemap[self._pvtype]
1235 self._ctype = _typemap[self._pvtype]
1236 self.__cache = {}
1237

Member Function Documentation

◆ _query()

microscope.cameras.pvcam.PVParam._query ( self,
what = ATTR_CURRENT,
force_query = False )
protected
Query the DLL for an attribute for this parameter.

This returns pythonic types, not ctypes.

Definition at line 1252 of file pvcam.py.

1252 def _query(self, what=ATTR_CURRENT, force_query=False):
1253 """Query the DLL for an attribute for this parameter.
1254
1255 This returns pythonic types, not ctypes."""
1256 err = None
1257 key = (self, what) # key for cache
1258 if self.cam._acquiring and not force_query:
1259 return self.__cache.get(key, None)
1260 if what == ATTR_AVAIL:
1261 return self.available
1262 elif not self.available:
1264 "Parameter %s is not available" % self.name
1265 )
1266 rtype = _attr_map[what] # return type
1267 if not rtype:
1268 rtype = _get_param(self.cam.handle, self.param_id, ATTR_TYPE)
1269 if rtype.value == TYPE_CHAR_PTR:
1270 buf_len = _length_map[self.param_id]
1271 if not buf_len:
1273 "pvcam: parameter %s not supported in python." % self.name
1274 )
1275 try:
1276 result = _get_param(
1277 self.cam.handle, self.param_id, what, buf_len=buf_len
1278 )
1279 except Exception as e:
1280 err = e
1281 else:
1282 result = result.value
1283 else:
1284 try:
1285 result = _get_param(self.cam.handle, self.param_id, what)
1286 except Exception as e:
1287 err = e
1288 else:
1289 result = ctypes.POINTER(self._ctype)(result).contents.value
1290 # Test on err.args prevents indexing into empty tuple.
1291 if err and err.args and err.args[0].startswith("pvcam error 49"):
1292 _logger.warn(
1293 "Parameter %s not available due to camera state.", self.name
1294 )
1295 result = None
1296 elif err:
1297 raise e
1298 else:
1299 self.__cache[key] = result
1300 return result
1301

◆ access()

microscope.cameras.pvcam.PVParam.access ( self)
Return parameter access attribute.

Definition at line 1303 of file pvcam.py.

1303 def access(self):
1304 """Return parameter access attribute."""
1305 return int(
1306 _get_param(self.cam.handle, self.param_id, ATTR_ACCESS).value
1307 )
1308

◆ available()

microscope.cameras.pvcam.PVParam.available ( self)
Return whether or not parameter is available on hardware.

Definition at line 1310 of file pvcam.py.

1310 def available(self):
1311 """Return whether or not parameter is available on hardware."""
1312 return bool(
1313 _get_param(self.cam.handle, self.param_id, ATTR_AVAIL).value
1314 )
1315

◆ count()

microscope.cameras.pvcam.PVParam.count ( self)
Return count of parameter enum entries.

Definition at line 1317 of file pvcam.py.

1317 def count(self):
1318 """Return count of parameter enum entries."""
1319 return int(
1320 _get_param(self.cam.handle, self.param_id, ATTR_COUNT).value
1321 )
1322

◆ current()

microscope.cameras.pvcam.PVParam.current ( self)
Return the current (or cached) parameter value.

Subclasses should override this for more complex data types.

Reimplemented in microscope.cameras.pvcam.PVEnumParam, and microscope.cameras.pvcam.PVStringParam.

Definition at line 1331 of file pvcam.py.

1331 def current(self):
1332 """Return the current (or cached) parameter value.
1333
1334 Subclasses should override this for more complex data types."""
1335 return self._query()
1336
1337

◆ factory()

microscope.cameras.pvcam.PVParam.factory ( camera,
param_id )
static
Create a PVParam or appropriate subclass

Definition at line 1203 of file pvcam.py.

1203 def factory(camera, param_id):
1204 """Create a PVParam or appropriate subclass"""
1205 # A mapping of pv parameters types to python types.
1206 # None means unsupported.
1207 # Parameters omitted from the mapping will default to PVParam.
1208 __types__ = {
1209 TYPE_SMART_STREAM_TYPE: None,
1210 TYPE_SMART_STREAM_TYPE_PTR: None,
1211 TYPE_VOID_PTR: None,
1212 TYPE_VOID_PTR_PTR: None,
1213 TYPE_ENUM: PVEnumParam,
1214 TYPE_CHAR_PTR: PVStringParam,
1215 }
1216 # Determine the appropiate type from its id.
1217 pvtype = __types__.get(param_id >> 24 & 255, PVParam)
1218 if pvtype is None:
1220 "Parameter %s not supported" % _param_to_name[param_id]
1221 )
1222 return pvtype(camera, param_id)
1223

◆ set_value()

microscope.cameras.pvcam.PVParam.set_value ( self,
new_value )
Set a parameter value.

Subclasses should do whatever processing they need on new_value,
then call super().set_value(new_value)

Reimplemented in microscope.cameras.pvcam.PVEnumParam, and microscope.cameras.pvcam.PVStringParam.

Definition at line 1238 of file pvcam.py.

1238 def set_value(self, new_value):
1239 """Set a parameter value.
1240
1241 Subclasses should do whatever processing they need on new_value,
1242 then call super().set_value(new_value)"""
1243 try:
1244 ref = ctypes.byref(new_value)
1245 except TypeError:
1246 # Need to convert python type to ctype first.
1247 ref = ctypes.byref(self._ctype(new_value))
1248 _set_param(self.cam.handle, self.param_id, ref)
1249 # Read back the value to update cache.
1250 self._query(force_query=True)
1251

◆ values()

microscope.cameras.pvcam.PVParam.values ( self)
Get parameter min and max values.

Subclasses for strings and enum override this.

Reimplemented in microscope.cameras.pvcam.PVEnumParam, and microscope.cameras.pvcam.PVStringParam.

Definition at line 1324 of file pvcam.py.

1324 def values(self):
1325 """Get parameter min and max values.
1326
1327 Subclasses for strings and enum override this."""
1328 return (self._query(ATTR_MIN), self._query(ATTR_MAX))
1329

Member Data Documentation

◆ _ctype

microscope.cameras.pvcam.PVParam._ctype = _typemap[self._pvtype]
protected

Definition at line 1235 of file pvcam.py.

◆ _pvtype

int microscope.cameras.pvcam.PVParam._pvtype = param_id >> 24 & 255
protected

Definition at line 1229 of file pvcam.py.

◆ available

microscope.cameras.pvcam.PVParam.available

Definition at line 1262 of file pvcam.py.

◆ cam

microscope.cameras.pvcam.PVParam.cam = weakref.proxy(camera)

Definition at line 1226 of file pvcam.py.

◆ dtype

microscope.cameras.pvcam.PVParam.dtype = _dtypemap[self._pvtype]

Definition at line 1234 of file pvcam.py.

◆ name

str microscope.cameras.pvcam.PVParam.name = _param_to_name[param_id]

Definition at line 1228 of file pvcam.py.

◆ param_id

microscope.cameras.pvcam.PVParam.param_id = param_id

Definition at line 1227 of file pvcam.py.


The documentation for this class was generated from the following file: