benfasoli
4/6/2017 - 5:05 PM

GRIMM Data Logging

GRIMM 1.109 particle counter parsing and serial data logging interface

#!/bin/bash

if ! screen -list | grep -q readGrimm; then
  /usr/bin/screen -S readGrimm -dm /usr/bin/python /home/pi/readGrimm.py
  echo "GRIMM script needed a restart..." >> /home/pi/errorlog.txt
fi


# /usr/bin/rsync -av /home/pi/data/* benfasoli@155.101.15.103:/projects/daq/uofu/grimm/
#!/bin/bash

/usr/bin/screen -S readGrimm -dm /usr/bin/python /home/pi/readGrimm.py
#!/usr/bin/python
# GRIMM data collection script
# Ben Fasoli

# SET PATHS
serialpath = '/dev/serial/by-id/usb-utek_USB__-__Serial_Cable_FTXEK2YB-if00-port0'
outpath = '/home/pi/data/'            # path ending in /
outname = 'grimm'

# SET INSTRUMENT PARAMETERS
baud=9600                        # serial baud rate
delimit='\n'                     # character delimiter

# SET PROGRAM PARAMETERS
checkT=0.05                      # time between checks for new data (s)

# ----------------------------------------------------------------
print('GRIMM data logger.             by: Ben Fasoli\n')

# Import modules
import serial as ser                   # serial port use
import os.path                         # access to disk paths
import datetime                        # time stamps (UTC)
import re                              # regular expression matching
from time import sleep                 # allows us to sleep


print('Opening serial port...')
s = ser.Serial(serialpath, baud)
#s.write('R')
#sleep(1)


buf=str()
print('Starting data collection...\n')

while True:
    try:
        buf = buf + s.read(s.inWaiting())   # Check for new data
        if buf.count(delimit) > 3:
            while not buf.startswith('C'): buf = buf[1: ]

        if buf.count(delimit) > 3:
            tcollected = datetime.datetime.utcnow()

            # Delimit the collected buffer. Left of the
            # delimiter character is considered the full
            # data line, right is considered the start of
            # a new data line.
            buf = buf.split(delimit)
            left = ' '.join(buf[0:4])
            buf = ''.join(buf[4:])

            left = left.replace('\r', ' ').replace('\n', ' ')
            left = re.sub('C.:|c.:|C.;|c.;','', left)
            left = re.sub('\s+', ',', left)
            if left.endswith(','): left = left[0:-1]

            saveln = str(tcollected) + str(left) + '\n'
            print(saveln)

            # Save to daily data file archive.
            filename = outpath+outname+'_'+tcollected.strftime('%Y')+'_'+\
                tcollected.strftime('%m')+'_'+tcollected.strftime('%d')+'.dat'
            with open(filename, 'a+') as f:
                f.write(saveln)

        else:
            sleep(checkT) # Time between checks for new data

    except (KeyboardInterrupt, SystemExit):
        print('\nExiting...')
        s.flush()
        s.close()
        print('Closed successfully.')
        raise
*/5	*	*	*	*	nice /home/pi/alive.sh