====== USB2OSC Arduino/DS3232====== Lire des informations venant d'un port USB pour les transférer vers de l'OSC Ici on récupère les lignes du port sur lequel est l'arduino/RCT pour mettre à jour l'horloge générale et aussi la température (dallas ds3232) #!/usr/bin/python # -*- coding: utf-8 -*- import serial, time, liblo, sys, os PORT="/dev/ttyUSB0" BAUDS=115200 PORTOSC=9001 IPOSC="localhost" HWCLOCK=0 temp=0 try: targetOSC = liblo.Address('127.0.0.1',9001) except liblo.AddressError, err: print str(err) sys.exit() try: ser = serial.Serial(PORT,BAUDS,timeout=1) except: sys.stderr.write("Error opening serial port %s\n" % (ser.portstr) ) sys.exit(1) while (True): try: line = ser.readline() if len(line) > 13 : temp = line[22:27] year = line[8:10] if HWCLOCK == 0 and year > 14 : date_line = line[3:5] +'/' + line[0:2] + '/' + year time_line = line[11:19] # recup de la date venant du arduino/rtc 2014Oct21 17:32:51 et maj 1 seule fois # test si > 2014 alors date ok os.system('date -s %s' %date_line) os.system('date -s %s' %time_line) os.system('hwclock --systohc') HWCKOCK=1 # au cas ou penser a strftime() et strptime() print "%s" % date_line print "%s" % time_line liblo.send(targetOSC,"/DATE", date_line) liblo.send(targetOSC,"/TIME", date_line) liblo.send(targetOSC,"/TEMP", ('d',temp) ) time.sleep(.5) except KeyError: pass except KeyboardInterrupt: quit()