rohdeschwarz  0.2.0
TCPIP socket library for Rohde & Schwarz instrument control
trace.cpp
Go to the documentation of this file.
1 
7 // rohdeschwarz
11 #include "rohdeschwarz/helpers.hpp"
13 using namespace rohdeschwarz;
14 using namespace rohdeschwarz::instruments::vna;
15 
16 
17 Trace::Trace(Vna* znx, const char* name) :
18  _vna(znx),
19  _name(name)
20 {
21  // no operations
22 }
23 
24 
25 Trace::Trace(Vna* znx, const std::string& name) :
26  _vna(znx),
27  _name(name)
28 {
29  // no operations
30 }
31 
32 
33 std::string Trace::name() const
34 {
35  return _name;
36 }
37 
38 
40 {
41  _vna->write(":CALC%1%:PAR:SEL \'%2%\'", channel(), _name);
42 }
43 
44 
45 std::string Trace::parameter()
46 {
47  const auto response = _vna->query(":CALC%1%:PAR:MEAS? \'%2%\'", channel(), _name);
48  return unquote(rightTrim(response));
49 }
50 
51 
52 void Trace::setParameter(const char* parameter)
53 {
54  const std::string parameter_str(parameter);
55  setParameter(parameter_str);
56 }
57 
58 
59 void Trace::setParameter(const std::string& parameter)
60 {
61  _vna->write(":CALC%1%:PAR:MEAS \'%2%\',\'%3%\'", channel(), _name, parameter);
62 }
63 
64 
65 std::string Trace::format()
66 {
67  select();
68  const auto response = _vna->query(":CALC%1%:FORM?", channel());
69  return rightTrim(response);
70 }
71 
72 
73 void Trace::setFormat(const char* format)
74 {
75  const std::string format_str(format);
76  setFormat(format_str);
77 }
78 
79 
80 void Trace::setFormat(const std::string& format)
81 {
82  select();
83  _vna->write(":CALC%1%:FORM %2%", channel(), format);
84 }
85 
86 
87 unsigned int Trace::channel()
88 {
89  return std::stoi(_vna->query(":CONF:TRAC:CHAN:NAME:ID? \'%1%\'", _name));
90 }
91 
92 unsigned int Trace::diagram()
93 {
94  auto response = _vna->query(":CONF:TRAC:WIND? \'%1%\'", _name);
95  return std::stoi(rightTrim(response));
96 }
97 
98 
99 void Trace::setDiagram(unsigned int diagram)
100 {
101  _vna->write(":DISP:WIND%1%:TRAC:EFE \'%2%\'", diagram, _name);
102 }
103 
104 
105 std::vector<double> Trace::y()
106 {
107  // set data format to binary 64-bit, little-endian
108  PreserveDataFormat preserve_data_format(_vna);
109  DataFormat format = _vna->dataFormat();
110  format.setBinary64Bit();
111  format.setLittleEndian();
112 
113  // write
114  if (!_vna->write("CALC:DATA:TRAC? \'%1%\',FDAT", name()))
115  {
116  // error
117  return std::vector<double>();
118  }
119 
120  // read
121  return _vna->read64BitVector();
122 }
123 
124 
125 std::vector<std::complex<double>> Trace::y_complex()
126 {
127  // set data format to binary 64-bit, little-endian
128  PreserveDataFormat preserve_data_format(_vna);
129  DataFormat format = _vna->dataFormat();
130  format.setBinary64Bit();
131  format.setLittleEndian();
132 
133  // write
134  if (!_vna->write(":CALC:DATA:TRAC? \'%1%\',SDAT", name()))
135  {
136  // error
137  return std::vector<std::complex<double>>();
138  }
139 
140  // read
141  return _vna->read64BitComplexVector();
142 }
std::vector< std::complex< double > > read64BitComplexVector()
Reads block data and parses it into vector <complex <double>>
Definition: instrument.cpp:229
std::string query(std::string scpi_command, Args &&... args)
Definition: instrument.hpp:173
bool write(std::string scpi_command, Args &&... args)
Definition: instrument.hpp:142
std::vector< double > read64BitVector()
Reads block data and parses it into vector <double>
Definition: instrument.cpp:214
Object-oriented control of the data transfer format and byte order.
Definition: data_format.hpp:36
Class for preserving data format and byte order in a particular scope.
unsigned int diagram()
Queries the index of the diagram for this trace.
Definition: trace.cpp:92
void setParameter(const char *parameter)
Sets the measurement parameter for this trace.
Definition: trace.cpp:52
void select()
Make trace the active trace.
Definition: trace.cpp:39
std::string format()
Queries the trace format.
Definition: trace.cpp:65
void setFormat(const char *format)
Sets the trace format.
Definition: trace.cpp:73
std::string name() const
Trace name.
Definition: trace.cpp:33
Trace(Vna *vna, const char *name)
Constructor.
Definition: trace.cpp:17
void setDiagram(unsigned int diagram)
Adds trace to diagram.
Definition: trace.cpp:99
unsigned int channel()
Queries the index of the measurement channel for this trace.
Definition: trace.cpp:87
std::vector< double > y()
Returns formatted Y values from the last measurement of this trace.
Definition: trace.cpp:105
std::string parameter()
Gets the measurement parameter for this trace.
Definition: trace.cpp:45
std::vector< std::complex< double > > y_complex()
Returns unformatted Y values from the last measurement of this trace.
Definition: trace.cpp:125
Object-oriented R&S ZNX-series VNA control.
Definition: vna.hpp:34
DataFormat dataFormat()
Object-oriented control of the data transfer format.
Definition: vna.cpp:26
rohdeschwarz helper function definition
std::string unquote(const char *text)
Removes quotes from beginning and end of string.
Definition: helpers.cpp:121
std::string rightTrim(std::string text)
Trims whitespace from right (end) of string.
Definition: helpers.cpp:47
rohdeschwarz::instruments::vna::PreserveDataFormat definition
rohdeschwarz::to_vector(), rohdeschwarz::to_vector_complex_double() definitions and implementations
rohdeschwarz::instruments::vna::Trace definition
rohdeschwarz::instruments::vna::Vna definition