Lugovtsov/project/hardware/Generator.cpp

64 lines
1.3 KiB
C++
Raw Normal View History

2022-11-01 16:18:53 +03:00
#include "Generator.hpp"
2022-11-28 23:17:12 +03:00
#include <string>
#include <vector>
2022-11-28 18:31:51 +03:00
#include <fstream>
2022-11-28 23:17:12 +03:00
#include <filesystem>
namespace fs = std::filesystem;
2022-11-28 18:31:51 +03:00
Generator::Generator() : m_channel("C1")
{
2022-11-28 23:17:12 +03:00
auto devices_path = files_path("/dev/usbtmc");
bool success = false;
for (auto const &device_path : devices_path)
{
m_root_path = device_path;
std::string response = query("*IDN?");
response.erase(0, response.find(',') + 1);
response.erase(response.find(','));
if (response == "AKIP-3409-4")
{
success = true;
break;
}
}
2022-11-28 18:31:51 +03:00
2022-11-28 23:17:12 +03:00
if (!success)
throw std::runtime_error("Generator (AKIP-3409-4) is not available!");
2022-11-28 18:31:51 +03:00
}
void Generator::command(std::string const &comm) const
{
std::ofstream out;
out.open(m_root_path);
if (!out.is_open())
std::cerr << "**ERROR** file is not open to output." << std::endl;
else
{
out << comm;
out.close();
}
}
std::string Generator::query(std::string const &comm) const
{
command(comm);
std::string buffer;
std::ifstream in;
in.open(m_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;
}