LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2019, 12:13 PM   #1
RonHof
LQ Newbie
 
Registered: Aug 2006
Posts: 23

Rep: Reputation: 1
Python EOL marker serial.read


I'm trying to read data from a serial port:
Code:
ser = serial.Serial(
        port='/dev/ttyUSB0',
        baudrate = 4800,
        parity = serial.PARITY_NONE,
        stopbits = serial.STOPBITS_ONE,
        bytesize = serial.EIGHTBITS,
        timeout=1)
and

Code:
    Str = ser.read(8)
    print (Str)
I expected to see xxxx.xxb'\r'
but what I seem to be getting is b'xxxx.xx\r'
It seems to be splitting the EOL marker some how. I'm asssuming that b'\r' is old fashioned carriage return and has the same effect as b'\n' [new line] I'm completely baffled. Any suggestions?
 
Old 10-15-2019, 01:12 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Is the line terminator being sent as '\r' or '\r\n'?
 
Old 10-15-2019, 01:24 PM   #3
RonHof
LQ Newbie
 
Registered: Aug 2006
Posts: 23

Original Poster
Rep: Reputation: 1
It is '\r'
 
Old 10-15-2019, 01:27 PM   #4
RonHof
LQ Newbie
 
Registered: Aug 2006
Posts: 23

Original Poster
Rep: Reputation: 1
is there an easy way to specify the EOL to be '\r'
 
Old 10-15-2019, 01:38 PM   #5
RonHof
LQ Newbie
 
Registered: Aug 2006
Posts: 23

Original Poster
Rep: Reputation: 1
for example with no changes to the code, only stopping and starting the data stream, when it is working as I want the output of the print statement is

b' 0.89\r'
b' 0.89\r'
b' 0.89\r'
b' 0.89\r'


but when the output of the print statement is

b' 60\r 60\r'
b' 60\r 6'
b'0\r 60\r '
b' 60\r 60\r '
b' 60\r 60'

it doesn't work as I want
 
Old 10-15-2019, 05:08 PM   #6
RonHof
LQ Newbie
 
Registered: Aug 2006
Posts: 23

Original Poster
Rep: Reputation: 1
ser.eol = serial.EOL="\r" seems to do the job

Last edited by RonHof; 10-16-2019 at 04:01 PM. Reason: typo
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ubuntu 17.10 Finishes Its Transition to Python 3.6, Ubuntu 16.10 EOL Coming July LXer Syndicated Linux News 0 06-29-2017 05:06 PM
LXer: Python Python Python (aka Python 3) LXer Syndicated Linux News 0 08-05-2009 08:30 PM
Permanent marker pen on screen keymoo General 15 09-26-2007 06:16 AM
threads read marker not useful titanium_geek LQ Suggestions & Feedback 2 05-14-2006 01:29 AM
Marker disappeared Fredde87 Linux - General 0 09-16-2005 06:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration