The pyserial does not stop looping.

Asked 2 years ago, Updated 2 years ago, 34 views

Now, "Send a break signal automatically and finish processing when prompted."
I am thinking of the code

I can't write "Finish the process when you get a prompt" in it.
How should I write the code to stop?
Thank you very much for letting me know.

environment
Python 3.6.8
pyserial 3.4

import sys
import serial
import time

ser=serial.Serial(
     port = 'COM1',
     baudrate=115200,          
     parity = 'N',             
     stopbits = 1,
     bytesize = 8,
     timeout = 8
      )

ser.isOpen()

while True:
    ser.send_break()

    command='\r\n'
    out=ser.readline()
    out=out.decode("utf-8", "ignore")
    time.sleep(0.5)
    if out=='>':
        sys.exit()

python python3

2022-09-30 15:33

1 Answers

ser.isOpen()

The serial port may not be open.


2022-09-30 15:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.