Working with hardware

This commit is contained in:
Глеб Луговцов 2022-10-24 13:30:23 +03:00
parent 860c3dc802
commit e718654bd7
2 changed files with 52 additions and 0 deletions

BIN
project/device Executable file

Binary file not shown.

52
project/device.cpp Normal file
View File

@ -0,0 +1,52 @@
#include<fstream>
#include<iostream>
#include<string>
class Device
{
public:
Device(std::string name): root_path("/dev/" + name) { }
void send_command(std::string command)
{
std::ofstream out;
out.open(root_path);
if(!out.is_open()) {
std::cerr << "**ERROR** file is not open to output." << std::endl;
} else {
out << command;
out.close();
}
}
std::string accept_command()
{
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;
}
private:
std::string root_path;
std::string buffer;
};
int main()
{
Device generator("usbtmc0");
generator.send_command("*IDN?");
std::cout << generator.accept_command() << std::endl;
return 0;
}