File: display.py

package info (click to toggle)
linuxcnc 1%3A2.9.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 285,604 kB
  • sloc: python: 202,568; ansic: 109,036; cpp: 99,239; tcl: 16,054; xml: 10,631; sh: 10,303; makefile: 1,255; javascript: 138; sql: 72; asm: 15
file content (53 lines) | stat: -rwxr-xr-x 1,111 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

import time
import os
import sys

import linuxcnc
import linuxcnc_util
import hal

sys.stdout = os.fdopen(sys.stdout.fileno(), 'w')

c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel
l = linuxcnc_util.LinuxCNC(command=c, status=s, error=e)

print("info: Turning machine on")
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.wait_complete()

c.home(0)
c.home(1)
c.home(2)

print("info: Waiting for homing to complete")
l.wait_for_home([1, 1, 1, 0, 0, 0, 0, 0, 0])

c.mode(linuxcnc.MODE_MDI)

print("info: Moving to X1")
c.mdi("G0 X1Y0Z0")
c.wait_complete()
s.poll()

h = hal.component("python-ui")

# Wait for next MQTT publication
name='mqtt-publisher.lastpublish'
timeout = 10
lastpublish = hal.get_value(name)
start_time = time.time()
while (time.time() - start_time) < timeout and \
      hal.get_value(name) == lastpublish:
    time.sleep(0.1)
if hal.get_value(name) == lastpublish:
    raise RuntimeError(f"error: no MQTT publishing happened within {timeout} seconds")

print("info: Turning machine off")
c.state(linuxcnc.STATE_OFF)

sys.exit(0)