#!/usr/bin/env python2.7 # -*- coding: utf-8 -*- # # LinuxCNC HAL module # Copyright 2013 Michael Buesch # # Licensed under the terms of the GNU General Public License version 2. # import sys import os import hal from hal import HAL_BIT, HAL_U32, HAL_S32, HAL_FLOAT from hal import HAL_IN, HAL_OUT, HAL_RO, HAL_RW from awlsim import * from awlsim.util import * class AwlSimHAL(object): def __init__(self): self.h = hal.component("awlsim") self.__createHalPins() self.h.ready() def __createHalPins(self): h = self.h #TODO h.newparam("NAME", HAL_BIT, HAL_RW) #TODO h.newpin("NAME", HAL_BIT, HAL_IN) pass#TODO def __checkLinuxCNC(self): for lockname in ("/tmp/linuxcnc.lock", "/tmp/emc.lock"): try: os.stat(lockname) return True except OSError: pass printError("LinuxCNC: doesn't seem to be running") raise KeyboardInterrupt def eventLoop(self): while self.__checkLinuxCNC(): pass#TODO def main(): try: os.nice(-5) except OSError as e: printWarning("WARNING: Failed to renice awlsim HAL module: %s" % str(e)) try: awlsimhal = AwlSimHAL() awlsimhal.eventLoop() except KeyboardInterrupt as e: printInfo("Awlsim HAL module shutdown") return 0 if __name__ == "__main__": sys.exit(main())