Untitled
unknown
plain_text
a year ago
993 B
5
Indexable
import serial def check_port(port, baudrate=9600): try: with serial.Serial(port, baudrate, timeout=1) as ser: print(f"Port {port} is available.") return True except serial.SerialException as e: print(f"Error: {e}") return False def receive_message(port, baudrate=9600): if not check_port(port, baudrate): return try: with serial.Serial(port, baudrate, timeout=1) as ser: print("Waiting for message...") while True: if ser.in_waiting > 0: message = ser.readline().decode('utf-8').strip() print("Received message:", message) except serial.SerialException as e: print("Error:", e) if __name__ == "__main__": port = 'COM3' # پورت سریال بلوتوث خود را اینجا وارد کنید baudrate = 9600 # نرخ انتقال داده receive_message(port, baudrate)
Editor is loading...
Leave a Comment