Re: writing serial port data to the gzip file




Petr Jakes wrote:
I am trying to save data it is comming from the serial port continually
for some period.
(expect reading from serial port is 100% not a problem)
Following is an example of the code I am trying to write. It works, but
it produce an empty gz file (0kB size) even I am sure I am getting data
from the serial port. It looks like g.close() does not close the gz
file.
I was reading in the doc:

Calling a GzipFile object's close() method does not close fileobj,
since you might wish to append more material after the compressed
data...

so I am completely lost now...

thanks for your comments.
Petr Jakes
==== snippet of the code ====
def dataOnSerialPort():
data=s.readLine()
if data:
return data
else:
return 0

while 1:
g=gzip.GzipFile("/root/foofile.gz","w")
while dataOnSerialPort():
g.write(data)
else: g.close()

Your while loop is discarding result of dataOnSerialPort, so you're
probably writing empty string to the file many times. Typically this
kind of loop are implemented using iterators. Check if your s object
(is it from external library?) already implements iterator. If it does
then

for data in s:
g.write(data)

is all you need. If it doesn't, you can use iter to create iterator for
you:

for data in iter(s.readLine, ''):
g.write(data)

-- Leo

.



Relevant Pages

  • Re: Serial port :bytesAvailable
    ... I am reading binary data from a serial port (it is actually ... have no problem reading data, I am reading data from an eye ... input buffer, for this I am using the bytesAvailable function. ...
    (comp.soft-sys.matlab)
  • Re: Serial Port interfacing
    ... > I am having a problem reading from a serial port, first of all I have now ... resorted to using the MSComm ActiveX control on my Windows Forms to provide ... me with the interface to my serial port. ... my Card reader up and I plug it in and I swipe my transponder card the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Parsing data from pyserial
    ... He's reading with a 1-second timeout ... from the gizmo for the command sent to it. ... transmission mode of the serial port. ...
    (comp.lang.python)
  • Re: Pylab and pyserial plot in real time
    ... Basically the code was supposed to get the values from the serial port, ... more appropriate for the above mentioned task than pylab?? ... > What do you mean when you say it's in ASCII format? ... > problem is with the serial reading or with the plotting. ...
    (comp.lang.python)