Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serial write read lock #11

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
matrix:
os: [self-hosted]
python-version: [3.7, 3.11]
python-version: [3.8, 3.11]
steps:
- uses: actions/checkout@v3
- name: Set up Python for Self-Hosted Linux arm64
Expand Down
14 changes: 9 additions & 5 deletions rcb4/armh7interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import platform
import select
import struct
from threading import Lock
import time

from colorama import Fore
Expand Down Expand Up @@ -111,6 +112,7 @@ def padding_bytearray(ba, n):
class ARMH7Interface(object):

def __init__(self):
self.lock = Lock()
self.serial = None
self.id_vector = None
self.servo_sorted_ids = None
Expand Down Expand Up @@ -179,11 +181,13 @@ def serial_write(self, byte_list):
raise RuntimeError('Serial is not opened.')

data_to_send = bytes(byte_list)
try:
self.serial.write(data_to_send)
except serial.SerialException as e:
print(f"Error sending data: {e}")
return self.serial_read()
with self.lock:
try:
self.serial.write(data_to_send)
except serial.SerialException as e:
print(f"Error sending data: {e}")
ret = self.serial_read()
return ret

def serial_read(self, timeout=10):
if self.serial is None:
Expand Down