diff --git a/project/device b/project/device new file mode 100755 index 0000000..de85273 Binary files /dev/null and b/project/device differ diff --git a/project/device.cpp b/project/device.cpp new file mode 100644 index 0000000..a40942f --- /dev/null +++ b/project/device.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +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; +}