Lugovtsov/project/hardware/legacy/Device.cpp

45 lines
864 B
C++
Raw Normal View History

2022-10-31 14:07:36 +03:00
#include "Device.hpp"
2022-11-01 16:18:53 +03:00
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;
}
2022-11-28 18:31:51 +03:00
void Device::command(std::string const &comm) const
2022-11-01 16:18:53 +03:00
{
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();
}
}
2022-11-28 18:31:51 +03:00
std::string Device::query(std::string const &comm) const
2022-11-01 16:18:53 +03:00
{
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;
2022-11-01 14:52:12 +03:00
}