From 6f01d6184b2e33cc63b860acfeeb583893c0fea2 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Wed, 8 Mar 2023 22:03:51 +0000 Subject: [PATCH 1/4] Fix mypy error in channels.py --- pyvisa_sim/channels.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyvisa_sim/channels.py b/pyvisa_sim/channels.py index d204dca..a3c9721 100644 --- a/pyvisa_sim/channels.py +++ b/pyvisa_sim/channels.py @@ -194,9 +194,9 @@ def _match_setters(self, query: bytes) -> Optional[OptionalBytes]: try: if isinstance(parsed, dict) and "ch_id" in parsed: self._selected = parsed["ch_id"] - self._properties[name].set_value(parsed["0"]) + self._properties[name].set_value(str(parsed["0"])) else: - self._properties[name].set_value(parsed) + self._properties[name].set_value(str(parsed)) return response except ValueError: if isinstance(error_response, bytes): From 50dbd8a524fc6bd4dbe26cf20879fed14e97a9a6 Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Wed, 8 Mar 2023 22:08:05 +0000 Subject: [PATCH 2/4] Move type annotations to component.Component.__init__ --- pyvisa_sim/component.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/pyvisa_sim/component.py b/pyvisa_sim/component.py index 279bc92..873cf7e 100644 --- a/pyvisa_sim/component.py +++ b/pyvisa_sim/component.py @@ -189,10 +189,19 @@ class Component: """A component of a device.""" def __init__(self) -> None: - self._dialogues = {} - self._properties = {} - self._getters = {} - self._setters = [] + #: Stores the queries accepted by the device. + #: query: response + self._dialogues: Dict[bytes, bytes] = {} + #: Maps property names to value, type, validator + self._properties: Dict[str, Property] = {} + #: Stores the getter queries accepted by the device. + #: query: (property_name, response) + self._getters: Dict[bytes, Tuple[str, str]] = {} + #: Stores the setters queries accepted by the device. + #: (property_name, string parser query, response, error response) + self._setters: List[ + Tuple[str, stringparser.Parser, OptionalBytes, OptionalBytes] + ] = [] def add_dialogue(self, query: str, response: str) -> None: """Add dialogue to device. @@ -250,21 +259,6 @@ def match(self, query: bytes) -> Optional[OptionalBytes]: # --- Private API - #: Stores the queries accepted by the device. - #: query: response - _dialogues: Dict[bytes, bytes] - - #: Maps property names to value, type, validator - _properties: Dict[str, Property] - - #: Stores the getter queries accepted by the device. - #: query: (property_name, response) - _getters: Dict[bytes, Tuple[str, str]] - - #: Stores the setters queries accepted by the device. - #: (property_name, string parser query, response, error response) - _setters: List[Tuple[str, stringparser.Parser, OptionalBytes, OptionalBytes]] - def _match_dialog( self, query: bytes, dialogues: Optional[Dict[bytes, bytes]] = None ) -> Optional[bytes]: From 083a2e5e2bf6085dad792da09fe1b10b6a7582ff Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Sat, 11 Mar 2023 00:07:34 +0000 Subject: [PATCH 3/4] Revert "Move type annotations to component.Component.__init__" This reverts commit 50dbd8a524fc6bd4dbe26cf20879fed14e97a9a6. --- pyvisa_sim/component.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pyvisa_sim/component.py b/pyvisa_sim/component.py index 873cf7e..279bc92 100644 --- a/pyvisa_sim/component.py +++ b/pyvisa_sim/component.py @@ -189,19 +189,10 @@ class Component: """A component of a device.""" def __init__(self) -> None: - #: Stores the queries accepted by the device. - #: query: response - self._dialogues: Dict[bytes, bytes] = {} - #: Maps property names to value, type, validator - self._properties: Dict[str, Property] = {} - #: Stores the getter queries accepted by the device. - #: query: (property_name, response) - self._getters: Dict[bytes, Tuple[str, str]] = {} - #: Stores the setters queries accepted by the device. - #: (property_name, string parser query, response, error response) - self._setters: List[ - Tuple[str, stringparser.Parser, OptionalBytes, OptionalBytes] - ] = [] + self._dialogues = {} + self._properties = {} + self._getters = {} + self._setters = [] def add_dialogue(self, query: str, response: str) -> None: """Add dialogue to device. @@ -259,6 +250,21 @@ def match(self, query: bytes) -> Optional[OptionalBytes]: # --- Private API + #: Stores the queries accepted by the device. + #: query: response + _dialogues: Dict[bytes, bytes] + + #: Maps property names to value, type, validator + _properties: Dict[str, Property] + + #: Stores the getter queries accepted by the device. + #: query: (property_name, response) + _getters: Dict[bytes, Tuple[str, str]] + + #: Stores the setters queries accepted by the device. + #: (property_name, string parser query, response, error response) + _setters: List[Tuple[str, stringparser.Parser, OptionalBytes, OptionalBytes]] + def _match_dialog( self, query: bytes, dialogues: Optional[Dict[bytes, bytes]] = None ) -> Optional[bytes]: From e77b389bd128406cad0841f017630ff5c65df88b Mon Sep 17 00:00:00 2001 From: Douglas Thor Date: Sat, 11 Mar 2023 00:09:48 +0000 Subject: [PATCH 4/4] formatting --- pyvisa_sim/channels.py | 1 - pyvisa_sim/devices.py | 1 - pyvisa_sim/sessions/gpib.py | 1 - pyvisa_sim/sessions/serial.py | 4 ---- pyvisa_sim/sessions/tcpip.py | 2 -- pyvisa_sim/sessions/usb.py | 1 - 6 files changed, 10 deletions(-) diff --git a/pyvisa_sim/channels.py b/pyvisa_sim/channels.py index a3c9721..2816efc 100644 --- a/pyvisa_sim/channels.py +++ b/pyvisa_sim/channels.py @@ -71,7 +71,6 @@ class Channels(Component): can_select: bool def __init__(self, device: "Device", ids: List[str], can_select: bool): - super(Channels, self).__init__() self.can_select: bool = can_select self._selected = None diff --git a/pyvisa_sim/devices.py b/pyvisa_sim/devices.py index 70a046b..ba4a197 100644 --- a/pyvisa_sim/devices.py +++ b/pyvisa_sim/devices.py @@ -122,7 +122,6 @@ class Device(Component): delimiter: bytes def __init__(self, name: str, delimiter: bytes) -> None: - super(Device, self).__init__() self.name = name self.delimiter = delimiter diff --git a/pyvisa_sim/sessions/gpib.py b/pyvisa_sim/sessions/gpib.py index d18e1ee..ded9110 100644 --- a/pyvisa_sim/sessions/gpib.py +++ b/pyvisa_sim/sessions/gpib.py @@ -15,7 +15,6 @@ @session.Session.register(constants.InterfaceType.gpib, "INSTR") class GPIBInstrumentSession(session.Session): - parsed: rname.GPIBInstr def after_parsing(self) -> None: diff --git a/pyvisa_sim/sessions/serial.py b/pyvisa_sim/sessions/serial.py index f6416ce..f1dbbf0 100644 --- a/pyvisa_sim/sessions/serial.py +++ b/pyvisa_sim/sessions/serial.py @@ -16,7 +16,6 @@ @session.Session.register(constants.InterfaceType.asrl, "INSTR") class SerialInstrumentSession(session.Session): - parsed: rname.ASRLInstr def after_parsing(self) -> None: @@ -25,7 +24,6 @@ def after_parsing(self) -> None: ) def read(self, count: int) -> Tuple[bytes, constants.StatusCode]: - # TODO: Implement VI_ATTR_SUPPRESS_END_EN end_in, _ = self.get_attribute(constants.ResourceAttribute.asrl_end_in) @@ -56,7 +54,6 @@ def read(self, count: int) -> Tuple[bytes, constants.StatusCode]: return out, constants.StatusCode.success_termination_character_read elif end_in == constants.SerialTermination.last_bit: - if common.last_int(out) & mask: return out, constants.StatusCode.success @@ -90,7 +87,6 @@ def write(self, data: bytes) -> Tuple[int, constants.StatusCode]: for val in common.iter_bytes(data, mask, send_end): self.device.write(val) else: - for i in range(len(data)): self.device.write(data[i : i + 1]) diff --git a/pyvisa_sim/sessions/tcpip.py b/pyvisa_sim/sessions/tcpip.py index ae42eab..b9fb231 100644 --- a/pyvisa_sim/sessions/tcpip.py +++ b/pyvisa_sim/sessions/tcpip.py @@ -59,7 +59,6 @@ def write(self, data: bytes) -> Tuple[int, constants.StatusCode]: @session.Session.register(constants.InterfaceType.tcpip, "INSTR") class TCPIPInstrumentSession(BaseTCPIPSession): - parsed: rname.TCPIPInstr def after_parsing(self) -> None: @@ -74,7 +73,6 @@ def after_parsing(self) -> None: @session.Session.register(constants.InterfaceType.tcpip, "SOCKET") class TCPIPSocketSession(BaseTCPIPSession): - parsed: rname.TCPIPSocket def after_parsing(self) -> None: diff --git a/pyvisa_sim/sessions/usb.py b/pyvisa_sim/sessions/usb.py index 63674d6..8042b3b 100644 --- a/pyvisa_sim/sessions/usb.py +++ b/pyvisa_sim/sessions/usb.py @@ -75,7 +75,6 @@ def write(self, data: bytes) -> Tuple[int, constants.StatusCode]: @session.Session.register(constants.InterfaceType.usb, "RAW") class USBRawSession(session.Session): - parsed: rname.USBRaw def after_parsing(self) -> None: