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_<DataStreamInstrumentData::UnitType>(m, "UnitType")
26 .value("Arbitrary", DataStreamInstrumentData::UnitType::Arbitrary)
27 .value("LogicLevel", DataStreamInstrumentData::UnitType::LogicLevel)
28 .value("Counts", DataStreamInstrumentData::UnitType::Counts)
29 .value("Volt", DataStreamInstrumentData::UnitType::Volt)
30 .value("Ampere", DataStreamInstrumentData::UnitType::Ampere)
31 .value("Power_W", DataStreamInstrumentData::UnitType::Power_W)
32 .value("Power_dBm", DataStreamInstrumentData::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_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
47namespace 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...
static void import()
Make the Python interpreter import this module as PyModuleDataStreamInstrument. GIL has to be acquire...
Definition PyModules.cpp:49
size_t NumSamplesWritten
Contains the result of DynExpInstr::DataStreamBase::GetNumSamplesWritten().
Definition PyModules.h:58
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
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
Accumulates include statements to provide a precompiled header.