[Cialug] Python failing

Patrick Mcgillan patrick.mcgillan at gmail.com
Wed Jun 29 19:44:02 CDT 2016


The following script has been running fine for over a year. Now it is
stopping more than once a day. Kill program and restart and it again runs
fine for a while. Any thoughts? I know enough about python to be dangerous
to myself. n arduino uno is sending messages to the server running the
capture script.

Patrick


#!/usr/bin/python

import serial

debug = 0

MySerial = serial.Serial('/dev/ttyUSB0', 9600)

while True:
data = MySerial.readline();
print "%s" % (data)

if data.count(":") == 2: who,s1,s2 = data.split(":",3)
if data.count(":") == 3: who,s1,s2,s3 = data.split(":",4)
if data.count(":") == 4: who,s1,s2,s3,s4 = data.split(":",5)
if data.count(":") == 5: who,s1,s2,s3,s4,s5 = data.split(":",6)
if data.count(":") == 6: who,s1,s2,s3,s4,s5,s6 = data.split(":",7)

if data.count(":") > 1:
fileout = open ('/var/local/Sensor/' + who + '-Data.txt', 'a');
fileout.write (data);
fileout.close();
if data.count(":") > 1:
fileout = open ('/var/local/Sensor/' + who + '-Last.txt', 'w');
fileout.write (data);
fileout.close();


More information about the Cialug mailing list