from functools import partial
from fractions import Fraction
-from lowlevel import *
-import lowlevel
+from .lowlevel import *
+from . import lowlevel
import itertools
__all__ = ['Error', 'Context', 'Driver', 'Device', 'Session', 'Packet']
return Fraction(
g_variant_get_uint64(g_variant_get_child_value(value, 0)),
g_variant_get_uint64(g_variant_get_child_value(value, 1)))
- raise NotImplementedError, (
+ raise NotImplementedError(
"Can't convert GVariant type '%s' to a Python type." % type_string)
def python_to_gvariant(value):
result = g_variant_new_tuple(array, 2)
delete_gvariant_ptr_array(array)
return result
- raise NotImplementedError, (
+ raise NotImplementedError(
"Can't convert Python '%s' to a GVariant." % type(value))
def callback_wrapper(session, callback, device_ptr, packet_ptr):
check(sr_config_get(self.driver.struct, key, data, self.struct))
except Error as error:
if error.errno == SR_ERR_ARG:
- raise NotImplementedError, (
+ raise NotImplementedError(
"Device does not implement %s" % name)
else:
raise AttributeError
if self.struct.type == SR_DF_LOGIC:
self._payload = Logic(self,
void_ptr_to_sr_datafeed_logic_ptr(pointer))
+ elif self.struct.type == SR_DF_ANALOG:
+ self._payload = Analog(self,
+ void_ptr_to_sr_datafeed_analog_ptr(pointer))
else:
- raise NotImplementedError, (
+ raise NotImplementedError(
"No Python mapping for packet type %ѕ" % self.struct.type)
return self._payload
self._data = cdata(self.struct.data, self.struct.length)
return self._data
+class Analog(object):
+
+ def __init__(self, packet, struct):
+ self.packet = packet
+ self.struct = struct
+ self._data = None
+
+ @property
+ def num_samples(self):
+ return self.struct.num_samples
+
+ @property
+ def data(self):
+ if self._data is None:
+ self._data = float_array.frompointer(self.struct.data)
+ return self._data
+
for symbol_name in dir(lowlevel):
prefix = 'SR_DF_'
if symbol_name.startswith(prefix):