Advertisement
Guest User

Untitled

a guest
Sep 19th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. #!/usr/bin/python
  2. #
  3. #    This program is free software; you can redistribute it and/or modify
  4. #    it under the terms of the GNU General Public License as published by
  5. #    the Free Software Foundation; either version 2 of the License, or
  6. #    (at your option) any later version.
  7. #
  8. #    This program is distributed in the hope that it will be useful,
  9. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #    GNU General Public License for more details.
  12. #
  13. #    You should have received a copy of the GNU General Public License
  14. #    along with this program; if not, write to the Free Software
  15. #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  16.  
  17. import sys, os
  18. import emc, time
  19. import rs274.options
  20.  
  21. import hal
  22.  
  23. from time import *
  24. import time
  25.  
  26. # mit NML verbinden
  27. import gettext
  28. BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))
  29. gettext.install("emc2", localedir=os.path.join(BASE, "share", "locale"), unicode=True)
  30.  
  31. if len(sys.argv) > 1 and sys.argv[1] == '-ini':
  32.     ini = emc.ini(sys.argv[2])
  33.     emc.nmlfile = ini.find("EMC", "NML_FILE") or emc.nmlfile
  34.     del sys.argv[1:3]
  35.  
  36. s = emc.stat(); s.poll()
  37.  
  38. # funktion um den Dateinamen aus NML zu lesen
  39. def getfilename():
  40.     s.poll()
  41.     for k in dir(s):
  42.         if k.startswith("_"): continue
  43.         v = getattr(s, k)
  44.         if k.startswith("file"):
  45.             return v
  46.  
  47.  
  48. # Datei zum anhaengen oeffnen
  49. filename="/home/cv/emc2-timelogger.txt"
  50. filename=sys.argv[1];
  51. fh = open(filename,"a")
  52. fh.write("# hal_mylogger started at " + strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()) + "\n")
  53.  
  54.  
  55. # Halpins anlegen...
  56. h = hal.component("hal_mylogger")
  57. h.newpin("time", hal.HAL_FLOAT, hal.HAL_IN)
  58. h.newpin("running", hal.HAL_BIT, hal.HAL_IN)
  59. h.ready()
  60.  
  61. old_running = h.running
  62.  
  63. try:
  64.     while 1:
  65.         time.sleep(0.1)
  66.         if h.running != old_running:        
  67.             old_running = h.running
  68.             if not old_running:
  69.                 fh.write(str(h.time) + "s;" + strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()) + ";"+ getfilename() + "\n")
  70.  
  71. except KeyboardInterrupt:
  72.     fh.write("# hal_mylogger terminated at " + strftime("%a, %d %b %Y %H:%M:%S +0000", localtime()) + "\n")
  73.     fh.close()
  74.     raise SystemExit
  75.  
  76. # vim:sw=4:sts=4:et
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement