Import LinuxCNC source tree
This commit is contained in:
10
tests/halmodule.2/expected
Normal file
10
tests/halmodule.2/expected
Normal file
@@ -0,0 +1,10 @@
|
||||
- [0, 0, 0, 0, 0, 0, 0]
|
||||
0 [0, 0, 0, 0, 0, 0, 0]
|
||||
1 [1, 0, 0, 1, 0, 1, 1]
|
||||
2 [0, 1, 0, 1, 0, 1, 1]
|
||||
3 [1, 1, 1, 1, 1, 1, 0]
|
||||
- [1, 0, 0, 1, 0, 1, 1]
|
||||
0 [1, 0, 0, 1, 0, 1, 1]
|
||||
1 [0, 1, 0, 1, 0, 1, 1]
|
||||
2 [1, 1, 1, 1, 1, 1, 0]
|
||||
3 [0, 0, 0, 0, 0, 0, 0]
|
||||
51
tests/halmodule.2/halmodtest.py
Executable file
51
tests/halmodule.2/halmodtest.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
#
|
||||
# This shows HAL with Python without creating a component. All functions that
|
||||
# only require a mapped HAL shared memory segment will function fine without a
|
||||
# component.
|
||||
# That means hal.* functions will generally function as expected immediately
|
||||
# after the HAL module is imported.
|
||||
#
|
||||
|
||||
import time
|
||||
import hal
|
||||
|
||||
# Wait for at least one thread cycle
|
||||
def cycleWait():
|
||||
oldtime = time.time()
|
||||
newval = oldval = hal.get_value("testthread.threadbeat")
|
||||
while newval <= oldval:
|
||||
if time.time() - oldtime >= 10.0:
|
||||
sys.exit("error: cycleWait(): Timeout")
|
||||
time.sleep(0.001)
|
||||
newval = hal.get_value("testthread.threadbeat")
|
||||
|
||||
# We need to make sure that the servo-thread ran at least
|
||||
# once for the input to be copied to the output
|
||||
cycleWait()
|
||||
|
||||
sigs = [ "net-input-a", "net-input-b",
|
||||
"and2.0.out", "or2.0.out",
|
||||
"xor2.0.in0", "xor2.0.in1",
|
||||
"net-output" ]
|
||||
|
||||
def values(pfx):
|
||||
out = []
|
||||
for s in sigs:
|
||||
out.append(int(hal.get_value(s)))
|
||||
print(f"{pfx} {out}")
|
||||
|
||||
values("-")
|
||||
|
||||
v = hal.get_s("net-input-a")
|
||||
v += hal.get_s("net-input-b") * 2
|
||||
|
||||
for i in range(4):
|
||||
hal.set_s("net-input-a", 0 != (i+v) & 1)
|
||||
hal.set_s("net-input-b", 0 != (i+v) & 2)
|
||||
# Output is set in the thread cycle, need at least
|
||||
# one cycle after input change
|
||||
cycleWait()
|
||||
values(str(i))
|
||||
|
||||
32
tests/halmodule.2/test.hal
Normal file
32
tests/halmodule.2/test.hal
Normal file
@@ -0,0 +1,32 @@
|
||||
# The goal of this test is to run the 'halmodtest.py' script that will read the
|
||||
# pins *without* creating a component. We only need a mapped HAL shared memory
|
||||
# segment for that.
|
||||
# It is rather unimportant what is loaded. We just need to ensure we have a
|
||||
# working HAL system and some pins we can look at.
|
||||
loadrt threads name1=testthread period1=1000000
|
||||
|
||||
loadrt and2 count=1
|
||||
loadrt or2 count=1
|
||||
loadrt xor2 count=1
|
||||
|
||||
addf and2.0 testthread
|
||||
addf or2.0 testthread
|
||||
addf xor2.0 testthread
|
||||
|
||||
net net-input-a and2.0.in0 or2.0.in0
|
||||
net net-input-b and2.0.in1 or2.0.in1
|
||||
net net-xor-a and2.0.out xor2.0.in0
|
||||
net net-xor-b or2.0.out xor2.0.in1
|
||||
net net-output xor2.0.out
|
||||
|
||||
start
|
||||
|
||||
# Show the initial state
|
||||
loadusr -w ./halmodtest.py
|
||||
|
||||
# Force some value change
|
||||
sets net-input-a 1
|
||||
sets net-input-b 0
|
||||
|
||||
# This should show the changed state
|
||||
loadusr -w ./halmodtest.py
|
||||
Reference in New Issue
Block a user