Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1234

Python • Re: Serial communication problem

$
0
0
O my God, what a trivial solution it was... see.

Code:

import serialimport time# Konfiguracja portu szeregowegoser = serial.Serial('/dev/ttyUSB0', baudrate=300, bytesize=serial.SEVENBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1)try:    # Wysłanie danych    ser.write(b'o')    time.sleep(1)    ser.write(b'\r')         # Odczyt odpowiedzi    response = ser.readline()        # Wyświetlenie odpowiedzi    print("Odpowiedź z urządzenia:", response.decode().strip())finally:    # Zamykanie połączenia z portem szeregowym    ser.close()
box@box:~ $ sudo python last.py
185310312062421
box@box:~ $ sudo python last.py
185439312062421
box@box:~ $ sudo python last.py
185445312062421
box@box:~ $ sudo python last.py
185451312062421
box@box:~ $
After typing 'o,' just had to wait a moment before it was sent <CR>

I don't understand why, but it works. I checked in Screen, Minicom, PuTTY, and all sorts of other terminal programs, and it was always okay because there was always a moment before I hit Enter, and Python sent it immediately."

Statistics: Posted by dojnikowski — Wed Jun 12, 2024 4:55 pm



Viewing all articles
Browse latest Browse all 1234

Trending Articles