示例#1
0
文件: cbox.py 项目: umithardal/nicos
 def _calculatePossibleCapacities(self):
     caps = {}
     for c3bits in xrange(16):
         for c1c2serial in xrange(2):
             for c1bits in xrange(64):
                 for c2bits in xrange(32):
                     args = (c1bits, c2bits, c3bits, c1c2serial)
                     caps[self._calcSerialCapacity(*args)] = args
     odict = OrderedDict(sorted(iteritems(caps)))
     return odict
示例#2
0
文件: cbox.py 项目: umithardal/nicos
    def _getCurrentAdjustmentQualityOLD(self):
        """Reads the current adjustment quality multiple times (defined by
        "tuning_points") and returns the median."""
        revp = numpy.median([
            self._adevs['pa_revp'].read(0) for _ in xrange(self.tuning_points)
        ])
        fwdp = numpy.median([
            self._adevs['pa_fwdp'].read(0) for _ in xrange(self.tuning_points)
        ])

        return (fwdp - revp) / (fwdp + revp)
示例#3
0
 def _get_current_table_data(self):
     """Get the full table data of the current table in the correct storage
     format."""
     result = {}
     for i in xrange(self.tableWidget.rowCount()):
         row = self._get_row_data(i)
         echotime = row['echotime']
         del row['echotime']
         result[echotime] = row
     return result
示例#4
0
文件: cbox.py 项目: umithardal/nicos
    def _getCurrentAdjustmentQuality(self):
        """Reads the current adjustment quality multiple times (defined by
        "tuning_points") and returns the median."""
        current_coil1 = numpy.median([
            self._adevs['coil_amp'].read(0) for _ in xrange(self.tuning_points)
        ])

        # current_coil2 = numpy.median([self._adevs['coil2_amp'].read(0)
        #                         for _ in xrange(self.tuning_points)])

        return current_coil1
示例#5
0
    def _worker_inner(self):
        data = b''
        process = self._process_data

        while not self._stoprequest:
            if self._should_connect:
                if not self._socket:
                    self._connect()
                    if not self._socket:
                        self._wait_retry()
                        continue
            else:
                if self._socket:
                    self._disconnect()
                self._wait_retry()
                continue

            # process data so far
            data = process(data)

            # wait for a whole line of data to arrive
            while b'\n' not in data and self._socket and self._should_connect \
                  and not self._stoprequest:

                # optionally do some action while waiting
                self._wait_data()

                if self._queue.empty():
                    # NOTE: the queue.empty() check is not 100% reliable, but
                    # that is not important here: all we care is about not
                    # having the select always return immediately for writing
                    writelist = []
                else:
                    writelist = [self._socket]

                # read or write some data
                while 1:
                    try:
                        res = select.select([self._socket], writelist, [],
                                            self._selecttimeout)
                    except EnvironmentError as e:
                        if e.errno == errno.EINTR:
                            continue
                        raise
                    except TypeError:
                        # socket was None, let the outer loop handle that
                        res = ([], [], [])
                    break

                if res[1]:
                    # determine if something needs to be sent
                    tosend = ''
                    itemcount = 0
                    try:
                        # bunch a few messages together, but not unlimited
                        for _ in xrange(10):
                            tosend += self._queue.get(False)
                            itemcount += 1
                    except queue.Empty:
                        pass
                    # write data
                    try:
                        self._socket.sendall(to_utf8(tosend))
                    except Exception:
                        self._disconnect('disconnect: send failed')
                        # report data as processed, but then re-queue it to send
                        # after reconnect
                        for _ in range(itemcount):
                            self._queue.task_done()
                        data = b''
                        self._queue.put(tosend)
                        break
                    for _ in range(itemcount):
                        self._queue.task_done()
                if res[0]:
                    # got some data
                    try:
                        newdata = self._socket.recv(BUFSIZE)
                    except Exception:
                        newdata = b''
                    if not newdata:
                        # no new data from blocking read -> abort
                        self._disconnect('disconnect: recv failed')
                        data = b''
                        break
                    data += newdata

        if self._socket:
            # send rest of data
            tosend = ''
            itemcount = 0
            try:
                while 1:
                    tosend += self._queue.get(False)
                    itemcount += 1
            except queue.Empty:
                pass
            try:
                self._socket.sendall(to_utf8(tosend))
            except Exception:
                self.log.debug('exception while sending last batch of updates',
                               exc=1)
                # no reraise, we'll disconnect below anyways
            for _ in range(itemcount):
                self._queue.task_done()

        # end of while loop
        self._disconnect()