diff --git a/project/Device.cpp b/project/Device.cpp new file mode 100644 index 0000000..d712317 --- /dev/null +++ b/project/Device.cpp @@ -0,0 +1,3 @@ +#include "Device.hpp" + + diff --git a/project/Device.hpp b/project/Device.hpp new file mode 100644 index 0000000..e24f4ad --- /dev/null +++ b/project/Device.hpp @@ -0,0 +1,94 @@ +#include +#include +#include + +class Device { +public: + Device(std::string path_name): root_path("/dev/" + path_name) { + std::string idn = query("*IDN?"); + idn.erase(0, idn.find(',') + 1); + idn.erase(idn.find(',')); + + name = idn; + } + +protected: + void command(std::string comm) { + 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(); + } + } + + std::string query(std::string comm) { + 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; + } + +public: + std::string name; + std::string root_path; +}; + + +class Generator: public Device { +public: + Generator(std::string path_name): Device(path_name), channel("C1") { } + + void buzz() { + command("BUZZ ON"); + } + + void basic_wave( + size_t channel, + std::string type, + double frequency, + double period, + double amplitude, + double offset, + double phase + ); + + void set_channel(size_t ch) { + if (ch == 1 || ch == 2) channel = "C" + std::to_string(ch); + else std::cerr << "Invalid channel" << std::endl; + } + + void set_waveform(std::string type) { + command(channel + ":BSWV WVTP," + type); + } + +private: + std::string channel; +}; + + +class Oscilloscope: public Device { +public: + Oscilloscope(std::string path_name): Device(path_name) { } +}; + + + + + + + + diff --git a/project/Makefile b/project/Makefile new file mode 100644 index 0000000..5b34e72 --- /dev/null +++ b/project/Makefile @@ -0,0 +1,13 @@ +all: main + +main: main.o + g++ main.o -o main + +main.o: main.cpp + g++ -c main.cpp -o main.o + +clean: + rm -f main + rm -f *.o + +.PNONY: all clean diff --git a/project/device b/project/device deleted file mode 100755 index de85273..0000000 Binary files a/project/device and /dev/null differ diff --git a/project/device.cpp b/project/device.cpp deleted file mode 100644 index a40942f..0000000 --- a/project/device.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#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; -} diff --git a/project/main b/project/main new file mode 100755 index 0000000..6bb0db0 Binary files /dev/null and b/project/main differ diff --git a/project/main.cpp b/project/main.cpp new file mode 100644 index 0000000..4fc2754 --- /dev/null +++ b/project/main.cpp @@ -0,0 +1,39 @@ +#include "Device.hpp" +#include +#include + +int main() { + + // initialize generator and oscilloscope + + std::string generator_path; + std::string oscilloscope_path; + + for (size_t i = 0; i < 2; i++) { + auto path = "usbtmc" + std::to_string(i); + Device device(path); + + if (device.name == "AKIP-3409-4") generator_path = path; + else if (device.name == "AKIP-4131/1") oscilloscope_path = path; + else { + std::cerr << "Devices not available!" << std::endl; + return EXIT_FAILURE; + } + } + + Generator generator(generator_path); + Oscilloscope oscilloscope(oscilloscope_path); + + + // work with devices + + //generator.buzz(); + + std::string waveform; + std::cout << "Input waveform (SINE, SQUARE, RAMP, PULSE, NOISE, ARB, DC, PRBS, IQ):" << std::endl; + std::cin >> waveform; + + generator.set_waveform(waveform); + + return EXIT_SUCCESS; +} diff --git a/project/main.o b/project/main.o new file mode 100644 index 0000000..2519023 Binary files /dev/null and b/project/main.o differ diff --git a/project/hard_standarts.md b/project/materials/hard_standart.md similarity index 100% rename from project/hard_standarts.md rename to project/materials/hard_standart.md