LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-10-2013, 04:02 AM   #1
Exise
LQ Newbie
 
Registered: Jan 2010
Location: Netherlands
Distribution: Ubuntu (server) & RPi
Posts: 5

Rep: Reputation: 0
PySerial receiving strange data


I've connected an RPi to my smart meter with a serial cable. The smart meter automatically starts sending 20 lines of data, about every 10 seconds.

Smart meter output example data:
Code:
/ISk5\2ME382-1003
0-0:96.1.1(4B414C37303035313039)
1-0:1.8.1(00180.724*kWh)
1-0:1.8.2(00001.416*kWh)
1-0:2.8.1(00000.000*kWh)
1-0:2.8.2(00000.000*kWh)
[...]
!
However, when retrieving the data using PySerial I often get data like this:
Code:
b'\x00\n'
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00
Eventually, I do get some data, but not even all.

My script:
Code:
import sys
import serial

ser = serial.Serial()
ser.baudrate = 9600
ser.bytesize=serial.SEVENBITS
ser.parity=serial.PARITY_EVEN
ser.stopbits=serial.STOPBITS_ONE
ser.xonxoff=0
ser.rtscts=0
ser.timeout=None
ser.port="/dev/ttyUSB0"

ser.open()
count=0
stack=[]
while count < 25:
    p1_raw =  str(ser.readline())
    print(p1_raw)
    count=count+1

ser.close()
exit
The problem seems to be with Python/PySerial. When using cu or minicom the data is received properly.

Is this perhaps a PySerial bug?

Last edited by Exise; 07-13-2013 at 01:10 PM. Reason: Solved
 
Old 07-12-2013, 07:11 AM   #2
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
Are you sure you're using the right settings for pyserial. You are using 7E1 while 8N1 is the most used form nowadays.
7E1 means 7 bit data. Even parity. 1 stop bit
8E1 means 8 bit data. No parity . 1 stop bit.

Cheers
 
Old 07-13-2013, 01:10 PM   #3
Exise
LQ Newbie
 
Registered: Jan 2010
Location: Netherlands
Distribution: Ubuntu (server) & RPi
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gdejonge View Post
Are you sure you're using the right settings for pyserial. You are using 7E1 while 8N1 is the most used form nowadays.
7E1 means 7 bit data. Even parity. 1 stop bit
8E1 means 8 bit data. No parity . 1 stop bit.

Cheers
After your post I tried changing various settings. Changing ser.xonxoff=0 to 1 solved the problem. Strange, because others with very similar set-ups did get it working with ser.xonxoff=0. Anyway, thank you!

Settings:
Code:
ser = serial.Serial()
ser.baudrate = 9600
ser.bytesize=serial.SEVENBITS
ser.parity=serial.PARITY_NONE
ser.stopbits=serial.STOPBITS_ONE
ser.xonxoff=1
ser.rtscts=0
 
  


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
[SOLVED] Has my server been comprimised? Receiving strange mails. Zippy1970 Linux - Security 4 10-17-2010 05:43 PM
Not receiving UDP data duttaa Linux - Networking 4 08-19-2009 01:51 AM
Strange problem with not receiving IP address matthalliday Linux - Wireless Networking 3 05-04-2007 10:49 AM
Strange load oscillation receiving udp multicast nathan2225 Linux - Networking 0 03-28-2007 04:10 AM
Receiving all data from socket Ohmu Programming 6 03-08-2004 01:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:07 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