Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #include <fcntl.h> // Contains file controls like O_RDWR
  6. #include <errno.h> // Error integer and strerror() function
  7. #include <termios.h> // Contains POSIX terminal control definitions
  8. #include <unistd.h> // write(), read(), close()
  9.  
  10.  
  11. using namespace std;
  12.  
  13. class PowerSupplyOp {
  14.     public:
  15.  
  16.     float V_conversion=1.812*10**(-3);  //voltage conversion factor
  17.     float I_conversion=4.980*10**(-3);   //current conversion factor (mA)
  18.     char STX[] = "02";          //start of text - fixed
  19.     char ETX[] = "03";          //end of text - fixed
  20.     char CR[] = "0D";           //delimiter - fixed
  21.  
  22.  
  23.     char convert(char command) //convert command to hexadecimal and get a bytearray sum??
  24.     {
  25.  
  26.  
  27.     }
  28.  
  29.     char checksum(char sum_command, double sum_voltage) //necessary for communication with power supply
  30.     {
  31.  
  32.  
  33.     }
  34.  
  35.  
  36.  
  37.     void start() //Connect to the Power supply
  38.     {
  39.         ser = open("/dev/ttyUSB0", O_RDWR);
  40.         if (ser <0){
  41.             printf("Error %i from open: %s\n", errno, strerror(errno));
  42.         }
  43.  
  44.         // Create new termios struc to set configuration
  45.         struct termios tty;
  46.         memset(&tty, 0, sizeof tty);
  47.  
  48.         // Read in existing settings, and handle any error
  49.         if(tcgetattr(serial_port, &tty) != 0) {
  50.             printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
  51.         }
  52.         tty.c_cflag |= PARENB;  // Set parity bit, enabling parity
  53.  
  54.         tty.c_cflag &= ~CSTOPB; // One stop bit used in communication
  55.  
  56.         tty.c_cflag |= CS8; // 8 bits per byte
  57.  
  58.         // Set baud rate
  59.         cfsetispeed(&tty, B38400);
  60.         cfsetospeed(&tty, B38400);
  61.  
  62.         // Save tty settings, also checking for error
  63.         if (tcsetattr(serial_port, TCSANOW, &tty) != 0) {
  64.             printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
  65.         }}
  66.  
  67.  
  68.     void stop() //disconnect from the Power supply
  69.     {
  70.         close(ser)
  71.     }
  72.  
  73.     char convert()
  74.  
  75.  
  76.     std::vector<double> getVolt() //outputs the Voltage for the four channels (same value for all channels), similar to getValue
  77.     {
  78.  
  79.     }
  80.  
  81.     std::vector<double> getCurr() //outputs the Current for the four channels (same value for all channels)
  82.     {
  83.  
  84.     }
  85.  
  86.  
  87.     void loadConfig(double u0) //sets the voltage, similar to setValue
  88.     {
  89.  
  90.     }
  91.  
  92. };
  93.  
  94.  
  95. int main () {
  96.  
  97.  
  98.  
  99.   return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement