Skip to content

Commit

Permalink
read packets in the adc's data format
Browse files Browse the repository at this point in the history
read_packet() scans bytes from the serial port until if finds one with
the control bit set HIGH, then takes that byte and the next two and
returns their numerical values as a list.
  • Loading branch information
liliakai committed Aug 31, 2012
1 parent b12bed7 commit 1ee3f5c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ def open_file():

return open(logdir + '/' + filename(i), 'w')

def read_packet(port)
while True:
data = ord(port.read(1))
if (data & 0x80) != 0:
return [data] + map(ord, port.read(2))

def main():
outfile = open_file()
port = open_serial()

while True:
outfile.write(port.readline())
outfile.write(read_packet())

outfile.close()
port.close()
Expand Down

0 comments on commit 1ee3f5c

Please sign in to comment.