From: Maxious Date: Sat, 29 Sep 2012 14:02:54 +0000 Subject: add serial port reading X-Git-Url: https://maxious.lambdacomplex.org/git/?p=scannr.git&a=commitdiff&h=aa30d3bc3c8200cfda6e3821314d1b6b2595f677 --- add serial port reading --- --- /dev/null +++ b/README.txt @@ -1,1 +1,1 @@ - +ffmpeg from http://ffmpeg.zeranoe.com/builds/ --- a/scannr.py +++ b/scannr.py @@ -1,21 +1,30 @@ +import logging +logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s\t%(levelname)s\t%(message)s') + import snd import time from datetime import date import threading from pydispatch import dispatcher import wave +import serial +#python -m serial.tools.miniterm -p COM20 -e -b 115200 --cr filename = "demo.wav" +MIN_LENGTH = 90000 def worker(filename): """thread worker function http://www.doughellmann.com/PyMOTW/threading/ - https://github.com/uskr/pynma - -http://stackoverflow.com/questions/1092531/event-system-in-python """ +ffmpeg -i 2012-09-29-1348911268.34-demo.wav -ar 8000 -ab 4.75k test.3gp +http://stackoverflow.com/questions/2559746/getting-error-while-converting-wav-to-amr-using-ffmpeg +""" print 'Worker for '+filename - + ser.write("GLG\r") + line = ser.readline() # read a '\n' terminated line + print line return def filenameMaker(): @@ -25,20 +34,26 @@ def record_to_async_file(): "Records from the microphone and outputs the resulting data to `path`" sample_width, data = snd.record() - data = snd.pack('<' + ('h'*len(data)), *data) - path = filename - dispatcher.send( signal='FILE_CREATED', sender=filename, filename=filename) - wf = wave.open(path, 'wb') - wf.setnchannels(1) - wf.setsampwidth(sample_width) - wf.setframerate(snd.RATE) - wf.writeframes(data) - wf.close() - print("done - result written to "+path) + print str(len(data)) + if len(data) > MIN_LENGTH: + data = snd.pack('<' + ('h'*len(data)), *data) + path = filename + dispatcher.send( signal='FILE_CREATED', sender=filename, filename=filename) + wf = wave.open(path, 'wb') + wf.setnchannels(1) + wf.setsampwidth(sample_width) + wf.setframerate(snd.RATE) + wf.writeframes(data) + wf.close() + print("done - result "+str(len(data))+" frames written to "+path) dispatcher.connect( filenameMaker, signal='SND_STARTED', sender=dispatcher.Any ) dispatcher.connect( worker, signal='FILE_CREATED', sender=dispatcher.Any ) + +ser = serial.Serial('COM20', 112500, timeout=1) + print "Scannr started..." while True: print "ready to record" record_to_async_file() +ser.close() --- /dev/null +++ b/trunklog.php @@ -1,1 +1,31 @@ - +"; +if (($handle = fopen("C:\Users\Madoka\AppData\Roaming\UniTrunker\S00000001\UniTrunker-20120411.LOG", "r")) !== FALSE) { + while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { + + if ($row > 0 && count($data) == 9) { + + echo ""; + for ($c=0; $c < count($data); $c++) { + echo ''.$data[$c] . "\n"; + } + echo ""; + } + $row++; + } + fclose($handle); +} +echo ""; +?>