Exemple #1
0
class AppRoot(ComponentBase):

    dataSaver = Instance(DataSaver)
    tw4b = Instance(TW4B)
    currentMeasurement = DataSetTrait().tag(name="Current measurement",
                                            data_label="Amplitude",
                                            axes_labels=["Time"])

    progress = traitlets.Float(0, min=0, max=1, read_only=True).tag(name="Progress")
    traitlets.Int(1, min=1).tag(name="No. of measurements", priority=99)

    def __init__(self, objectName=None, loop=None):
        super().__init__(objectName="Measurement", loop=loop)
        self.title = "Taipan - HHI"

        self.dataSaver = DataSaver(objectName="Data Saver")
        self.tw4b = TW4B(objectName="TW4B", loop=loop)

        self.nMeasurements = traitlets.Int(1, min=1).tag(name="No. of measurements", priority=99)


    async def __aenter__(self):
        self.tw4b.start_device_discovery()
        await asyncio.sleep(2)
        await super().__aenter__()
        return self

    @action("Take measurements")
    async def takeMeasurements(self):
        for i in range(self.nMeasurements):
            self.set_trait('progress', i / self.nMeasurements)
            self.set_trait("currentMeasurement", await self.tw4b.readDataSet())
            self.dataSaver.process(self.currentMeasurement)
Exemple #2
0
class AppRoot(ComponentBase):

    dataSaver = Instance(DataSaver)
    tem_fs = Instance(TEMFiberStretcher)
    currentMeasurement = DataSetTrait().tag(name="Current measurement",
                                            data_label="Amplitude",
                                            axes_labels=["Time"])

    progress = traitlets.Float(0, min=0, max=1,
                               read_only=True).tag(name="Progress")
    nMeasurements = traitlets.Int(1, min=1).tag(name="No. of measurements",
                                                priority=99)

    def __init__(self, objectName=None, loop=None):
        super().__init__(objectName="Measurement", loop=loop)
        self.title = "Taipan - Schweißgüte 2"

        self.dataSaver = DataSaver(objectName="Data Saver")
        self.tem_fs = TEMFiberStretcher(tem_port1,
                                        tem_port2,
                                        objectName="TEM FiberStretcher",
                                        loop=loop)

    @action("Take measurements")
    async def takeMeasurements(self):
        for i in range(self.nMeasurements):
            self.set_trait("currentMeasurement", await
                           self.tem_fs.readDataSet())
            self.dataSaver.process(self.currentMeasurement)
            self.set_trait('progress', (i + 1) / self.nMeasurements)
Exemple #3
0
class AppRoot(ComponentBase):

    someDataSet = DataSetTrait().tag(name="Current measurement",
                                     data_label="Amplitude",
                                     axes_labels=["Sample number"])

    scan = Instance(Scan)

    def __init__(self, loop=None):
        super().__init__(objectName="Example application", loop=loop)

        self.scan = Scan()

        self.scan.manipulator = DummyManipulator()
        self.scan.dataSource = DummyContinuousDataSource(self.scan.manipulator)

        self.scan.minimumValue = Q_(0, 'mm')
        self.scan.maximumValue = Q_(10, 'mm')
        self.scan.positioningVelocity = Q_(1, 'mm/s')
        self.scan.scanVelocity = Q_(0.5, 'mm/s')
        self.scan.step = Q_(0.2, 'mm')

    @action("Take new measurement")
    async def takeMeasurement(self):
        dataSet = await self.scan.readDataSet()
        self.set_trait('someDataSet', dataSet)
Exemple #4
0
class AppRoot(ComponentBase):
    currentMeasurement = DataSetTrait().tag(name="Current measurement",
                                            data_label="Amplitude",
                                            axes_labels=["Time"])

    manipulator = Instance(DummyManipulator)
    dataSource = Instance(DummyContinuousDataSource)

    def __init__(self, loop=None):
        super().__init__(objectName=": )", loop=loop)
        self.manipulator = DummyManipulator()
        self.manipulator.objectName = "Stage"
        self.dataSource = DummyContinuousDataSource(self.manipulator)

    async def __aenter__(self):
        await super().__aenter__()
        return self

    @action("Start continuous datasource")
    async def takeMeasurements(self):
        await self.dataSource.update_live_data()
Exemple #5
0
class AppRoot(ComponentBase):

    someDataSet = DataSetTrait().tag(name="Current measurement",
                                     data_label="Amplitude",
                                     axes_labels=["Sample number"])

    scan = Instance(Scan)

    def __init__(self, loop=None):
        super().__init__(objectName="Example application", loop=loop)

        self.scan = Scan()

        self.scan.manipulator = DummyManipulator()
        self.scan.dataSource = SR7230(rm.open_resource(SR7230_LAN_Port),
                                      ethernet=True)
        # self.scan.dataSource = SR7230(rm.open_resource(SR7230_USB_Port), ethernet=False)

        self.scan.continuousScan = True
        self.scan.minimumValue = Q_(0, 'mm')
        self.scan.maximumValue = Q_(10, 'mm')
        self.scan.positioningVelocity = Q_(1, 'mm/s')
        self.scan.scanVelocity = Q_(0.5, 'mm/s')
        self.scan.step = Q_(0.2, 'mm')

    async def __aenter__(self):
        # await super().__aenter__()
        await self.scan.dataSource.__aenter__()  # lockin

        return self

    async def __aexit__(self, *args):
        await self.scan.dataSource.__aexit__(*args)  # lockin
        await super().__aexit__(*args)

    @action("Take new measurement")
    async def takeMeasurement(self):
        dataSet = await self.scan.readDataSet()
        self.set_trait('someDataSet', dataSet)
Exemple #6
0
class NIDAQ(DataSource):

    dataRate = QuantityTrait(Q_(0, 'Hz'), read_only=True).tag(name="Data rate")

    active = traitlets.Bool(False, read_only=True).tag(name="Active")

    currentDataSet = DataSetTrait(read_only=True).tag(
        name="Current chunk",
        data_label="Amplitude",
        axes_labels=["Sample number"])

    analogChannel = traitlets.Unicode('Dev1/ai0', read_only=False)
    clockSource = traitlets.Unicode('', read_only=False)

    voltageMin = QuantityTrait(Q_(-10, 'V'))
    voltageMax = QuantityTrait(Q_(10, 'V'))

    def __init__(self, objectName=None, loop=None):
        super().__init__(objectName=objectName, loop=loop)

        self.chunkSize = 2000
        self.sampleRate = 1e6

        self.readEveryN = 100

        self.currentTask = None

        self._buf = None
        self._cumBuf = np.zeros(0)

        self._axis = None

        self.__pendingFutures = []

        self._chunkReadyCallbacks = []

        self._lastTime = 0

    def _everyNCallback(self):
        read = mx.int32()
        self.currentTask.ReadAnalogF64(
            self.readEveryN,
            0,  # timeout
            mx.DAQmx_Val_GroupByScanNumber,
            self._buf,
            self._buf.size,
            mx.byref(read),
            None)

        # this callback is called from another thread, so we'll post a queued
        # call to the event loop
        chunk = self._buf.copy()
        self._loop.call_soon_threadsafe(lambda: self._handleNewChunk(chunk))

        return 0

    def _taskDone(self, status):
        self.stop()
        return 0

    def _handleNewChunk(self, chunk):
        self._cumBuf = np.concatenate((self._cumBuf, chunk))

        while len(self._cumBuf) >= self.chunkSize:
            properChunk = self._cumBuf[:self.chunkSize].copy()
            self._cumBuf = self._cumBuf[self.chunkSize:].copy()

            if self._axis is None:
                axis = Q_(np.arange(len(properChunk)))
            else:
                axis = self._axis.copy()

            properChunk = Q_(properChunk, 'V')
            dataSet = DataSet(properChunk, [axis])
            self.set_trait('currentDataSet', dataSet)

            cur = time.perf_counter()
            rate = 1.0 / (cur - self._lastTime)
            self.set_trait('dataRate', Q_(rate, 'Hz'))
            self._lastTime = cur

            self._chunkReady(dataSet)

            for fut in self.__pendingFutures:
                if not fut.done():
                    fut.set_result(dataSet)

            self.__pendingFutures = []

    @action('Start task')
    async def start(self, scanAxis=None):
        if self.active or self.currentTask is not None:
            raise RuntimeError("Data source is already running")

        if scanAxis is not None:
            self.chunkSize = len(scanAxis)
            self._axis = scanAxis

        self._buf = np.zeros(self.readEveryN)
        self.currentTask = mx.Task()
        self.currentTask.EveryNCallback = self._everyNCallback
        self.currentTask.DoneCallback = self._taskDone

        self.currentTask.CreateAIVoltageChan(self.analogChannel, "",
                                             mx.DAQmx_Val_RSE, -10.0, 10.0,
                                             mx.DAQmx_Val_Volts, None)

        self.currentTask.CfgSampClkTiming(
            self.clockSource,
            self.sampleRate,
            mx.DAQmx_Val_Rising,
            mx.DAQmx_Val_ContSamps,
            10 * self.chunkSize  # suggested buffer size
        )

        self.currentTask.AutoRegisterEveryNSamplesEvent(
            mx.DAQmx_Val_Acquired_Into_Buffer, self.readEveryN, 0)

        self.currentTask.AutoRegisterDoneEvent(0)
        self.currentTask.StartTask()
        self.set_trait("active", True)

    @action('Stop task')
    async def stop(self):
        if self.currentTask is not None:
            self.currentTask.ClearTask()
            self.currentTask = None
            self.set_trait("active", False)
            self._cumBuf = np.zeros(0)
            self._axis = None
            logging.info("Task stopped.")

    def addChunkReadyCallback(self, callback):
        self._chunkReadyCallbacks.append(callback)

    def removeChunkReadyCallback(self, callback):
        self._chunkReadyCallbacks.remove(callback)

    def _chunkReady(self, dataSet):
        for cb in self._chunkReadyCallbacks:
            cb(dataSet)

    async def readDataSet(self):
        fut = self._loop.create_future()
        self.__pendingFutures.append(fut)
        dset = await fut
        self._dataSetReady(dset)
        return dset
Exemple #7
0
class NIFiniteSamples(DataSource):

    dataRate = QuantityTrait(Q_(0, 'Hz'), read_only=True).tag(name="Data rate")
    active = traitlets.Bool(False, read_only=True).tag(name="Active")

    dataSet = DataSetTrait(read_only=True).tag(name="Current chunk",
                                               data_label="Amplitude",
                                               axes_labels=["Sample number"])

    analogChannel = traitlets.Unicode('Dev1/ai0', read_only=False)
    clockSource = traitlets.Unicode('', read_only=False)

    voltageMin = QuantityTrait(Q_(-10, 'V'))
    voltageMax = QuantityTrait(Q_(10, 'V'))

    sampleRate = 1e6
    currentTask = None

    def __init__(self, objectName=None, loop=None):
        super().__init__(objectName=objectName, loop=loop)
        self._axis = None
        self.dataPoints = None
        self._lastTime = 0
        self._currentFuture = None

    @action('Start task')
    async def start(self, scanAxis=None):
        if self.active or self.currentTask is not None:
            raise RuntimeError("Data source is already running")

        if scanAxis is not None:
            self.dataPoints = len(scanAxis)
            self._axis = scanAxis
        else:
            raise RuntimeError('Provide scan axis to NiFiniteSamples Start '
                               'method')

        self.currentTask = mx.Task()
        self.currentTask.CreateAIVoltageChan(self.analogChannel, "",
                                             mx.DAQmx_Val_RSE, -10.0, 10.0,
                                             mx.DAQmx_Val_Volts, None)

        self.currentTask.CfgSampClkTiming(self.clockSource, self.sampleRate,
                                          mx.DAQmx_Val_Rising,
                                          mx.DAQmx_Val_FiniteSamps,
                                          self.dataPoints)

        self.currentTask.DoneCallback = self._taskDone
        self.currentTask.StartTask()
        self._currentFuture = self._loop.create_future()
        self.set_trait("active", True)

    def _taskDone(self):
        self._loop.call_soon_threadsafe(self._handleNewDataSet)
        return 0

    def _handleNewDataSet(self):
        read = mx.int32()
        buf = np.zeros((self.dataPoints, ))
        self.currentTask.ReadAnalogF64(
            mx.DAQmx_Val_Auto,
            0,  # timeout
            mx.DAQmx_Val_GroupByScanNumber,
            buf,
            buf.size,
            mx.byref(read),
            None)

        dset = DataSet(Q_(buf, 'V'), [self._axis.copy()])
        self._currentFuture.set_result(dset)
        self.set_trait('dataSet', dset)
        cur = time.perf_counter()
        rate = 1.0 / (cur - self._lastTime)
        self.set_trait('dataRate', Q_(rate, 'Hz'))
        self._loop.create_task(self.stop())
        return 0

    @action('Stop task')
    async def stop(self):
        if self.currentTask is not None:
            self.currentTask.ClearTask()

        self.set_trait("active", False)
        self.currentTask = None

    async def readDataSet(self):
        if self._currentFuture is None:
            raise RuntimeError("Start datasource before reading")

        return await self._currentFuture