Skip to content

Commit

Permalink
Merge pull request #85 from jtilahun/monotonic
Browse files Browse the repository at this point in the history
Use the monotonic clock to measure time elapsed
  • Loading branch information
MatthieuDartiailh authored Oct 30, 2023
2 parents 8052150 + c1d9651 commit f1e254c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyvisa_sim/sessions/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def read(self, count: int) -> Tuple[bytes, constants.StatusCode]:

last_bit, _ = self.get_attribute(constants.ResourceAttribute.asrl_data_bits)
mask = 1 << (last_bit - 1)
start = time.time()
start = time.monotonic()

out = b""

while time.time() - start <= timeout:
while time.monotonic() - start <= timeout:
last = self.device.read()

if not last:
Expand Down
4 changes: 2 additions & 2 deletions pyvisa_sim/sessions/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ def read(self, count: int) -> Tuple[bytes, constants.StatusCode]:
timeout, _ = self.get_attribute(constants.ResourceAttribute.timeout_value)
timeout /= 1000

start = time.time()
start = time.monotonic()

out = b""

while time.time() - start <= timeout:
while time.monotonic() - start <= timeout:
last = self.device.read()

if not last:
Expand Down

0 comments on commit f1e254c

Please sign in to comment.