Я создал этот скрипт Python, чтобы перевести проблему до самой фундаментальной.
Это работает в Windows против Com3 (мой Arduino запрограммирован для возврата данных через последовательный). < /p>
Почему это не работает на Ubuntu Linux с использованием /dev /tty2. Я добавил себя в группу и, учитывая сообщения о серийном объекте, что он связан. Но ничего не происходит после подключения. (Я также вижу, что /dev /tty1 и /dev /tty3 не подключаются, так что сообщает мне, что мои разрешения хороши в /dev /tty2, нет?)# This test file will write / read to a COM port on Windows but not on
# Ubuntu Linux against "/dev/tty2". Why?
import serial
while True:
try:
ser = serial.Serial('/dev/tty2', 9600, timeout = 1)
if ser:
print("Connected to: ", ser.name)
except serial.SerialException as e:
print(f"Error opening serial port: {e}")
exit()
try:
ser.write(b"Test from Python\n")
while True:
data = ser.readline()
if data:
print("Received: ", data.decode().strip())
except Exception as e:
print(f"Error during communication: {e}")
finally:
# Close the serial port
if ser.is_open:
ser.close()
print("Serial port closed")
Подробнее здесь: https://stackoverflow.com/questions/796 ... untu-linux