def con(): hw = HardwareManager(port='virtual:./radiation_device.py') hw.connect_direct(1) con = hw.controller() yield con hw.disconnect()
def hw(): hw = HardwareManager(port='virtual:{}'.format(path)) hw.connect_direct(1) yield hw hw.disconnect() hw.close()
def conf_ascii_tracing(): conf_file = os.path.join(os.path.dirname(__file__), 'tracing_ascii_config.json') if '@' in conf_file or ',' in conf_file or ';' in conf_file: pytest.skip('Cannot pass device config because path has [@,;] in it') hw = HardwareManager('virtual:tracing_test@%s' % conf_file) hw.connect_direct('1') yield hw hw.disconnect()
class TestBLED112AdapterStream(unittest.TestCase): """ Test to make sure that the BLED112AdapterStream is working properly Test that it can connect, connect_direct, send rpcs and get reports """ def setUp(self): self.old_serial = serial.Serial serial.Serial = util.dummy_serial.Serial self.adapter = MockBLED112(3) self.dev1 = MockIOTileDevice(100, 'TestCN') self.dev1_ble = MockBLEDevice("00:11:22:33:44:55", self.dev1) self.adapter.add_device(self.dev1_ble) util.dummy_serial.RESPONSE_GENERATOR = self.adapter.generate_response self.dev1.reports = [ IndividualReadingReport.FromReadings(100, [IOTileReading(0, 1, 2)]) ] self._reports_received = threading.Event() logging.basicConfig(level=logging.INFO, stream=sys.stdout) self.scanned_devices = [] self.hw = HardwareManager(port='bled112:test') def tearDown(self): self.hw.close() def test_connect_direct(self): self.hw.connect_direct("00:11:22:33:44:55") def test_connect_nonexistent(self): with pytest.raises(HardwareError): self.hw.connect_direct("00:11:22:33:44:56") def test_connect_badconnstring(self): with pytest.raises(HardwareError): self.hw.connect_direct("00:11:22:33:44:5L") def test_report_streaming(self): self.hw.connect_direct("00:11:22:33:44:55") assert self.hw.count_reports() == 0 self.hw.enable_streaming() time.sleep( 0.2) #Wait for report callback to happen from bled112 thread assert self.hw.count_reports() == 1
def p(tmpdir): path = os.path.join(os.path.dirname(__file__), 'rpc_device.py') config = { "device": { "tiles": [{ "address": 10, "name": path, "args": {} }], "iotile_id": 1 } } config_path_obj = tmpdir.join('tasks.json') config_path_obj.write(json.dumps(config)) config_path = str(config_path_obj) hw = HardwareManager(port='virtual:tile_based@%s' % config_path) hw.connect_direct(1) tile = hw.get(10) yield tile hw.disconnect()