简体   繁体   中英

python pyserial readline not working, but screen kinda does, worked in ubuntu 16

I have a script which monitors the serial com port:

nano spo.py:

#!/usr/bin/env python3
import serial, time
ser = serial.Serial('/dev/ttyS0', 9600)
while 1:
        serial_line = ser.readline()
        print(serial_line)
        time.sleep(60)

ser.close()

ctrl+x to save and exit

chmod +x spo.py
./spo.py

This script worked under Ubuntu 16, that system may have been an older version of python as well.

under Ubuntu 18.04 I am not getting serial output now, assuming either because of newer Ubuntu, or the newer version of python it comes with.

EDIT, I found a way to get SOME output while running my script (while the script is running I powered the device off and on a couple times):

b'NONIN AVANT 9600\r\n'                                                                                                         
b'NONIN AVANT 9600\r\n'                                                                                                                                                             
b'NONIN AVANT 9600\r\n'                                                                                                                                                             

the above is formatted differently than it used t be though:

NONIN AVANT 9600

if I use screen, i get a bit more butonly if i hit enter

screen /dev/ttyS0 9600

then every time I hit enter I get the initial data:

NONIN AVANT 9600

Patient:
Clinician:

09/01/04 12:52:32 
SpO2= 96 HR= 62 F

if I hit enter again I get more, but it starts over isntead of showing the next line:

NONIN AVANT 9600

Patient:
Clinician:

09/01/04 12:53:55 
SpO2= 97 HR= 65 F

under Ubuntu 16 on my old install from years ago, the output would be like this, initializing once and then getting a new stats line every second:

NONIN AVANT 9600

Patient:
Clinician:

09/01/04 12:53:55 
SpO2= 97 HR= 65 F
SpO2= 98 HR= 69 F
SpO2= 96 HR= 70 F
SpO2= 98 HR= 74 F
SpO2= 97 HR= 63 F
SpO2= 96 HR= 62 F
SpO2= 95 HR= 64 F

I only get the re-initialized output that I do in screen if I hit the enter key.

I am hoping somebody can help me figure this out, I feel like I am going round and round in circles chasing dead ends.

The device is a Nonin Avant 9600: ASCII serial 9600 baud with 8 databits, 1 start bit, and 2 stop bits. Each line is terminated by CR/LF

For anybody that finds this thread. I had tried several different ways of getting output from the serial port, nothing was working. I was using our backup oximeter to test with. I switched out the oximeter for the one we normally use, and now serial communication is working properly. The bad oximeter appeared to be functioning correctly and displayed correctly on its screen, so I would not have guessed it might have been the device causing the problem with the serial communication.

Also oddly, turning the device off and on gets me some data out of the serial port, but only initially, I don't keep getting data. I almost gotta wonder if its just a setting or something weird with the device, but I looked the manual over and don't see anything. Wish I knew a little bit more about electronics, would be nice to fix this other one, but there are not any obviously burnt or bulging components, so I wouldn't know what to look for next.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM