[Python] Understand data received from serial with Python [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    Good morning, i'm pretty new to read some data from serial device and i don't understand how to reach the goal. I'm a mechanical designer and waiting for the company to hire a programmer i need to reach a goal: read a simple data from a serial communication

    I have wrote a little program in Python like this after i have read some document about serial communication and with the help of other user in this forum.

    import serial
    from time import sleep
    port = "COM3"
    baudrate = 9600

    ser = serial.Serial(port,baudrate,timeout=1,parity=serial.PARITY_NONE,bytesize=serial.EIGHTBITS,stopbits=serial.STOPBITS_ONE)

    if ser.is_open == True:
    print("Porta " + port + " aperta")
    else:
    print("porta " + port + " chiusa")

    print("dati ricevuti:")

    while True:
    data = ser.readline()
    sleep(0.1)
    data_left = ser.inWaiting()
    data += ser.readline(data_left)
    print (data) #print received data


    nothing difficult but the return in terminal is this:

    Porta COM3 aperta
    dati ricevuti:
    b''
    b''
    b''
    b''
    b''
    b''


    All the data are blank and i pretty sure i have to send command first to receive later a response with the data i need. From a program we have i have the possibility to read the data and i have tried to monitor how work with a serial monitor software.

    [​IMG]

    I know this isn't my job but i want to achieve this goal, for me is a little start for other project in the future.

    I appreciate any help and, if anyone have some video tutorial or other, link me to
    to increase my knowledge.

    I try to read some data from a serial communication to manipulate it after.

    Continue reading...

Compartilhe esta Página