예제 #1
0
 def stop_avantes(self):
     global measuring_thread
     stop_measuring.set()
     measuring_thread.join()
     exitStatus = ava.stopMeasure(self.handler)
     if __debug__:
         log.warning('Stopped infinite measurement with code: %s',
                     ERROR_CODES_MESSAGES[exitStatus])
         """
         Probably, last measurement should be written to a
         file/db
         """
     return True
예제 #2
0
    def readQueue(self):
        while True:
            if self.receive(timeout=None):
                if 'type' in self.message.keys():
                    switch = self.switch_case(self.message['type'])
                    if switch == False:
                        if __debug__:
                            log.warning('Exiting')
                        break

        # release communication with the device
        if __debug__:
            log.warning('Removing the device')
        self.closeRecvQueue()
        self.device.release()
예제 #3
0
    def measure_avantes(self):
        global MEASUREMENT_TIMEOUT
        global is_measurement_available
        global measuring_thread

        exitStatus = ava.prepareMeasure(self.handler, self.cfg)
        if __debug__:
            log.warning('Prepare measurenet function return %s',
                        ERROR_CODES_MESSAGES[exitStatus])
        if exitStatus == 0:
            if self.data.type != 'black':
                ava.setDigitalOut(self.handler, c_ubyte(3), c_ubyte(1))
            else:
                ava.setDigitalOut(self.handler, c_ubyte(3), c_ubyte(0))

            if self.cfg.amount == -1:
                # infinite measurement
                exitStatus = ava.measure(self.handler,
                                         call_back,
                                         c_short(self.cfg.amount))

                measuring_thread = threading.Thread(target=self.infinite_measure)
                measuring_thread.start()
            else:
                exitStatus = ava.measure(self.handler,
                                         call_back,
                                         c_short(self.cfg.amount))
                if __debug__:
                    log.warning('Measurement function return %s',
                                ERROR_CODES_MESSAGES[exitStatus])

                if exitStatus == 0:
                    """
                    Main thread stop as a workaround for
                    Incorrect behavior
                    """
                    if not is_measurement_available.wait(timeout=MEASUREMENT_TIMEOUT):
                        if __debug__:
                            log.error('Measurement timeout occur %s',
                                      ERROR_CODES_MESSAGES[exitStatus])
                        return False
                    else:
                        is_measurement_available.clear()
                        # arbitrary defined timeout time
                        return self.avantesGetScopeData()
        return False
예제 #4
0
    def avantesGetScopeData(self):
        """
        Scoped data should be collected as many times,
        as measurement amount was set
        (amount of measurements)
        """
        for i in range (0, self.cfg.amount):
            """
            Data might not be ready yet,
            so a procedure will be repeated a few more times,
            for successful data collection
            """
            timeout = time.time() + 6
            while time.time() < timeout:
                time.sleep(0.5)
                exitStatus = ava.getScopeData(self.handler,
                                              c_uint(1),
                                              self.data.c_double_array)

                if exitStatus != 0:
                    if __debug__:
                        log.error('Cannot get scoped data %s',
                                  ERROR_CODES_MESSAGES[exitStatus])
                else:
                    break

            """
            Device hadn't sent the data
            errors in communication might be
            """
            if exitStatus != 0:
                if __debug__:
                    log.warning('Data receiving timeout')
                return False

            self.avantesSetMeasAttribute()
            if self.data.type == 'analyte':
                exitStatus = self.data.calcAbsorbance()

        return True
예제 #5
0
 def eventFire(self, event, data): 
     obj = events.EVENTS[event](data)
     if event in init.events.EVENTS:
         obj = events.Event(event, data)
     elif event in init.events.CUSTOM_EVENTS:
         obj = events.EventCustom(event, data)
     elif event in init.events.PLUGIN_EVENTS:
         obj = events.EventPlugin(event, data)
     else:
         return log.warning('Unknown/Unregistered event was fired!')
         
     for i in self.Listeners.keys():
         if i == event:
             for listener in self.Listeners[i]:
                 thread.start_new_thread(listener, (obj, time.time()))
             break
     return obj
예제 #6
0
    def buildReply(self, message):
        reply = {'reply':str(message)}
        return reply

    @_if_debug(log)
    def readQueue(self):
        while True:
            if self.receive(timeout=None):
                if 'type' in self.message.keys():
                    switch = self.switch_case(self.message['type'])
                    if switch == False:
                        if __debug__:
                            log.warning('Exiting')
                        break

        # release communication with the device
        if __debug__:
            log.warning('Removing the device')
        self.closeRecvQueue()
        self.device.release()

args = ReceiverParser().getArgs()
mq_receiver = Receiver(args)
if mq_receiver.setRecvQueue(args.id):
    log.info('New queue created %s', args.id)
    mq_receiver.readQueue()
else:
    log.warning('Using old queue %s', args.id)
    mq_receiver.readQueue()