mirror of
https://github.com/galera951/experiment-automation.git
synced 2024-11-25 15:15:52 +03:00
Working with hardware
This commit is contained in:
parent
860c3dc802
commit
e718654bd7
BIN
project/device
Executable file
BIN
project/device
Executable file
Binary file not shown.
52
project/device.cpp
Normal file
52
project/device.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user