Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script to analyze and plot data with pulox PO-300, rev. 6.6 #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions cms50dplus/cms50dplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def getDictData(self):
class RecordedDataPoint(object):
def __init__(self, time, data):
if data[0] & 0xfe != 0xf0 or data[1] & 0x80 == 0 or data[2] & 0x80 != 0:
print data
print ('DATA: {}, Invalid data packet.'.format(data))
raise ValueError("Invalid data packet.")

self.time = time
Expand Down Expand Up @@ -254,8 +254,12 @@ def getRecordedData(self, time):

length = (((lena & 0x7f) << 14) | ((lenb & 0x7f) << 7) | lenc) + 1

# wildi
if length % 3 != 0:
raise Exception("Length not divisible by 3!")
# raise Exception("Length not divisible by 3!")
print("Length not divisible by 3!: {}".format(length % 3 ))
length -=length % 3
print("new length: {}".format(length))

# Calculate length in hours, minutes, and seconds.
s = length / 3
Expand All @@ -276,7 +280,10 @@ def getRecordedData(self, time):
raise Exception("Timeout during download!")
packet[i%3] = byte
if i%3 == 2:
yield RecordedDataPoint(time, packet)
try:
yield RecordedDataPoint(time, packet)
except ValueError:
continue
time = time + datetime.timedelta(seconds=1)
packet = [0]*3

Expand Down Expand Up @@ -317,8 +324,8 @@ def dumpRecordedData(starttime, port, filename):
for recordedData in oximeter.getRecordedData(starttime):
writer.writerow(recordedData.getCsvData())
measurements += 1
sys.stdout.write("\rGot {0} measurements...".format(measurements))
sys.stdout.flush()
#wildi sys.stdout.write("\rGot {0} measurements...".format(measurements))
#sys.stdout.flush()

def valid_datetime(s):
try:
Expand All @@ -344,4 +351,3 @@ def valid_datetime(s):
print "Missing start time for RECORDED mode."

print ""
print "Done."
Loading