rs232-serial-communication.py

AAEON PICO-PTH4: Pico-ITX Board with Intel Panther Lake SoC · File : rs232-serial-communication.py · Language : Python · Use case : Communications série RS-232 avec un périphérique industriel via les ports internes

Example of bidirectional serial communication via the internal RS-232/422/485 ports of the board.

The board has two internal serial ports. Install 'pyserial'. Configure jumpers or BIOS for RS-232 mode. Adjust device name (/dev/ttyS0 or ttyS1) based on OS.

rs232-serial-communication.py

#!/usr/bin/env python3
"""
Communication série RS-232 sur AAEON PICO-PTH4.
Utilise les ports série internes (souvent /dev/ttyS0 ou /dev/ttyS1).
Nécessite le module 'pyserial'.
"""
import serial
import time

# Adapter le port selon la configuration BIOS/OS
# Les ports internes sont souvent ttyS0 et ttyS1
PORT = '/dev/ttyS0'
BAUDRATE = 9600

try:
    ser = serial.Serial(PORT, BAUDRATE, timeout=1)
    print(f"Ouverture du port {PORT} à {BAUDRATE} bauds...")
    
    if ser.is_open:
        while True:
            # Envoyer une commande
            command = "PING\r\n"
            ser.write(command.encode('utf-8'))
            print(f"Envoyé: {command.strip()}")
            
            # Lire la réponse
            response = ser.readline().decode('utf-8').strip()
            if response:
                print(f"Reçu: {response}")
            
            time.sleep(2)
            
except Exception as e:
    print(f"Erreur série: {e}")
    print("Vérifiez les permissions d'accès aux ports série (/dev/ttyS*) et le câblage.")

← Back to the board