Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #custom_postgui.hal
- net spindle-enable => pyvcp.spindle-enable-led in_use_accounting.spindle_on_in
- net reset_session_counters in_use_accounting.session_reset <= pyvcp.session-reset
- net iua00 in_use_accounting.total_runtime_out => pyvcp.total_runtime
- net ioa01 in_use_accounting.session_runtime_out => pyvcp.session_runtime
- net iua10 in_use_accounting.total_machine_on_out => pyvcp.total_machine_on
- net iua11 in_use_accounting.session_machine_on_out => pyvcp.session_machine_on
- net iua20 in_use_accounting.total_prog_run_out => pyvcp.total_prog_run
- net iua21 in_use_accounting.session_prog_run_out => pyvcp.session_prog_run
- net iua30 in_use_accounting.total_spindle_on_out => pyvcp.total_spindle_on
- net iua31 in_use_accounting.session_spindle_on_out => pyvcp.session_spindle_on
- net machine-is-on halui.machine.is-on => and2.0.in0 in_use_accounting.machine_on_in
- net programm-is-running halui.program.is-running => or2.0.in0 in_use_accounting.program_running_in
- #----------------------------------------------------------------------------------------------------
- #custompanel.xml
- <?xml version='1.0' encoding='UTF-8'?>
- <pyvcp>
- <vbox>
- <labelframe text="accounting">
- <table flexible_rows="[2,3,4,5]" flexible_columns="[2,3]">
- <tablesticky sticky="news"/>
- <tablerow/>
- <label>
- <text>""</text>
- </label>
- <label>
- <text>"total:"</text>
- </label>
- <label>
- <text>"session:"</text>
- </label>
- <tablerow/>
- <label>
- <text>"emc on:"</text>
- </label>
- <number>
- <halpin>"total_runtime"</halpin>
- </number>
- <number>
- <halpin>"session_runtime"</halpin>
- </number>
- <tablerow/>
- <label>
- <text>"machine_on:"</text>
- </label>
- <number>
- <halpin>"total_machine_on"</halpin>
- </number>
- <number>
- <halpin>"session_machine_on"</halpin>
- </number>
- <tablerow/>
- <label>
- <text>"program run:"</text>
- </label>
- <number>
- <halpin>"total_prog_run"</halpin>
- </number>
- <number>
- <halpin>"session_prog_run"</halpin>
- </number>
- <tablerow/>
- <label>
- <text>"spindle run:"</text>
- </label>
- <number>
- <halpin>"total_spindle_on"</halpin>
- </number>
- <number>
- <halpin>"session_spindle_on"</halpin>
- </number>
- </table>
- <button>
- <halpin>"session-reset"</halpin>
- <text>"reset session"</text>
- </button>
- </labelframe>
- </vbox>
- </pyvcp>
- #----------------------------------------------------------------------------------------------------
- #in_use_accounting.py
- #!/usr/bin/python
- # HAL userspace component to account for machine use
- #
- # Copyright (C) 2009 Joachim Steiger <reprap@hyte.de>
- #
- # 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
- from math import *
- import sys
- import time
- import pickle
- import hal
- DATAFILE = '/home/emc2/.in_use_logger/accounting.log'
- try:
- import psyco
- psyco.full()
- except ImportError:
- pass
- try:
- data_f = file(DATAFILE,'r')
- data = pickle.load(data_f)
- data_f.close()
- foo = time.localtime()
- data_f = file(DATAFILE+"_backup_%i-%i-%i_%i-%i-%i" % ( foo.tm_year, foo.tm_mon, foo.tm_mday, foo.tm_hour, foo.tm_min, foo.tm_sec),'w')
- pickle.dump(data, data_f)
- data_f.flush()
- data_f.close()
- data_f = file(DATAFILE,'w')
- pickle.dump(data, data_f)
- data_f.flush()
- except IOError:
- data = {}
- data['total_runtime'] = 0.0 # program (axis) running
- data['total_machine_on'] = 0.0 #stepper powered
- data['total_program_running'] = 0.0 #program running
- data['total_spindle_on'] = 0.0 # spindle rotation
- data['session_runtime'] = 0.0 # program (axis) running
- data['session_machine_on'] = 0.0 #stepper powered
- data['session_program_running'] = 0.0 #program running
- data['session_spindle_on'] = 0.0 # spindle rotation
- data_f = file(DATAFILE,'w')
- pickle.dump(data, data_f)
- data_f.flush()
- c = hal.component("in_use_accounting")
- c.newpin("machine_on_in", hal.HAL_BIT, hal.HAL_IN)
- c.newpin("program_running_in", hal.HAL_BIT, hal.HAL_IN)
- c.newpin("spindle_on_in", hal.HAL_BIT, hal.HAL_IN)
- c.newpin("session_reset", hal.HAL_BIT, hal.HAL_IN)
- c.newpin("total_runtime_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.newpin("total_machine_on_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.newpin("total_prog_run_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.newpin("total_spindle_on_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.newpin("session_runtime_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.newpin("session_machine_on_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.newpin("session_prog_run_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.newpin("session_spindle_on_out", hal.HAL_FLOAT, hal.HAL_OUT)
- c.ready()
- newtime = time.time()
- time.sleep(1)
- foo = 0
- try:
- while 1:
- oldtime = newtime
- newtime = time.time()
- inctime = newtime - oldtime
- data['total_runtime'] += inctime
- data['session_runtime'] += inctime
- if c['machine_on_in'] != 0:
- data['total_machine_on'] += inctime
- data['session_machine_on'] += inctime
- if c['program_running_in'] != 0:
- data['total_program_running'] += inctime
- data['session_program_running'] += inctime
- if c['spindle_on_in'] != 0:
- data['total_spindle_on'] += inctime
- data['session_spindle_on'] += inctime
- if c['session_reset'] != 0:
- data['session_runtime'] = 0.0 # program (axis) running
- data['session_machine_on'] = 0.0 #stepper powered
- data['session_program_running'] = 0.0 #program running
- data['session_spindle_on'] = 0.0 # spindle rotation
- c['total_runtime_out'] = data['total_runtime']
- c['session_runtime_out'] = data['session_runtime']
- c['total_machine_on_out'] = data['total_machine_on']
- c['session_machine_on_out'] = data['session_machine_on']
- c['total_prog_run_out'] = data['total_program_running']
- c['session_prog_run_out'] = data['session_program_running']
- c['total_spindle_on_out'] = data['total_spindle_on']
- c['session_spindle_on_out'] = data['session_spindle_on']
- foo += 1
- if foo >10:
- data_f.seek(0)
- pickle.dump(data, data_f)
- data_f.flush()
- foo=0
- time.sleep(1)
- except (KeyboardInterrupt,):
- data_f.flush()
- data_f.close()
- raise SystemExit, 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement