Merge remote-tracking branch 'origin/main'

This commit is contained in:
Lugovtsov Gleb 2022-11-12 16:55:54 +03:00
commit 40cee3bf4c
19 changed files with 297 additions and 1 deletions

View File

@ -370,7 +370,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
"version": "3.10.6"
}
},
"nbformat": 4,

BIN
3.5.1-ne-plasma/latex.zip Normal file

Binary file not shown.

Binary file not shown.

BIN
3.6.1-spectrum/latex.zip Normal file

Binary file not shown.

Binary file not shown.

6
project/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*test*
*tmp*
.vscode
*.exe
*.o
main

View File

@ -0,0 +1,44 @@
#include "Device.hpp"
Device::Device(std::string path_name) : root_path("/dev/" + path_name)
{
std::string response = query("*IDN?");
response.erase(0, response.find(',') + 1);
response.erase(response.find(','));
name = response;
}
void Device::command(std::string comm)
{
std::ofstream out;
out.open(root_path);
if (!out.is_open())
std::cerr << "**ERROR** file is not open to output." << std::endl;
else
{
out << comm;
out.close();
}
}
std::string Device::query(std::string comm)
{
command(comm);
std::string buffer;
std::ifstream in;
in.open(root_path);
if (!in.is_open())
std::cerr << "**ERROR** file is not open to input." << std::endl;
else
{
std::getline(in, buffer);
in.close();
}
return buffer;
}

View File

@ -0,0 +1,25 @@
#pragma once
#include<fstream>
#include<iostream>
#include<string>
class Device
{
public:
Device(std::string path_name);
std::string get_name()
{
return name;
}
void command(std::string comm);
std::string query(std::string comm);
protected:
std::string name;
std::string root_path;
};

View File

@ -0,0 +1,2 @@
#include "Generator.hpp"

View File

@ -0,0 +1,54 @@
#pragma once
#include "Device.hpp"
class Generator : public Device
{
public:
Generator(std::string path_name) : Device(path_name), m_channel("C1") {}
void set_channel(size_t channel)
{
if (channel == 1 || channel == 2)
m_channel = "C" + std::to_string(channel);
else
std::cerr << "Invalid channel" << std::endl;
}
void buzz()
{
command("BUZZ ON");
}
void set_waveform(std::string waveform)
{
command(m_channel + ":BSWV WVTP," + waveform);
}
void set_frequency(double frequency)
{
command(m_channel + ":BSWV FRQ," + std::to_string(frequency));
}
void set_period(double period)
{
command(m_channel + ":BSWV PERI," + std::to_string(period));
}
void set_amplitude(double amplitude)
{
command(m_channel + ":BSWV AMP," + std::to_string(amplitude));
}
void set_offset(double offset)
{
command(m_channel + ":BSWV OFST," + std::to_string(offset));
}
void set_phase(double phase)
{
command(m_channel + ":BSWV PHSE," + std::to_string(phase));
}
private:
std::string m_channel;
};

26
project/hardware/Makefile Normal file
View File

@ -0,0 +1,26 @@
CC=g++
CFLAGS=-c
EXECUTABLE=start
all: $(EXECUTABLE)
$(EXECUTABLE): main.o Device.o Generator.o Oscilloscope.o
$(CC) main.o Device.o Generator.o Oscilloscope.o -o main
main.o: main.cpp
$(CC) $(CFLAGS) main.cpp
Device.o: Device.cpp
$(CC) $(CFLAGS) Device.cpp
Generator.o: Generator.cpp
$(CC) $(CFLAGS) Generator.cpp
Oscilloscope.o: Oscilloscope.cpp
$(CC) $(CFLAGS) Oscilloscope.cpp
clean:
rm -f main
rm -f *.o
.PNONY: all clean

View File

@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include <string>
#include "Oscilloscope.hpp"
class Measurement
{
public:
Measurement() = default;
Measurement(std::string name_) : name(name_) { }
Measurement(std::string stat_response, bool)
{
size_t name_start = stat_response.find(" C") + 5;
size_t name_end = stat_response.find(":");
name = stat_response.substr(name_start, name_end - name_start);
}
// private:
std::string name;
double mean;
double min;
double max;
double std_dev;
double count;
};

View File

@ -0,0 +1 @@
#include "Oscilloscope.hpp"

View File

@ -0,0 +1,61 @@
#pragma once
#include "Device.hpp"
#include "Measurement.hpp"
#include <string>
#include <unistd.h>
class Oscilloscope : public Device
{
public:
Oscilloscope(std::string path_name) : Device(path_name), m_channel("C1") {}
void set_channel(size_t channel)
{
if (channel == 1 || channel == 2)
m_channel = "C" + std::to_string(channel);
else
std::cerr << "Invalid channel" << std::endl;
}
Measurement get_pkpk()
{
comm_param_custom("PKPK");
comm_param_stat(1);
// size_t count = 0;
// while (count <= 20)
// {
// std::string response = quer_param_value("STAT1");
// size_t count_ind = response.find("count,") + 5;
// std::string count_str = response.substr(count_ind);
// std::cerr << count_str;
// comm_param_stat(0);
// count = std::stoi(count_str);
// }
std::string response = quer_param_value("STAT1");
comm_param_stat(0);
std::cout << response << std::endl;
return Measurement(response, 1);
}
private:
void comm_param_custom(std::string param)
{
command("PACU " + param + "," + m_channel);
}
void comm_param_stat(bool condition)
{
command("PASTAT " + condition ? "ON" : "OFF");
}
std::string quer_param_value(std::string custom)
{
return query("PAVA? " + custom);
}
std::string m_channel;
};

36
project/hardware/main.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "Generator.hpp"
#include "Oscilloscope.hpp"
#include <vector>
#include <unistd.h>
int main() {
// initialize generator and oscilloscope
std::string generator_path;
std::string oscilloscope_path;
for (size_t i = 0; i < 2; i++) {
auto path = "usbtmc" + std::to_string(i);
Device device(path);
if (device.get_name() == "AKIP-3409-4")
generator_path = path;
else if (device.get_name() == "AKIP-4131/1")
oscilloscope_path = path;
else {
std::cerr << "Devices not available!" << std::endl;
return EXIT_FAILURE;
}
}
Generator generator(generator_path);
Oscilloscope oscilloscope(oscilloscope_path);
// work with devices
std::cout << oscilloscope.query("C1:WF? DAT2").substr(1, 3) << std::endl;
return EXIT_SUCCESS;
}

13
project/hardware/osc.md Normal file
View File

@ -0,0 +1,13 @@
## Channel commands
TRA -- trace
VDIV -- vertical sensitivity
## MEASURE commands
PACU -- parameter custom
PAVA? -- parameter value
## WAVEFORM commands
#todo

Binary file not shown.