Ejemplo n.º 1
0
    def test_001_initialize(self, close_transaction=True):
        """
        - start transaction
        - initialize
        - return transaction id
        """
        
        self._check_skip()
        
        # Begin an explicit transaction.
        reply = yield self.ia_client.start_transaction(0)
        success = reply['success']
        tid = reply['transaction_id']
        self.assert_(InstErrorCode.is_ok(success))
        self.assertEqual(type(tid),str)
        self.assertEqual(len(tid),36)
    
        log.debug("test_001_initialize tid = " + str(tid))
        
        # Issue state transition commands to bring the agent into
        # observatory mode.
        
        # Initialize the agent.
        cmd = [AgentCommand.TRANSITION,AgentEvent.INITIALIZE]
        reply = yield self.ia_client.execute_observatory(cmd,tid) 
        success = reply['success']
        result = reply['result']
        
        self.assert_(InstErrorCode.is_ok(success))
        
        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 2
0
    def test_021_acquisition_start_wait_stop(self, close_transaction=True):
        """
        - go active an run
        - execute START_AUTO_SAMPLING
        - wait for a few seconds
        - execute STOP_AUTO_SAMPLING
        """
        
        self._check_skip()
        
        tid = yield self.test_002_go_active_run(False) 
        
        channel = SiamDriverChannel.INSTRUMENT
 
        
        # Start autosampling
        # TODO using hard-code "val" which is a channel in the TEstInstrument
        acq_channel = "val"
        chans = [acq_channel]
        cmd = [DriverCommand.START_AUTO_SAMPLING]
        reply = yield self.ia_client.execute_device(chans,cmd,tid)
        success = reply['success']
        result = reply['result']

        # temporary: instead of failing, skip
        if not InstErrorCode.is_ok(success): raise unittest.SkipTest(str(result))
        
        self.assert_(InstErrorCode.is_ok(success))

        print red('=============== autosampling started')
        
        # Wait for a few samples to arrive.
        yield pu.asleep(30)
        
        # Stop autosampling.
        print red('=============== stopping autosampling ')
        chans = [acq_channel]
        cmd = [DriverCommand.STOP_AUTO_SAMPLING]  #,'GETDATA']
        while True:
            reply = yield self.ia_client.execute_device(chans,cmd,tid)
            success = reply['success']
            result = reply['result']
            
            if InstErrorCode.is_ok(success):
                break
            
            elif InstErrorCode.is_equal(success,InstErrorCode.TIMEOUT):
                pass
            
            else:
                self.fail('Stop autosample failed with error: '+str(success))
            
        print red('=============== autosampling result ' + str(result))
        
        self.assert_(InstErrorCode.is_ok(success))
        
        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 3
0
    def test_021_acquisition_start_wait_stop(self, close_transaction=True):
        """
        - go active an run
        - execute START_AUTO_SAMPLING
        - wait for a few seconds
        - execute STOP_AUTO_SAMPLING
        """

        self._check_skip()

        tid = yield self.test_002_go_active_run(False)

        channel = SiamDriverChannel.INSTRUMENT

        # Start autosampling
        # TODO using hard-code "val" which is a channel in the TEstInstrument
        acq_channel = "val"
        chans = [acq_channel]
        cmd = [DriverCommand.START_AUTO_SAMPLING]
        reply = yield self.ia_client.execute_device(chans, cmd, tid)
        success = reply['success']
        result = reply['result']

        # temporary: instead of failing, skip
        if not InstErrorCode.is_ok(success):
            raise unittest.SkipTest(str(result))

        self.assert_(InstErrorCode.is_ok(success))

        print red('=============== autosampling started')

        # Wait for a few samples to arrive.
        yield pu.asleep(30)

        # Stop autosampling.
        print red('=============== stopping autosampling ')
        chans = [acq_channel]
        cmd = [DriverCommand.STOP_AUTO_SAMPLING]  #,'GETDATA']
        while True:
            reply = yield self.ia_client.execute_device(chans, cmd, tid)
            success = reply['success']
            result = reply['result']

            if InstErrorCode.is_ok(success):
                break

            elif InstErrorCode.is_equal(success, InstErrorCode.TIMEOUT):
                pass

            else:
                self.fail('Stop autosample failed with error: ' + str(success))

        print red('=============== autosampling result ' + str(result))

        self.assert_(InstErrorCode.is_ok(success))

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 4
0
    def test_001_initialize(self, close_transaction=True):
        """
        - start transaction
        - initialize
        - return transaction id
        """

        self._check_skip()

        # Begin an explicit transaction.
        reply = yield self.ia_client.start_transaction(0)
        success = reply['success']
        tid = reply['transaction_id']
        self.assert_(InstErrorCode.is_ok(success))
        self.assertEqual(type(tid), str)
        self.assertEqual(len(tid), 36)

        log.debug("test_001_initialize tid = " + str(tid))

        # Issue state transition commands to bring the agent into
        # observatory mode.

        # Initialize the agent.
        cmd = [AgentCommand.TRANSITION, AgentEvent.INITIALIZE]
        reply = yield self.ia_client.execute_observatory(cmd, tid)
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 5
0
    def test_020_acquisition_get_last_sample(self, close_transaction=True):
        """
        - go active and run
        - execute GET_LAST_SAMPLE
        - verify successful completion
        """

        self._check_skip()

        tid = yield self.test_002_go_active_run(False)

        chans = [SiamDriverChannel.INSTRUMENT]
        cmd = [SiamDriverCommand.GET_LAST_SAMPLE]
        reply = yield self.ia_client.execute_device(chans, cmd, tid)
        success = reply['success']
        result = reply['result']

        # temporary: instead of failing, skip
        if not InstErrorCode.is_ok(success):
            raise unittest.SkipTest(str(result))

        self.assert_(InstErrorCode.is_ok(success))

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 6
0
    def test_003_go_active_run_reset(self, close_transaction=True):
        """
        TODO
        """

        self._check_skip()
        
        tid = yield self.test_002_go_active_run(False) 

        # Reset the agent to disconnect and bring down the driver and client.
        cmd = [AgentCommand.TRANSITION,AgentEvent.RESET]
        reply = yield self.ia_client.execute_observatory(cmd,tid)
        success = reply['success']
        result = reply['result']
        self.assert_(InstErrorCode.is_ok(success))

        # Check agent state.
        params = [AgentStatus.AGENT_STATE]
        reply = yield self.ia_client.get_observatory_status(params,tid)
        success = reply['success']
        result = reply['result']
        agent_state = result[AgentStatus.AGENT_STATE][1]
        self.assert_(InstErrorCode.is_ok(success))        
        self.assert_(agent_state == AgentState.UNINITIALIZED)        

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 7
0
    def test_003_go_active_run_reset(self, close_transaction=True):
        """
        TODO
        """

        self._check_skip()

        tid = yield self.test_002_go_active_run(False)

        # Reset the agent to disconnect and bring down the driver and client.
        cmd = [AgentCommand.TRANSITION, AgentEvent.RESET]
        reply = yield self.ia_client.execute_observatory(cmd, tid)
        success = reply['success']
        result = reply['result']
        self.assert_(InstErrorCode.is_ok(success))

        # Check agent state.
        params = [AgentStatus.AGENT_STATE]
        reply = yield self.ia_client.get_observatory_status(params, tid)
        success = reply['success']
        result = reply['result']
        agent_state = result[AgentStatus.AGENT_STATE][1]
        self.assert_(InstErrorCode.is_ok(success))
        self.assert_(agent_state == AgentState.UNINITIALIZED)

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 8
0
    def test_020_acquisition_get_last_sample(self, close_transaction=True):
        """
        - go active and run
        - execute GET_LAST_SAMPLE
        - verify successful completion
        """
        
        self._check_skip()
        
        tid = yield self.test_002_go_active_run(False) 
        
        chans = [SiamDriverChannel.INSTRUMENT]
        cmd = [SiamDriverCommand.GET_LAST_SAMPLE]
        reply = yield self.ia_client.execute_device(chans,cmd,tid)
        success = reply['success']
        result = reply['result']

        # temporary: instead of failing, skip
        if not InstErrorCode.is_ok(success): raise unittest.SkipTest(str(result))
        
        self.assert_(InstErrorCode.is_ok(success))
 
        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 9
0
    def test_005_get_params_subset_good(self):
        """
        - connect
        - get with [(SiamDriverChannel.INSTRUMENT,'startDelayMsec'), (SiamDriverChannel.INSTRUMENT,'diagnosticSampleInterval')]
        - disconnect
        """
        
        self._check_skip()
                
        yield self.__connect()
        
        params = [(SiamDriverChannel.INSTRUMENT,'startDelayMsec'), (SiamDriverChannel.INSTRUMENT,'diagnosticSampleInterval')]
        reply = yield self.driver_client.get(params)
        success = reply['success']
        result = reply['result']      
        self.assert_(InstErrorCode.is_ok(success))  
        
        # verify all returned params are for SiamDriverChannel.INSTRUMENT and are OK (value doesn't matter)
        for key in result:
            ch, pr = key
            self.assertEqual(SiamDriverChannel.INSTRUMENT, ch)
            successParam, val = result[key]
            self.assert_(InstErrorCode.is_ok(successParam))
        

        yield self.__disconnect()
Ejemplo n.º 10
0
    def test_010_params_get_set_verify(self, close_transaction=True):
        """
        - go active and run
        - get params
        - set some params
        - get params and verify
        """

        self._check_skip()

        tid = yield self.test_002_go_active_run(False)

        channel = SiamDriverChannel.INSTRUMENT

        # Get driver parameters.
        params = [(channel, 'all')]
        reply = yield self.ia_client.get_device(params, tid)
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))

        # Strip off individual success vals to create a set params to
        # restore original config later.
        orig_config = dict(map(lambda x: (x[0], x[1][1]), result.items()))

        # set a few parameters
        """these parameters happen to be present in the TestInstrument1 instrument """
        params = {
            (channel, 'startDelayMsec'): '600',
            (channel, 'packetSetSize'): '21'
        }

        setparams = params

        reply = yield self.ia_client.set_device(params, tid)
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))

        # Verify the set changes were made.
        params = [(channel, 'all')]
        reply = yield self.ia_client.get_device(params, tid)
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))

        self.assertEqual(setparams[(channel, 'startDelayMsec')],
                         result[(channel, 'startDelayMsec')][1])
        self.assertEqual(setparams[(channel, 'packetSetSize')],
                         result[(channel, 'packetSetSize')][1])

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 11
0
    def test_010_params_get_set_verify(self, close_transaction=True):
        """
        - go active and run
        - get params
        - set some params
        - get params and verify
        """
        
        self._check_skip()
        
        tid = yield self.test_002_go_active_run(False) 
        
        channel = SiamDriverChannel.INSTRUMENT
 
        # Get driver parameters.
        params = [(channel,'all')]
        reply = yield self.ia_client.get_device(params,tid)
        success = reply['success']
        result = reply['result']
        
        self.assert_(InstErrorCode.is_ok(success))
        
        # Strip off individual success vals to create a set params to
        # restore original config later.
        orig_config = dict(map(lambda x : (x[0],x[1][1]),result.items()))

        # set a few parameters 
        """these parameters happen to be present in the TestInstrument1 instrument """
        params = {(channel,'startDelayMsec'):'600', (channel,'packetSetSize'):'21'}

        setparams = params
        
        reply = yield self.ia_client.set_device(params,tid)
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))

        # Verify the set changes were made.
        params = [(channel,'all')]
        reply = yield self.ia_client.get_device(params,tid)
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))

        self.assertEqual(setparams[(channel,'startDelayMsec')],
                         result[(channel,'startDelayMsec')][1])
        self.assertEqual(setparams[(channel,'packetSetSize')],
                         result[(channel,'packetSetSize')][1])
        
        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 12
0
    def test_002_go_active_run(self, close_transaction=True):
        """
        - initialize
        - GO_ACTIVE
        - check AgentState.IDLE
        - RUN
        - check AgentState.OBSERVATORY_MODE
        """

        self._check_skip()

        tid = yield self.test_001_initialize(False)

        # Connect to the device.
        cmd = [AgentCommand.TRANSITION, AgentEvent.GO_ACTIVE]
        log.debug("About to call self.ia_client.execute_observatory: cmd=" +
                  str(cmd) + ", tid=" + str(tid))
        reply = yield self.ia_client.execute_observatory(cmd, tid)
        success = reply['success']
        result = reply['result']
        self.assert_(InstErrorCode.is_ok(success))

        # Check agent state
        params = [AgentStatus.AGENT_STATE]
        log.debug("About to call self.ia_client.execute_observatory: params=" +
                  str(params) + ", tid=" + str(tid))
        reply = yield self.ia_client.get_observatory_status(params, tid)
        success = reply['success']
        result = reply['result']
        agent_state = result[AgentStatus.AGENT_STATE][1]
        self.assert_(InstErrorCode.is_ok(success))
        self.assert_(agent_state == AgentState.IDLE)

        # Enter observatory mode.
        cmd = [AgentCommand.TRANSITION, AgentEvent.RUN]
        reply = yield self.ia_client.execute_observatory(cmd, tid)
        success = reply['success']
        result = reply['result']
        self.assert_(InstErrorCode.is_ok(success))

        # Check agent state.
        params = [AgentStatus.AGENT_STATE]
        reply = yield self.ia_client.get_observatory_status(params, tid)
        success = reply['success']
        result = reply['result']
        agent_state = result[AgentStatus.AGENT_STATE][1]
        self.assert_(InstErrorCode.is_ok(success))
        self.assert_(agent_state == AgentState.OBSERVATORY_MODE)

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 13
0
    def test_002_go_active_run(self, close_transaction=True):
        """
        - initialize
        - GO_ACTIVE
        - check AgentState.IDLE
        - RUN
        - check AgentState.OBSERVATORY_MODE
        """
        
        self._check_skip()
        
        tid = yield self.test_001_initialize(False) 
        
        # Connect to the device.
        cmd = [AgentCommand.TRANSITION,AgentEvent.GO_ACTIVE]
        log.debug("About to call self.ia_client.execute_observatory: cmd=" +str(cmd)+ ", tid=" + str(tid))
        reply = yield self.ia_client.execute_observatory(cmd,tid) 
        success = reply['success']
        result = reply['result']
        self.assert_(InstErrorCode.is_ok(success))

        # Check agent state
        params = [AgentStatus.AGENT_STATE]
        log.debug("About to call self.ia_client.execute_observatory: params=" +str(params)+ ", tid=" + str(tid))
        reply = yield self.ia_client.get_observatory_status(params, tid)
        success = reply['success']
        result = reply['result']
        agent_state = result[AgentStatus.AGENT_STATE][1]
        self.assert_(InstErrorCode.is_ok(success))        
        self.assert_(agent_state == AgentState.IDLE)
        
        # Enter observatory mode.
        cmd = [AgentCommand.TRANSITION,AgentEvent.RUN]
        reply = yield self.ia_client.execute_observatory(cmd,tid) 
        success = reply['success']
        result = reply['result']
        self.assert_(InstErrorCode.is_ok(success))
                
        # Check agent state.
        params = [AgentStatus.AGENT_STATE]
        reply = yield self.ia_client.get_observatory_status(params,tid)
        success = reply['success']
        result = reply['result']
        agent_state = result[AgentStatus.AGENT_STATE][1]
        self.assert_(InstErrorCode.is_ok(success))        
        self.assert_(agent_state == AgentState.OBSERVATORY_MODE)

        if close_transaction:
            yield self._close_transaction(tid)

        defer.returnValue(tid)
Ejemplo n.º 14
0
    def op_connect(self, content, headers, msg):
        
        # Timeout not implemented for this op.
        timeout = content.get('timeout',None)
        if timeout != None:
            assert(isinstance(timeout,int)), 'Expected integer timeout'
            assert(timeout>0), 'Expected positive timeout'
            pass


        success = self.fsm.on_event(SiamDriverEvent.CONNECT) 
        reply = {'success':success,'result':None}
        if InstErrorCode.is_error(reply['success']):
            yield self.reply_ok(msg, reply)
            return
        
        success = self.fsm.on_event(SiamDriverEvent.CONNECTION_COMPLETE)
        reply['success'] = success
        
        """
        There is no actual "connect"/"disconnect" as the driver interacts 
        via messaging with the SIAM-CI adapter service. 
        We just start our proxy:
        """
        yield self.siamci.start()
        
        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug('op_connect: SiamCiProxy started')
        
        yield self.reply_ok(msg, reply)
Ejemplo n.º 15
0
    def op_configure(self, content, headers, msg):

        assert (isinstance(content, dict)), 'Expected dict content.'
        params = content.get('params', None)
        assert (isinstance(params, dict)), 'Expected dict params.'

        # Timeout not implemented for this op.
        timeout = content.get('timeout', None)
        if timeout != None:
            assert (isinstance(timeout, int)), 'Expected integer timeout'
            assert (timeout > 0), 'Expected positive timeout'
            pass

        # Set up the reply message and validate the configuration parameters.
        # Reply with the error message if the parameters not valid.
        reply = {'success': None, 'result': params}
        reply['success'] = self._validate_configuration(params)

        if InstErrorCode.is_error(reply['success']):
            yield self.reply_ok(msg, reply)
            return

        # Fire EVENT_CONFIGURE with the validated configuration parameters.
        # Set the error message if the event is not handled in the current
        # state.
        reply['success'] = self.fsm.on_event(SiamDriverEvent.CONFIGURE, params)

        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug('op_configure: complete. success = %s' %
                      (reply['success']))

        yield self.reply_ok(msg, reply)
Ejemplo n.º 16
0
    def op_connect(self, content, headers, msg):

        # Timeout not implemented for this op.
        timeout = content.get('timeout', None)
        if timeout != None:
            assert (isinstance(timeout, int)), 'Expected integer timeout'
            assert (timeout > 0), 'Expected positive timeout'
            pass

        success = self.fsm.on_event(SiamDriverEvent.CONNECT)
        reply = {'success': success, 'result': None}
        if InstErrorCode.is_error(reply['success']):
            yield self.reply_ok(msg, reply)
            return

        success = self.fsm.on_event(SiamDriverEvent.CONNECTION_COMPLETE)
        reply['success'] = success
        """
        There is no actual "connect"/"disconnect" as the driver interacts 
        via messaging with the SIAM-CI adapter service. 
        We just start our proxy:
        """
        yield self.siamci.start()

        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug('op_connect: SiamCiProxy started')

        yield self.reply_ok(msg, reply)
Ejemplo n.º 17
0
    def op_disconnect(self, content, headers, msg):

        # Timeout not implemented for this op.
        timeout = content.get('timeout', None)
        if timeout != None:
            assert (isinstance(timeout, int)), 'Expected integer timeout'
            assert (timeout > 0), 'Expected positive timeout'
            pass

        success = self.fsm.on_event(SiamDriverEvent.DISCONNECT)
        reply = {'success': success, 'result': None}

        if InstErrorCode.is_error(reply['success']):
            yield self.reply_ok(msg, reply)
            return

        success = self.fsm.on_event(SiamDriverEvent.DISCONNECT_COMPLETE)
        reply['success'] = success
        """
        @TODO: why calling ''yield self.siamci.stop()'' to stop (terminate) the 
        SiamCiProxy process causes errors?  Here are some of the errors if this
        call is included when running test_siam_driver.py: 
            [process        :780] WARNING:Process bootstrap RPC conv-id=carueda_46740.7#29 timed out!
            [state_object   :113] ERROR:ERROR in StateObject process(event=deactivate)
            [receiver       :169] ERROR:Receiver error: Illegal state change
            [state_object   :132] ERROR:Subsequent ERROR in StateObject error(), ND-ND
        """
        #        yield self.siamci.stop()

        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug('op_disconnect: complete. success = %s' %
                      (reply['success']))

        yield self.reply_ok(msg, reply)
Ejemplo n.º 18
0
    def test_008_get_last_sample(self):
        """
        - connect
        - execute with SiamDriverChannel.INSTRUMENT and SiamDriverCommand.GET_LAST_SAMPLE
        - disconnect
        """
        
        self._check_skip()
        
        yield self.__connect()
        
        channels = [SiamDriverChannel.INSTRUMENT]
        command = [SiamDriverCommand.GET_LAST_SAMPLE]
        timeout = 10
        reply = yield self.driver_client.execute(channels,command,timeout)
            
        success = reply['success']
        result = reply['result']
        
        log.debug("test_010_get_last_sample result =" +str(result))
        
        self.assert_(InstErrorCode.is_ok(success))
        
        assert(isinstance(result, dict))    
        
        # NOTE: the following specific channels are for the TEstInstrument used
        # during development (which cannot be asserted in a general setting, of course) 
#        self.assert_('sequenceNumber' in result)
#        self.assert_('val' in result)
        
        current_state = yield self.driver_client.get_state()
        self.assertEqual(current_state, SiamDriverState.CONNECTED)
        

        yield self.__disconnect()
Ejemplo n.º 19
0
 def __connect_and_get_channels(self):
     """
     @return: the reported channels
     """
     
     self._check_skip()
     
     yield self.__connect()
     
     channels = [SiamDriverChannel.INSTRUMENT]
     command = [SiamDriverCommand.GET_CHANNELS]
     timeout = 10
     reply = yield self.driver_client.execute(channels,command,timeout)
         
     success = reply['success']
     result = reply['result']
     
     log.debug("test_009_get_channels result =" +str(result))
     
     self.assert_(InstErrorCode.is_ok(success))
     
     assert(isinstance(result, (tuple,list)))    
     
     current_state = yield self.driver_client.get_state()
     self.assertEqual(current_state, SiamDriverState.CONNECTED)
     
     defer.returnValue(result)
Ejemplo n.º 20
0
 def test_006_set_params_valid(self):
     """
     - connect
     - set a couple of valid parameters
     - disconnect
     
     @todo: A more complete test would involve the retrieval of the settable parameters,
     ideally along with an indication of valid (range of) values, and then set the 
     parameter with one such value.
     """
     
     self._check_skip()
     
     yield self.__connect()
     
     channel = SiamDriverChannel.INSTRUMENT
     """these parameters happen to be present in the TestInstrument1 instrument """
     params = {(channel,'startDelayMsec'):'600', (channel,'packetSetSize'):'21'}
     reply = yield self.driver_client.set(params)
     success = reply['success']
     result = reply['result']
     
     self.assert_(InstErrorCode.is_ok(success))
     
     assert(isinstance(result, dict))   
     self.assertEqual(result.get("startDelayMsec", None), '600')
     self.assertEqual(result.get("packetSetSize", None), '21')
     
     yield self.__disconnect()
Ejemplo n.º 21
0
    def test_005_get_params_subset_good_and_bad(self):
        """
        - connect
        - get with [(SiamDriverChannel.INSTRUMENT,'startDelayMsec'), (SiamDriverChannel.INSTRUMENT,'INVALID_param')]
        - disconnect
        """
        
        self._check_skip()
                
        yield self.__connect()
        
        params = [(SiamDriverChannel.INSTRUMENT,'startDelayMsec'), (SiamDriverChannel.INSTRUMENT,'INVALID_param')]
        reply = yield self.driver_client.get(params)
        success = reply['success']
        result = reply['result']      
        self.assert_(InstErrorCode.is_error(success))  
        
        #
        # TODO: Note, the adapter returns a single Error when any of the requested
        # params is invalid, ie., does not yet provide discriminated errors.
        # So the result here is None.
#        successParam, val = result[(SiamDriverChannel.INSTRUMENT,'startDelayMsec')]
#        self.assert_(InstErrorCode.is_ok(successParam))
#        
#        successParam, val = result[(SiamDriverChannel.INSTRUMENT,'INVALID_param')]
#        self.assert_(InstErrorCode.is_error(successParam))
        

        yield self.__disconnect()
Ejemplo n.º 22
0
    def op_configure(self, content, headers, msg):
        
        assert(isinstance(content, dict)), 'Expected dict content.'
        params = content.get('params', None)
        assert(isinstance(params, dict)), 'Expected dict params.'
        
        # Timeout not implemented for this op.
        timeout = content.get('timeout', None)
        if timeout != None:
            assert(isinstance(timeout, int)), 'Expected integer timeout'
            assert(timeout > 0), 'Expected positive timeout'
            pass

        # Set up the reply message and validate the configuration parameters.
        # Reply with the error message if the parameters not valid.
        reply = {'success':None, 'result':params}
        reply['success'] = self._validate_configuration(params)
        
        if InstErrorCode.is_error(reply['success']):
            yield self.reply_ok(msg, reply)
            return
        
        # Fire EVENT_CONFIGURE with the validated configuration parameters.
        # Set the error message if the event is not handled in the current
        # state.
        reply['success'] = self.fsm.on_event(SiamDriverEvent.CONFIGURE,params)

        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug('op_configure: complete. success = %s' % (reply['success']))
            
        yield self.reply_ok(msg, reply)
Ejemplo n.º 23
0
    def __disconnect(self):
        # Dissolve the connection to the device.
        reply = yield self.driver_client.disconnect()
        current_state = yield self.driver_client.get_state()
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))
        self.assertEqual(result,None)
        self.assertEqual(current_state, SiamDriverState.DISCONNECTED)
Ejemplo n.º 24
0
 def test_001_initialize(self):
     
     self._check_skip()
                     
     reply = yield self.driver_client.initialize()
     success = reply['success']
     result = reply['result']
     self.assert_(InstErrorCode.is_ok(success))
     
     current_state = yield self.driver_client.get_state()
     self.assertEqual(current_state, SiamDriverState.UNCONFIGURED)
Ejemplo n.º 25
0
    def __connect(self):

        yield self.test_002_configure();
        
        # Establish connection to device and verify.
        try:
            reply = yield self.driver_client.connect()
        except:
            self.fail('Could not connect to the device.')
            
        current_state = yield self.driver_client.get_state()
        success = reply['success']
        result = reply['result']

        self.assert_(InstErrorCode.is_ok(success))
        self.assertEqual(result,None)
        self.assertEqual(current_state, SiamDriverState.CONNECTED)
Ejemplo n.º 26
0
    def test_002_configure(self):

        self._check_skip()
                
        yield self.test_001_initialize()
        
        params = self.driver_config

        # Configure the driver and verify.
        reply = yield self.driver_client.configure(params)        
        current_state = yield self.driver_client.get_state()
        success = reply['success']
        result = reply['result']
                
        self.assert_(InstErrorCode.is_ok(success))
        self.assertEqual(result,params)
        self.assertEqual(current_state, SiamDriverState.DISCONNECTED)
Ejemplo n.º 27
0
    def _configure(self, params):

        # Validate configuration.
        success = self._validate_configuration(params)
        if InstErrorCode.is_error(success):
            return False

        # Set configuration parameters.
        self.pid = params['pid']
        self.port = params['port']

        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug("_configure: pid = '" + \
                      str(self.pid) + "' port = '" + str(self.port) + "'")

        self.siamci = SiamCiAdapterProxy(self.pid, self.port)

        return True
Ejemplo n.º 28
0
    def _configure(self, params):
        
        # Validate configuration.
        success = self._validate_configuration(params)
        if InstErrorCode.is_error(success):
            return False

        # Set configuration parameters.
        self.pid = params['pid']
        self.port = params['port']

        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug("_configure: pid = '" + \
                      str(self.pid) + "' port = '" + str(self.port) + "'")
            
        self.siamci = SiamCiAdapterProxy(self.pid, self.port)
        
        return True
Ejemplo n.º 29
0
 def test_004_get_status(self):
     """
     - connect
     - get_status
     - disconnect
     """
     
     self._check_skip()
             
     yield self.__connect()
     
     # @todo: Only the all-all params is handled; handle other possible params
     params = [('all','all')]
     reply = yield self.driver_client.get_status(params)
     success = reply['success']
     result = reply['result']      
     self.assert_(InstErrorCode.is_ok(success))  
     
     yield self.__disconnect()
Ejemplo n.º 30
0
 def test_006_set_params_invalid(self):
     """
     - connect
     - set some invalid parameters (we just check the operation completes)
     - disconnect
     """
     
     self._check_skip()
     
     yield self.__connect()
     
     channel = SiamDriverChannel.INSTRUMENT
     params = {(channel,'baudrate'):'19200', (channel,'someWrongParam'):'someValue'}
     reply = yield self.driver_client.set(params)
     success = reply['success']
     result = reply['result']
     
     self.assert_(InstErrorCode.is_error(success))
     
     yield self.__disconnect()
Ejemplo n.º 31
0
    def op_disconnect(self, content, headers, msg):
        
        # Timeout not implemented for this op.
        timeout = content.get('timeout',None)
        if timeout != None:
            assert(isinstance(timeout,int)), 'Expected integer timeout'
            assert(timeout>0), 'Expected positive timeout'
            pass

        success = self.fsm.on_event(SiamDriverEvent.DISCONNECT) 
        reply = {'success':success,'result':None}
        
        if InstErrorCode.is_error(reply['success']):
            yield self.reply_ok(msg, reply)
            return
        

        success = self.fsm.on_event(SiamDriverEvent.DISCONNECT_COMPLETE)
        reply['success'] = success
        
        """
        @TODO: why calling ''yield self.siamci.stop()'' to stop (terminate) the 
        SiamCiProxy process causes errors?  Here are some of the errors if this
        call is included when running test_siam_driver.py: 
            [process        :780] WARNING:Process bootstrap RPC conv-id=carueda_46740.7#29 timed out!
            [state_object   :113] ERROR:ERROR in StateObject process(event=deactivate)
            [receiver       :169] ERROR:Receiver error: Illegal state change
            [state_object   :132] ERROR:Subsequent ERROR in StateObject error(), ND-ND
        """
#        yield self.siamci.stop()


        if log.getEffectiveLevel() <= logging.DEBUG:
            log.debug('op_disconnect: complete. success = %s' % (reply['success']))
            
        yield self.reply_ok(msg, reply)               
Ejemplo n.º 32
0
    def test_009_acquisition_start_wait_stop(self):
        """
        - connect and get channels reported by instrument
        - select a reported channel randomly
        - start receiver service (in lieu of InstrumentAgent)
        - execute START_AUTO_SAMPLING with selected channel
        - wait for a few seconds
        - execute STOP_AUTO_SAMPLING with selected channel
        - disconnect
        """
        
        self._check_skip()
                
        #
        # connect and get channels
        #
        channels = yield self.__connect_and_get_channels()
        if len(channels) == 0:
            raise unittest.SkipTest('No reported channels from the instrument at port ' +str(SiamCiTestCase.port))
        
        #
        # randomly select a reported channel:
        #
        channel = channels[random.randint(0, len(channels) - 1)]
        
        #
        # start receiver service and set the publish_stream
        #
        receiver_service_name = 'test_siam_driver_receiver' 
        receiver_client = yield self._start_receiver_service(receiver_service_name)
        publish_stream = "siamci." + receiver_service_name
        reply = yield self.driver_client.set_publish_stream(publish_stream)
        success = reply['success']
        result = reply['result']
        self.assert_(InstErrorCode.is_ok(success))
        
        #
        # tell receiver to expect related publication
        # @todo: more robust assignment of publish IDs
        #
        publish_id = "data_acquisition;port=" + SiamCiTestCase.port + ";channel=" +channel
        
        # prepare to receive result:
        yield receiver_client.expect(publish_id);
        
        #
        # execute START_AUTO_SAMPLING
        # NOTE SiamDriverChannel.INSTRUMENT is not handled. We use the concrete
        # channel selected above
        #
        channels = [channel]
        command = [SiamDriverCommand.START_AUTO_SAMPLING]
        timeout = 20
        reply = yield self.driver_client.execute(channels,command,timeout)
        success = reply['success']
        result = reply['result']
        
        self.assert_(InstErrorCode.is_ok(success))
        
        assert(isinstance(result, dict))    
        self.assertEqual(result.get("channel", None), channel)
        self.assertEqual(result.get("publish_stream", None), publish_stream)
        
        #
        # wait for a few samples to be notified to the receiver service
        #
        yield pu.asleep(20)

        #
        # check that we actually received data
        #
        expected = yield receiver_client.getExpected()
        self.assertEquals(len(expected), 0)

        #
        # execute STOP_AUTO_SAMPLING
        # 
        channels = [channel]
        command = [SiamDriverCommand.STOP_AUTO_SAMPLING]
        reply = yield self.driver_client.execute(channels, command)
        success = reply['success']
        result = reply['result']
        
        self.assert_(InstErrorCode.is_ok(success))
        

        #
        # disconnect
        #
        yield self.__disconnect()
Ejemplo n.º 33
0
 def _close_transaction(self, tid):
     log.debug(" _close_transaction: tid=" +str(tid))
     reply = yield self.ia_client.end_transaction(tid)
     success = reply['success']
     self.assert_(InstErrorCode.is_ok(success))
Ejemplo n.º 34
0
 def _close_transaction(self, tid):
     log.debug(" _close_transaction: tid=" + str(tid))
     reply = yield self.ia_client.end_transaction(tid)
     success = reply['success']
     self.assert_(InstErrorCode.is_ok(success))