Hi,

I have followed the tutorial on NDSPs. I have a working controller, tested with sipyco_rpctool and with the custom client shown in the tutorial. I am missing how to incorporate it into device_db.py and use it in a custom experiment. I have tried to add to device_db.py the following lines

device_db.update({
    "hello": {
        "type": "controller",
        "host": "::1", #localhost
        "port": 3249,
        "best_effort": False,
        "command": "python //Users/Javier/ARTIQ/Javier/artiq-master/aqctl_hello.py "
    }
})

and tried to run a custom test script

from artiq.experiment import *

class hello_test(EnvExperiment):
    'Test script for hello controller'

    def build(self):
        self.setattr_device("hello")

    def run(self):
        self.hello.message("Hello, World!")

directly from the commandline using artiq_run hello_test.py but I get these error messages

(artiq5) C:\Users\Javier\ARTIQ\Javier\artiq-master>artiq_run hello_test.py
Traceback (most recent call last):
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\master\worker_db.py", line 88, in get
    dev = _create_device(desc, self)
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\master\worker_db.py", line 38, in _create_device
    return cls(desc["host"], desc["port"], target_name)
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\sipyco\pc_rpc.py", line 97, in __init__
    self.__socket = socket.create_connection((host, port), timeout)
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\socket.py", line 712, in create_connection
    raise err
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\socket.py", line 703, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Javier\anaconda3\envs\artiq5\Scripts\artiq_run-script.py", line 9, in <module>
    sys.exit(main())
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\frontend\artiq_run.py", line 225, in main
    return run(with_file=True)
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\frontend\artiq_run.py", line 211, in run
    raise exn
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\frontend\artiq_run.py", line 202, in run
    exp_inst = _build_experiment(device_mgr, dataset_mgr, args)
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\frontend\artiq_run.py", line 188, in _build_experiment
    return get_experiment(module, args.class_name)(managers)
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\language\environment.py", line 220, in __init__
    self.build(*args, **kwargs)
  File "hello_test.py", line 7, in build
    self.setattr_device("hello")
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\language\environment.py", line 304, in setattr_device
    setattr(self, key, self.get_device(key))
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\language\environment.py", line 297, in get_device
    return self.__device_mgr.get(key)
  File "C:\Users\Javier\anaconda3\envs\artiq5\lib\site-packages\artiq\master\worker_db.py", line 91, in get
    .format(name)) from e
artiq.master.worker_db.DeviceError: Failed to create device 'hello'

I'm probably missing important details in the tutorial. I have read some advice I don't fully understand, such as

  1. The controller, which ... artiq.frontend.aqctl_XXX. A setup.py entry must also be created to install it.
  2. An optional client, which ... are front-end tools (called artiq.frontend.aqcli_XXX) that have setup.py entries.

...

tip: Defining the main function instead of putting its code directly in the if name == "main" body enables the controller to be used as well as a setuptools entry point.

I think setuptools is a python library for packaging Python projects (maybe ARTIQ is packaged using it) but I'm not sure if that is related to getting the hello controller to work in an experiment. Is the controller entry in device_db.py wrong? I cannot get more descriptive error messages, not even with artiq_master -v -v and artiq_run -v -v. Should I do something with some setup.py file?

Thanks for any help

update:

I have been reading socket.py around line 712 and wondered what would happen if I started manually the master. It works, so I think the problem must be in getting the controller started, although it doesn't show up until the socket fails.

In three different command windows I have written

(artiq5) C:\Users\Javier\ARTIQ\Javier\artiq-master>artiq_master
ARTIQ master is now ready.

and

(artiq5) C:\Users\Javier\ARTIQ\Javier\artiq-master>python aqctl_hello.py
message: Hello, World!

and

(artiq5) C:\Users\Javier\ARTIQ\Javier\artiq-master>artiq_run -v -v hello_test.py
DEBUG:artiq.compiler.import_cache:hook installed
DEBUG:artiq.compiler.import_cache:added 'hello_test.py' to cache

and I get the greeting in the middle window. I have tried writing the command several ways, with different errors

"command": "python C:\Users\Javier\ARTIQ\Javier\artiq-master\aqctl_hello.py"
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 7-8: truncated \UXXXXXXXX escape

"command": "python C:\\Users\Javier\ARTIQ\Javier\artiq-master\aqctl_hello.py"
artiq.master.worker_db.DeviceError: Failed to create device 'hello'

"command": "python   \\Users\Javier\ARTIQ\Javier\artiq-master\aqctl_hello.py"
artiq.master.worker_db.DeviceError: Failed to create device 'hello'

"command": "python   \\Users\\Javier\\ARTIQ\\Javier\\artiq-master\\aqctl_hello.py"
artiq.master.worker_db.DeviceError: Failed to create device 'hello'

"command": "python   //Users/Javier/ARTIQ/Javier/artiq-master/aqctl_hello.py"
artiq.master.worker_db.DeviceError: Failed to create device 'hello'

"command": "python    /Users/Javier/ARTIQ/Javier/artiq-master/aqctl_hello.py"
artiq.master.worker_db.DeviceError: Failed to create device 'hello'

The problem you have has nothing to do with setup.py.
Your controller is simply not started. You need to either start it manually (run the command in another terminal window) which is typically what you would do while developing it, or use artiq_master + artiq_ctlmgr to have ARTIQ start it based on the device database's contents.

Thanks for the answer. It is working now.