#---------------------------------------------------------------------- # SABVABAA Hovercraft EM ICE Thickness measurements # # University of Bergen, Norway # Dept. of Earth Science # # Rev Date By Description # --------------------------------------------------------------------- # 0.1 19 June 2008 CH & OM Test version #---------------------------------------------------------------------- import serial, math #import winsound from time import gmtime, localtime, strftime VERSION = "Ver. 0.1 Date: 19 June 2008" #--- Remember: In this program, serial ports counted from zero - so COM1 is 0 ... #--- The GPS is using the serial port built-into the PC (this #--- is COM1), but the EM_PORT and the Sonic_port (distance to ice measurements) #--- uses USB-to-serial adapters. And these USB based COM ports may #--- be assigned other COM port names when the PC is rebooted. #2008, with USB Hub #EM_PORT = 15 #Sonic_PORT = 14 #GPS_PORT = 0 # new for 2009 EM_PORT = 7 Sonic_PORT = 1 GPS_PORT = 0 # if the sonar isn't there, as in June 2009, Sonar_ON has to be set to 0, otherwise to 1 Sonar_ON = 0 #------------------------------------------------------------ # M A I N P R O G R A M #------------------------------------------------------------ print ''' ============================================================== EM logger test program Terminate program by CTRL-C (may wait a bit) ''' print "Version ...........:", VERSION print "Serial port used for EM.. : COM", int(EM_PORT + 1) print "Serial port used for Sonic..: COM", int(Sonic_PORT + 1) print ''' ============================================================== ''' FileName = strftime("%Y%m%d%H%M", localtime()) FileName += ".txt" # raw_input("File name: ") # FileName += ".txt" print "File name is", FileName LogFile = open(FileName, "a") #--- Open COM ports #--------- First the EM port try: #EMin = serial.Serial(port=EM_PORT, baudrate=9600) print "EM serial port opened!" except: print '''EM Com port does not exist! Use terminal program Tera Term to check assignments of serial ports, and change COM port settings in top of this program accordingly. ''' exit(0) #EMstring = EMin.readline(eol='\r') # empty incomplete lines #-------- Then the Sonic port (distance measurement to ice surface) try: #Sin = serial.Serial(port=Sonic_PORT, baudrate=38400) print "Sonic serial port opened!" except: print '''Sonic Com port does not exist! Use terminal program Tera Term to check assignments of serial ports, and change COM port settings in top of this program accordingly. ''' exit(0) #Heightstring = Sin.readline(eol='\r') # empty incomplete lines #---------- Open GPS port try: #GPSin = serial.Serial(port=GPS_PORT, baudrate=4800, timeout=0.5) print "GPS port opened!" except: print "GPS Com port does not exist!" exit(0) #GPSstring = GPSin.readline() # empty incomplete lines Lat = 100. Lon = 400. Thickness = 999 s = "1,2,3,4,5,6,7,8,9,0".split(',') #-------------- Loop externally. Interrupt by CTRL-C i=0 print "here" char="\r" while 1: if Sonar_ON == 1: Sin = serial.Serial(port=Sonic_PORT, baudrate=38400) Heightstring = Sin.readline(eol='\r') Heightstring = Sin.readline(eol='\r') #print Heightstring Height = float(Heightstring)/1000. Sin.close() #print "Sonic ok" else: Height = 1.7 #modal height from 2008 EMin = serial.Serial(port=EM_PORT, baudrate=9600) #print "EM port open" EMstring = EMin.readline(eol='\r') EMstring = EMin.readline(eol='\r') #print EMstring EMin.close() AppCond = -float(EMstring[2:7])/4. try: Thickness = -1/0.786 * math.log((AppCond - 15.39)/1146.2) - Height - 0.1 #Final equation from 2008 except: pass #print Heightstring, Height, EMstring, EMstring[2:7] print Lat, Lon, Height, AppCond, Thickness GPSstring = " " GPSin = serial.Serial(port=GPS_PORT, baudrate=4800, timeout=0.5) GPSstringraw = GPSin.readline() #1 #print GPSstringraw if "$GPRMC" in GPSstringraw: GPSstring = GPSstringraw GPSstringraw = GPSin.readline() #2 #print GPSstringraw if "$GPRMC" in GPSstringraw: GPSstring = GPSstringraw GPSstringraw = GPSin.readline() #3 #print GPSstringraw if "$GPRMC" in GPSstringraw: GPSstring = GPSstringraw GPSstringraw = GPSin.readline() #4 #print GPSstringraw if "$GPRMC" in GPSstringraw: GPSstring = GPSstringraw GPSstringraw = GPSin.readline() #5 #print GPSstringraw if "$GPRMC" in GPSstringraw: GPSstring = GPSstringraw GPSstringraw = GPSin.readline() #6 #print GPSstringraw if "$GPRMC" in GPSstringraw: GPSstring = GPSstringraw # GPSstringraw = GPSin.readline() #7 # print GPSstringraw # if "$GPRMC" in GPSstringraw: # GPSstring = GPSstringraw # print GPSstring GPSin.close() #--- print GPSstring if "$GPRMC" in GPSstring: #print GPSstring s = GPSstring.split(',') #print s[1], s[3], s[5] try: Latdeg = int(float(s[3])/100.) Latmin = float(s[3])-100*Latdeg Lat = Latdeg+Latmin/60. Londeg = int(float(s[5])/100.) Lonmin = float(s[5])-100*Londeg Lon = Londeg+Lonmin/60. #print Latdeg, Latmin, Lat, Londeg, Lonmin, Lon except: pass try: Output = "%f\t%f\t%s\t%1.2f\t%1.3f\t%1.2f\n" % (Lat, Lon, s[1], AppCond, Height, Thickness) except: pass LogFile.write(Output) LogFile.flush() # sleep(1) # if char == "\n": # print telegram[:-1] # print value/1000.0 # LogFile.flush() # telegram = "" Sin.close() EMin.close() LogFile.close() exit()