#! /usr/local/bin/python
#**********************************************************#
# #
# 4m OFTC Logging Program, Bill Gillespie, NOAO. #
# March 20, 2003 #
# #
# ********************************************** #
# #
# This program's basic function is to querry and log data #
# strings from the 4 meter telescope facilities #
# Oil and Floor Temperature Microcontroller. #
# #
#**********************************************************#
#------- Fetch modules ----------------------------------------------------#
#------- the pyserial module had to be installed for this program ---------#
import serial, os, sys, time, string
#------- Get Time String ---------------------------------------------------#
timenow = time.ctime(time.time())
timenow = timenow[4:25]
#-------- Set up the serial line for R/W ------------------------------------#
dev=serial.Serial('/dev/tty***', 4800, 7, 1, timeout=1)
dev.flush()
#-------- Fetch the main values with oftc device calls ---------------------#
dev.write('oftv\r')
OFTV = dev.readlines()
OFTV = `OFTV` # OFTV converted from object to a string
dev.flush()
dev.write('osetpoint?\r')
Oset = dev.readlines()
Oset = `Oset` # Oset is now a string (was object)
dev.flush()
dev.write('fsetpoint?\r')
Fset = dev.readlines()
Fset = `Fset` # ditto above
dev.flush()
#------- Print the TIME string to the log file ------------------------------#
LogFile = open("/usr/local/gui/oftc/oftc-log-file.txt", "a")
LogFile.write("%-22s" % (timenow))
#------- Clean data strings of unwanted characters --------------------------#
OFTV = OFTV.replace(","," ")
OFTV = OFTV.replace("'"," ")
Oset = Oset.replace(","," ")
Oset = Oset.replace("'"," ")
Fset = Fset.replace(","," ")
Fset = Fset.replace("'"," ")
#------- Parse strings and print log data to log file -----------------------#
OilSetPt = string.split(Oset) # splits the string into list based on white space.
LogFile.write("%5s" % OilSetPt[2]) # prints new list item 1, to the log file.
(OGS, OGR, OSX, OXR, OPR, OSP, AMP, spr, tb1) = string.split(OFTV)[12:21]
LogFile.write("%5s %5s %5s %5s %5s %5s %5s %5s %8s" % (OGS, OGR, OSX, OXR, OPR, OSP, AMP, spr, tb1))
FloorSetPt = string.split(Fset) # splits the string into list based on white space.
LogFile.write("%5s" % FloorSetPt[2]) # prints new list item 1, to the log file.
(FGS, FGR, FT1, FT2, FT3, spr, spr, spr, tb2) = string.split(OFTV)[32:41]
LogFile.write("%5s %5s %5s %5s %5s %5s %5s %5s %8s" % (FGS, FGR, FT1, FT2, FT3, spr, spr, spr, tb2))
LogFile.write("\n")
LogFile.close()
#------- flush and close the serial line -----------------------------------#
dev.flush()
dev.close()