killerpopiller 0 Newbie Poster

Hi,

I can connect to an energy-meter (Baudrate 300!) and the logfile with 228 lines comes slowly in.

line = ser.readline(eol='!') 
print line

If I use the above code, the complete logfiles is shown.
And if I parse separatly saved logfiles with match, it sorts out the right values into sqlite.
So both "parts" work separatly.

But my script is not capable of handing over the output to parse it. It does'nt throw an error, only that 0 values were given.

What am I missing? First I thought, the script is to fast for the slow input (takes over a minute), but the script waits long enough before it is finished.

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*- 

import serial
import time
import re
import sqlite3

ser = serial.Serial()
ser.baudrate = 300
ser.port = '/dev/ttyUSB0'     
ser.timeout = 20 
ser.parity = serial.PARITY_EVEN
ser.stopbits = serial.STOPBITS_ONE
ser.bytesize = serial.SEVENBITS

ser.open()
ser.isOpen()

#initiating logfile-output with /?!
time.sleep(2)
ser.write("/?!")
#time.sleep(0.001) 
ser.write("\r\n")       
time.sleep(2)

connection = sqlite3.connect('/var/www/zaehler/test1.db')
cursor = connection.cursor()
extrakt = []

#line = ser.readline(eol='!')
#print line - would work
   
for line in ser.readline(eol='!'):
                match = re.search(r'(0\.0\.0|0\.9\.1|0\.9\.2|1\.6\.1|1\.8\.1)\(([0-9\.]+)', line)
                if match: 
                        version,value = match.groups() 
                        extrakt.append(value)

cursor.execute('INSERT INTO energielog (sernr, time, date, peak, kwh) values (?, ?, ?, ?, ?)', extrakt)

connection.commit()

ser.close()
cursor.close()
connection.close()
ser.readline(eol='!') = z   
for line in z:
    match..

If I assign a value to the output (buffer?) it throws Error: ser.readlines(eol='!') = z
SyntaxError: can't assign to function call