def test_visa_usb(exopy_qtbot): """ Test the visa usb connection. """ c = VisaUSB() show_widget(exopy_qtbot, c) c.widgets()[-6].text = '0x00' c.widgets()[-4].text = '0x01' c.widgets()[-2].text = '0x02' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == { 'interface_type': 'USB', 'resource_class': 'INSTR', 'manufacturer_id': '0x00', 'model_code': '0x01', 'serial_number': '0x02', 'usb_interface_number': '0', 'board': '0' } exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_visa_rs232(windows): """Test the rs232 visa connection. """ c = VisaRS232() show_widget(c) c.widgets()[-1].text = '1' process_app_events() assert c.gather_infos() == { 'interface_type': 'ASRL', 'resource_class': 'INSTR', 'board': '1' } assemble_canonical_name(**c.gather_infos())
def test_visa_rs232(exopy_qtbot): """Test the rs232 visa connection. """ c = VisaRS232() show_widget(exopy_qtbot, c) c.widgets()[-1].text = '1' def assert_infos(): assert c.gather_infos() == {'interface_type': 'ASRL', 'resource_class': 'INSTR', 'board': '1'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def _parse_test(self, rn, **kwargs): p = rname.ResourceName.from_string(rn) r = dict( (k, getattr(p, k)) for k in p._fields + ("interface_type", "resource_class") ) r["canonical_resource_name"] = rname.assemble_canonical_name(**r) assert r == kwargs, rn
def test_visa_tcpip_instr(windows): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(c) c.widgets()[-4].text = '192.168.0.10' process_app_events() c.widgets()[-1].checked = True process_app_events() assert c.gather_infos() == { 'interface_type': 'TCPIP', 'resource_class': 'INSTR', 'host_address': '192.168.0.10', 'lan_device_name': 'inst0', 'board': '0' } assemble_canonical_name(**c.gather_infos())
def test_visa_GPIB(windows): """Test the GPIB visa connection. """ c = VisaGPIB() show_widget(c) c.widgets()[-2].text = '1' process_app_events() c.widgets()[-1].checked = True process_app_events() assert c.gather_infos() == { 'interface_type': 'GPIB', 'resource_class': 'INSTR', 'board': '0', 'primary_address': '1', 'secondary_address': '0' } assemble_canonical_name(**c.gather_infos())
def test_visa_tcpip_instr(exopy_qtbot): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(exopy_qtbot, c) c.widgets()[-4].text = '192.168.0.10' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == {'interface_type': 'TCPIP', 'resource_class': 'INSTR', 'host_address': '192.168.0.10', 'lan_device_name': 'inst0', 'board': '0'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_visa_GPIB(exopy_qtbot): """Test the GPIB visa connection. """ c = VisaGPIB() show_widget(exopy_qtbot, c) c.widgets()[-2].text = '1' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == {'interface_type': 'GPIB', 'resource_class': 'INSTR', 'board': '0', 'primary_address': '1', 'secondary_address': '0'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def format_connection_infos(self, infos): """Use pyvisa to build the canonical resource name. """ from pyvisa.rname import assemble_canonical_name infos = {k: v for k, v in infos.items() if v} if 'resource_name' in infos: return {'resource_name': infos['resource_name']} else: return {'resource_name': assemble_canonical_name(**infos)}
def test_visa_tcpip_socket(windows, process_and_sleep): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(c) c.resource_class = 'SOCKET' process_and_sleep() c.widgets()[-4].text = '192.168.0.10' c.widgets()[-2].text = '10000' process_app_events() c.widgets()[-1].checked = True process_app_events() assert c.gather_infos() == { 'interface_type': 'TCPIP', 'resource_class': 'SOCKET', 'host_address': '192.168.0.10', 'port': '10000', 'board': '0' } assemble_canonical_name(**c.gather_infos())
def test_visa_tcpip_socket(exopy_qtbot, dialog_sleep): """Test the visa tcpip connection. """ c = VisaTCPIP() show_widget(exopy_qtbot, c) c.resource_class = 'SOCKET' exopy_qtbot.wait(10 + dialog_sleep) c.widgets()[-4].text = '192.168.0.10' c.widgets()[-2].text = '10000' exopy_qtbot.wait(10) c.widgets()[-1].checked = True def assert_infos(): assert c.gather_infos() == {'interface_type': 'TCPIP', 'resource_class': 'SOCKET', 'host_address': '192.168.0.10', 'port': '10000', 'board': '0'} exopy_qtbot.wait_until(assert_infos) assemble_canonical_name(**c.gather_infos())
def test_visa_usb(windows): """ Test the visa usb connection. """ c = VisaUSB() show_widget(c) c.widgets()[-6].text = '0x00' c.widgets()[-4].text = '0x01' c.widgets()[-2].text = '0x02' process_app_events() c.widgets()[-1].checked = True process_app_events() assert c.gather_infos() == { 'interface_type': 'USB', 'resource_class': 'INSTR', 'manufacturer_id': '0x00', 'model_code': '0x01', 'serial_number': '0x02', 'usb_interface_number': '0', 'board': '0' } assemble_canonical_name(**c.gather_infos())
def compute_id(cls, args, kwargs): """Assemble the resource name from the provided info. """ rname = None if args: msg = 'A single positional argument is allowed for %s' % cls assert len(args) == 1, msg rname = args[0] elif 'resource_name' in kwargs: rname = kwargs['resource_name'] if rname: try: kwargs['resource_name'] = to_canonical_name(rname) except Exception: # TODO Use a more adequate exception # Fail silently to allow the use of VISA alias kwargs['resource_name'] = rname else: visa_infos = cls._get_visa_infos(kwargs) kwargs['resource_name'] =\ assemble_canonical_name(**visa_infos) return kwargs['resource_name']
def format_connection_infos(self, infos): """Use pyvisa to build the canonical resource name. """ from pyvisa.rname import assemble_canonical_name return {'resource_name': assemble_canonical_name(**infos)}
def _parse_test(self, rn, **kwargs): p = rname.ResourceName.from_string(rn) r = dict((k, getattr(p, k)) for k in p._fields + ('interface_type', 'resource_class')) r['canonical_resource_name'] = rname.assemble_canonical_name(**r) self.assertEqual(r, kwargs, rn)