machinetalk - hello world

81 views
Skip to first unread message

mlampert

unread,
May 19, 2019, 3:23:40 AM5/19/19
to Machinekit
I'm looking for a simple example on how to connect to machinekit (remotely) and - for argument's sake - retrieve the MachineInfo.
I've started up mkwrapper-sim and I can connect to it and use the Cetus UI, so that seems to work alright. When I try to use pymachinetalk I get the this error:

markus@pocketbeagle:~/github/pymachinetalk/examples/application_basic$ python ./command.py
Exception in thread zeroconf-ServiceBrowser__machinekit._tcp.local.:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1170, in run
    handler(self.zc)
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1118, in <lambda>
    state_change=state_change,
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1033, in fire
    h(**kwargs)
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1091, in on_change
    listener.add_service(*args)
  File "/home/markus/github/pymachinetalk/pymachinetalk/dns_sd.py", line 215, in add_service
    info = zeroconf.get_service_info(type_, name)
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1580, in get_service_info
    info = ServiceInfo(type_, name)
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1191, in __init__
    if not type_.endswith(service_type_name(name)):
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 246, in service_type_name
    "Unexpected characters '%s.'" % '.'.join(remaining[1:]))
BadTypeInNameException: Unexpected characters 'local pid 1159.'

Traceback (most recent call last):
  File "./command.py", line 48, in <module>
    get_out_of_estop()
  File "./command.py", line 28, in get_out_of_estop
    raise RuntimeError('Could not connect')
RuntimeError: Could not connect
Exception in thread zeroconf-Reaper (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1017, in run
  File "/usr/lib/python2.7/dist-packages/zeroconf.py", line 1569, in wait
  File "/usr/lib/python2.7/threading.py", line 289, in __exit__
  File "/usr/lib/python2.7/threading.py", line 216, in __exit__
  File "/usr/lib/python2.7/threading.py", line 203, in release
<type 'exceptions.TypeError'>: 'NoneType' object is not callable

Anybody got any pointers? Or can see where I go wrong?

Thanks a bunch,
Markus

mlampert

unread,
May 26, 2019, 9:09:57 PM5/26/19
to Machinekit
I could not find any guide or managed to get any of the examples working. The only example I got to work was machinekit/src/machinetalk/tutorial/zeroconf/resolve.py but didn't understand what was going on - nor was it clear if I have to understand what's happening or not.

Attached are two simple examples I came up with - if there are better ways of doing it please let me know. Both examples use the packages python-zmq and python-zeroconf which are available on all major distributions and for python2 and python3. The reason I used zeroconf instead of the avahi/dbus approach of resolve.py is because it's a lot simpler - at least from my perspective.

mk-hello-world.py scans for all machinekit services and prints each one of them to the screen. Once no more services are discovered the process is terminated by pressing Ctrl+C.

I consider this the hello-world for Machinetalk because it is the first step to connecting to machinetalk. Because Machinetalk uses random ports one must first find a service's endpoint before we can connect to it..

The simple services (from a code effort to usefulness standpoint) are the publish/subscriber services. mk-hello-service.py subsribes to the status and error service. Each published service has a list of topics one can subscribe to (I could not find any documentation about the details). One must subscribe to a topic in order to trigger the initial full update message. An empty string can be used as the topic which serves as a wildcard for all topics - although in this case no initial full update is triggered, but you'll get all subsequent incremental updates.

It turns out to be important that the reverse lookups are setup correctly, otherwise there are significant delays in establishing a connection.


mk-hello-world.py
mk-hello-service.py
Reply all
Reply to author
Forward
0 new messages