def test_newsig(self): l.log() hal.newsig("floatsig1", hal.HAL_FLOAT) try: hal.newsig("floatsig1", hal.HAL_FLOAT) # RuntimeError: Failed to create signal floatsig1: HAL: ERROR: duplicate signal 'floatsig1' raise "should not happen" except RuntimeError: pass try: hal.newsig(32423 * 32432, hal.HAL_FLOAT) raise "should not happen" except TypeError: pass try: hal.newsig(None, hal.HAL_FLOAT) raise "should not happen" except TypeError: pass try: hal.newsig("badtype", 1234) raise "should not happen" except TypeError: pass
def test_net_existing_signal_with_bad_type(self): l.log() hal.newsig("f", hal.HAL_FLOAT) try: hal.net("f", "c1.s32out") raise "should not happen" except TypeError: pass del hal.signals["f"] assert 'f' not in hal.signals
def test_net_existing_signal(self): l.log() hal.newsig("s32", hal.HAL_S32) assert hal.pins["c1.s32out"].linked is False hal.net("s32", "c1.s32out") assert hal.pins["c1.s32out"].linked is True hal.newsig("s32too", hal.HAL_S32) try: hal.net("s32too", "c1.s32out") raise "should not happen" except RuntimeError: pass del hal.signals["s32"] assert 's32' not in hal.signals
def test_check_net_args(self): l.log() try: hal.net() except TypeError: pass assert 'c1-s32out' not in hal.signals try: hal.net(None, "c1.s32out") except TypeError: pass assert 'c1-s32out' not in hal.signals # single pin argument assert hal.pins["c1.s32out"].linked is False try: hal.net("c1.s32out") # RuntimeError: net: at least one pin name expected except RuntimeError: pass # XXX die beiden gehen daneben: # der pin wird trotz runtime error gelinkt und das signal erzeugt: # offensichtlich hal_net.pyx:39 vor dem test in hal_net.pyx:60 assert hal.pins["c1.s32out"].linked is False assert 'c1-s32out' not in hal.signals # single signal argument try: hal.net("noexiste") # RuntimeError: net: at least one pin name expected except RuntimeError: pass # two signals hal.newsig('sig1', hal.HAL_FLOAT) hal.newsig('sig2', hal.HAL_FLOAT) try: hal.net('sig1', 'sig2') # NameError: no such pin: sig2 except NameError: pass assert "noexiste" not in hal.signals hal.net("noexiste", "c1.s32out") assert "noexiste" in hal.signals ne = hal.signals["noexiste"] assert ne.writers == 1 assert ne.readers == 0 assert ne.bidirs == 0 try: hal.net("floatsig1", "c1.s32out") raise "should not happen" except RuntimeError: pass
# vim: sts=4 sw=4 et # basic HAL operations: # create a component with some pins # create a signal # link pin to signal # get/set pin values import time import machinekit.hal.cyhal as hal c = hal.Component('zzz') p = c.newpin("p0", hal.HAL_S32, hal.HAL_OUT, init=42) o0 = c.newpin("p1", hal.HAL_S32, hal.HAL_IN) o1 = c.newpin("p2", hal.HAL_S32, hal.HAL_IN) s = hal.newsig("signal", hal.HAL_S32) p.link(s) s.link(o0, o1) c.ready() print(p.get(), o0.get(), o1.get()) p.set(20) print(o0.get(), o1.get()) # give some time to watch in halcmd time.sleep(10) hal.delsig("signal") # exiting here will remove the comp, and unlink the pins