DynExp
Highly flexible laboratory automation for dynamically changing experiments.
PyModules.cpp
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
3 #include "stdafx.h"
4 #include "PyModules.h"
5 
7 
14 PYBIND11_EMBEDDED_MODULE(PyModuleDataStreamInstrument, m)
15 {
16  using namespace DynExpInstr;
17 
18  py::class_<BasicSample>(m, "BasicSample")
19  .def(py::init<>())
20  .def(py::init<typename BasicSample::DataType>())
21  .def(py::init<typename BasicSample::DataType, typename BasicSample::DataType>())
22  .def_readwrite("Value", &BasicSample::Value)
23  .def_readwrite("Time", &BasicSample::Time);
24 
25  py::enum_<DataStreamInstrumentData::UnitType>(m, "UnitType")
33 
34  py::bind_vector<decltype(DynExpInstr::PyDataStreamInstrument::Samples)>(m, "SampleListType");
35 
36  py::class_<PyDataStreamInstrument>(m, "DataStreamInstrument")
37  .def(py::init<>())
38  .def("CalcLastConsumedSampleID", &PyDataStreamInstrument::CalcLastConsumedSampleID)
39  .def_readonly("IsTimeUsed", &PyDataStreamInstrument::IsTimeUsed)
40  .def_readonly("ValueUnit", &PyDataStreamInstrument::ValueUnit)
41  .def_readonly("StreamSizeRead", &PyDataStreamInstrument::StreamSizeRead)
42  .def_readonly("StreamSizeWrite", &PyDataStreamInstrument::StreamSizeWrite)
43  .def_readonly("NumSamplesWritten", &PyDataStreamInstrument::NumSamplesWritten)
44  .def_readwrite("Samples", &PyDataStreamInstrument::Samples);
45 }
46 
47 namespace DynExpInstr
48 {
50  {
51  py::exec("import PyModuleDataStreamInstrument as DataStreamInstrument");
52  }
53 
54  size_t PyDataStreamInstrument::CalcLastConsumedSampleID(size_t NumConsumedSamples)
55  {
56  return NumSamplesWritten - Samples.size() + std::min(Samples.size(), NumConsumedSamples);
57  }
58 }
PYBIND11_MAKE_OPAQUE(decltype(DynExpInstr::PyDataStreamInstrument::Samples))
PYBIND11_EMBEDDED_MODULE(PyModuleDataStreamInstrument, m)
Creates an embedded Python module PyModuleDataStreamInstrument which contains DynExpInstr::BasicSampl...
Definition: PyModules.cpp:14
Implementation of mappings between DynExp instruments and corresponding embedded Python modules makin...
@ Ampere
Electric current in Ampere (A)
@ LogicLevel
Logic level (TTL) units (1 or 0)
@ Counts
Count rate in counts per second (cps)
bool IsTimeUsed
Contains the result of DynExpInstr::DataStreamBase::IsBasicSampleTimeUsed().
Definition: PyModules.h:38
static void import()
Make the Python interpreter import this module as PyModuleDataStreamInstrument. GIL has to be acquire...
Definition: PyModules.cpp:49
size_t StreamSizeWrite
Contains the result of DynExpInstr::DataStreamBase::GetStreamSizeWrite().
Definition: PyModules.h:53
size_t NumSamplesWritten
Contains the result of DynExpInstr::DataStreamBase::GetNumSamplesWritten().
Definition: PyModules.h:58
size_t StreamSizeRead
Contains the result of DynExpInstr::DataStreamBase::GetStreamSizeRead().
Definition: PyModules.h:48
DataStreamBase::BasicSampleListType Samples
Samples of the data stream instrument.
Definition: PyModules.h:63
size_t CalcLastConsumedSampleID(size_t NumConsumedSamples)
Allows to calculate the ID of the last consumed sample based on the amount of samples consumed from t...
Definition: PyModules.cpp:54
DataStreamInstrumentData::UnitType ValueUnit
Refer to DynExpInstr::DataStreamInstrumentData::UnitType.
Definition: PyModules.h:43
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
Definition: Instrument.h:1254
Accumulates include statements to provide a precompiled header.
DataType Value
Value in a unit as specified by the class derived from DataStreamInstrument.
DataType Time
Time in seconds.