summaryrefslogtreecommitdiffstats
path: root/linuxcnc/awlsim-linuxcnc-hal
blob: edd4cc61f41c04a89efd2e65fe61aa3213ce3a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
#
# LinuxCNC HAL module
# Copyright 2013 Michael Buesch <m@bues.ch>
#
# 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())
bues.ch cgit interface