Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jlashner committed Dec 18, 2024
1 parent 44196c0 commit e355b34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions socs/testing/device_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import pytest
import serial
from serial.serialutil import SerialException


def create_device_emulator(responses, relay_type, port=9001, encoding='utf-8',
Expand Down Expand Up @@ -190,7 +191,13 @@ def _read_serial(self):

while self._read:
if self.ser.in_waiting > 0:
msg = self.ser.readline()
try:
msg = self.ser.readline()
except SerialException as e:
self.logger.error(f"Serial error: {e}")
self.ser.close()
return

if self.encoding:
msg = msg.strip().decode(self.encoding)
self.logger.debug(f"msg='{msg}'")
Expand Down Expand Up @@ -327,10 +334,10 @@ def create_tcp_relay(self, port):
"""
self._type = 'tcp'
self._sock_bound = False
self._bkg_read = threading.Thread(name='background',
bkg_read = threading.Thread(name='background',
target=self._read_socket,
kwargs={'port': port})
self._bkg_read.start()
bkg_read.start()

# wait for socket to bind properly before returning
while not self._sock_bound:
Expand Down
3 changes: 2 additions & 1 deletion socs/testing/hwp_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def __init__(
self.run_enc_thread = False

if self.enc_port == 0:
self._enc_port = _find_open_port()
self.enc_port = _find_open_port()

self.logger = _create_logger("HWP", log_level=log_level)

Expand Down Expand Up @@ -321,6 +321,7 @@ def encoder_thread_func(self):
[header, clock, clock_overflow, edge_count]
).tobytes()
sock.sendto(byte_data, addr)

time.sleep(ENC_COUNTER_LEN / (2 * self.state.cur_freq * NUM_SLITS))
self.logger.info("Stopping encoder thread")

Expand Down

0 comments on commit e355b34

Please sign in to comment.