Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- import sys, os
- import emc, time
- import rs274.options
- import hal
- from time import *
- import time
- # mit NML verbinden
- import gettext
- BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))
- gettext.install("emc2", localedir=os.path.join(BASE, "share", "locale"), unicode=True)
- if len(sys.argv) > 1 and sys.argv[1] == '-ini':
- ini = emc.ini(sys.argv[2])
- emc.nmlfile = ini.find("EMC", "NML_FILE") or emc.nmlfile
- del sys.argv[1:3]
- s = emc.stat(); s.poll()
- # funktion um den Dateinamen aus NML zu lesen
- def getfilename():
- s.poll()
- for k in dir(s):
- if k.startswith("_"): continue
- v = getattr(s, k)
- if k.startswith("file"):
- return v
- # Datei zum anhaengen oeffnen
- filename="/home/cv/emc2-timelogger.txt"
- filename=sys.argv[1];
- fh = open(filename,"a")
- fh.write("# hal_mylogger started at " + strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()) + "\n")
- # Halpins anlegen...
- h = hal.component("hal_mylogger")
- h.newpin("time", hal.HAL_FLOAT, hal.HAL_IN)
- h.newpin("running", hal.HAL_BIT, hal.HAL_IN)
- h.ready()
- old_running = h.running
- try:
- while 1:
- time.sleep(0.1)
- if h.running != old_running:
- old_running = h.running
- if not old_running:
- fh.write(str(h.time) + "s;" + strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()) + ";"+ getfilename() + "\n")
- except KeyboardInterrupt:
- fh.write("# hal_mylogger terminated at " + strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()) + "\n")
- fh.close()
- raise SystemExit
- # vim:sw=4:sts=4:et
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement