DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
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
14PYBIND11_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_<DynExp::Units::UnitType>(m, "UnitType")
26 .value("Arbitrary", DynExp::Units::UnitType::Arbitrary)
27 .value("LogicLevel", DynExp::Units::UnitType::LogicLevel)
28 .value("Counts", DynExp::Units::UnitType::Counts)
29 .value("Volt", DynExp::Units::UnitType::Volt)
30 .value("Ampere", DynExp::Units::UnitType::Ampere)
31 .value("Power_W", DynExp::Units::UnitType::Power_W)
32 .value("Power_dBm", DynExp::Units::UnitType::Power_dBm);
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("ConsumeNone", &PyDataStreamInstrument::ConsumeNone)
40 .def("ConsumeAll", &PyDataStreamInstrument::ConsumeAll)
41 .def("Clear", &PyDataStreamInstrument::Clear)
42 .def_readonly("IsTimeUsed", &PyDataStreamInstrument::IsTimeUsed)
43 .def_readonly("ValueUnit", &PyDataStreamInstrument::ValueUnit)
44 .def_readonly("StreamSizeRead", &PyDataStreamInstrument::StreamSizeRead)
45 .def_readonly("StreamSizeWrite", &PyDataStreamInstrument::StreamSizeWrite)
46 .def_readonly("NumSamplesWritten", &PyDataStreamInstrument::NumSamplesWritten)
47 .def_readwrite("Samples", &PyDataStreamInstrument::Samples);
48}
49
50namespace DynExpInstr
51{
53 {
54 py::exec("import PyModuleDataStreamInstrument as DataStreamInstrument");
55 }
56
57 size_t PyDataStreamInstrument::CalcLastConsumedSampleID(size_t NumConsumedSamples) const
58 {
59 return NumSamplesWritten - Samples.size() + std::min(Samples.size(), NumConsumedSamples);
60 }
61
63 {
64 return NumSamplesWritten;
65 }
66}
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...
static void import()
Make the Python interpreter import this module as PyModuleDataStreamInstrument. GIL has to be acquire...
Definition PyModules.cpp:52
size_t NumSamplesWritten
Contains the result of DynExpInstr::DataStreamBase::GetNumSamplesWritten().
Definition PyModules.h:104
size_t ConsumeAll() const
Allows to calculate the ID of the last consumed sample for the situation that all samples were consum...
Definition PyModules.cpp:62
DataStreamBase::BasicSampleListType Samples
Samples of the data stream instrument.
Definition PyModules.h:109
size_t CalcLastConsumedSampleID(size_t NumConsumedSamples) const
Allows to calculate the ID of the last consumed sample based on the number of samples consumed from t...
Definition PyModules.cpp:57
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
@ Ampere
Electric current in Ampere (A)
@ Power_dBm
Power in dBm.
@ Arbitrary
Arbitrary units (a.u.)
@ LogicLevel
Logic level (TTL) units (1 or 0)
@ Power_W
Power in Watt (W)
@ Volt
Voltage in Volt (V)
@ Counts
Count rate in counts per second (cps)
Accumulates include statements to provide a precompiled header.