Esempio n. 1
0
    def cmd_serial_load(self, cmd_str):
        self.cmd_str_load = cmd_str
        try:
            if self.conn_load is None:
                raise batt.BattError('Communications port to load not open')

            self.conn_load.flushInput()
            self.conn_load.write(cmd_str)
        except Exception, e:
             raise batt.BattError(str(e))
Esempio n. 2
0
    def cmd_serial(self, cmd_str):
        self.cmd_str = cmd_str
        try:
            if self.conn is None:
                raise batt.BattError('Communications port to power supply not open')

            self.conn.flushInput()
            self.conn.write(cmd_str)
        except Exception, e:
             raise batt.BattError(str(e))
Esempio n. 3
0
 def cmd(self, cmd_str):
     self.cmd_str = cmd_str
     # self.ts.log_debug('cmd_str = %s' % cmd_str)
     try:
         self._cmd(cmd_str)
         resp = self._query('SYSTem:ERRor?\n') #\r
         #self.ts.log_debug('error resp = %s' % resp)
         if len(resp) > 0:
             if resp[0] != '0':
                 raise batt.BattError(resp + ' ' + self.cmd_str)
     except Exception, e:
         raise batt.BattError(str(e))
Esempio n. 4
0
 def cmd_load(self, cmd_str):
     self.cmd_str_load = cmd_str
     # self.ts.log_debug('cmd_str = %s' % cmd_str)
     try:
         self._cmd_load(cmd_str)
     except Exception, e:
         raise batt.BattError(str(e))
Esempio n. 5
0
 def cmd_usb(self, cmd_str):
     try:
         if self.conn is None:
             self.ts.log('USB device = %s' % self.usb_name)
             rm = visa.ResourceManager()
             self.conn = rm.open_resource(self.usb_name)
         #self.conn.write('*RST\n')
         self.conn.write('*CLS\n')
         self.conn.write(cmd_str)
     except Exception, e:
         raise batt.BattError(str(e))
Esempio n. 6
0
    def open(self):
        """
        Open the communications resources associated with the grid simulator.
        """
        try:
            self.conn = serial.Serial(port=self.serial_port, baudrate=self.baudrate, bytesize=8, stopbits=1,
                                           xonxoff=0, timeout=self.timeout, writeTimeout=self.write_timeout)

            time.sleep(2)
            #self.cmd('CONFigure:REMote ON\n')
        except Exception, e:
            raise batt.BattError(str(e))
Esempio n. 7
0
    def query_usb(self, cmd_str):
        # setup connection if not already established.
        try:
            if self.conn is None:
                self.ts.log('USB device = %s' % self.usb_name)
                rm = visa.ResourceManager()
                self.conn = rm.open_resource(self.usb_name)
            resp = self.conn.query(cmd_str)
            #self.ts.log_debug('cmd_str = %s, resp = %s' % (cmd_str, resp))

        except Exception, e:
            raise batt.BattError('Timeout waiting for response')
Esempio n. 8
0
    def cmd_tcp_load(self, cmd_str):
        try:
            if self.conn_load is None:
                self.ts.log('ipaddr = %s  ipport = %s' % (self.ipaddr_load, self.ipport_load))
                self.conn_load = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                self.conn_load.settimeout(self.timeout_load)
                self.conn_load.connect((self.ipaddr_load, self.ipport_load))

            # print 'cmd> %s' % (cmd_str)
            self.conn_load.send(cmd_str)
        except Exception, e:
            raise batt.BattError(str(e))
Esempio n. 9
0
    def open_load(self):
        """
        Open the communications resources associated with the grid simulator.
        """
        try:
            self.conn_load = serial.Serial(port=self.serial_port_load, baudrate=self.baudrate_load,
                                           bytesize=8, stopbits=1,
                                           xonxoff=0, timeout=self.timeout_load,
                                           writeTimeout=self.write_timeout_load)
            time.sleep(2)

        except Exception, e:
            raise batt.BattError(str(e))
Esempio n. 10
0
 def query_serial_load(self, cmd_str):
     resp = ''
     more_data = True
     self.cmd_serial_load(cmd_str)
     while more_data:
         try:
             count = self.conn_load.inWaiting()
             if count < 1:
                 count = 1
             data = self.conn_load.read(count)
             if len(data) > 0:
                 for d in data:
                     resp += d
                     if d == '\n':
                         more_data = False
                         break
             else:
                 raise batt.BattError('Timeout waiting for response')
         except batt.BattError:
             raise
         except Exception, e:
             raise batt.BattError('Timeout waiting for response - More data problem')
Esempio n. 11
0
    def query_tcp_load(self, cmd_str):
        resp = ''
        more_data = True

        self._cmd_load(cmd_str)

        while more_data:
            try:
                data = self.conn_load.recv(self.buffer_size_load)
                if len(data) > 0:
                    for d in data:
                        resp += d
                        if d == '\n': #\r
                            more_data = False
                            break
            except Exception, e:
                raise batt.BattError('Timeout waiting for response')
Esempio n. 12
0
 def query_load(self, cmd_str):
     # self.ts.log_debug('query cmd_str = %s' % cmd_str)
     try:
         resp = self._query_load(cmd_str).strip()
     except Exception, e:
         raise batt.BattError(str(e))