|
| 1 | +Configuration files |
| 2 | +=================== |
| 3 | + |
| 4 | +Description |
| 5 | +----------- |
| 6 | + |
| 7 | +The NXT-Python configuration files allow to define the NXT bricks you want to |
| 8 | +connect to, so that you do not need to give the needed argument for every |
| 9 | +scripts. |
| 10 | + |
| 11 | +You can place a :file:`.nxt-python.conf` in your home directory, or in the |
| 12 | +current directory. You can also explicitly give configuration file name to the |
| 13 | +invoked script or function. |
| 14 | + |
| 15 | + |
| 16 | +Format |
| 17 | +------ |
| 18 | + |
| 19 | +The configuration format is a INI-style format. It consists of several |
| 20 | +sections introduced by the section name in square brackets on its line. Each |
| 21 | +section contains a set of key/value pairs. The key and value are separated by |
| 22 | +a equal sign ('='). |
| 23 | + |
| 24 | +Configuration may include comments which are introduced by a '#' character. |
| 25 | + |
| 26 | +When looking for a brick, you can request NXT-Python to use a specific |
| 27 | +section, or :code:`[default]` if not specified. If the section is missing, or |
| 28 | +if a value is missing, the :code:`[DEFAULT]` section (note the uppercase) is |
| 29 | +used as a fallback. |
| 30 | + |
| 31 | +The following values can be defined: |
| 32 | + |
| 33 | +backends |
| 34 | + This is the space separated list of backends to use to find and connect to |
| 35 | + the brick. When not specified, a default list of backends is used: |
| 36 | + |
| 37 | + - :mod:`~nxt.backend.devfile` if :code:`filename` is given, |
| 38 | + - :mod:`~nxt.backend.socket` if :code:`server_host` or :code:`server_port` |
| 39 | + is given, |
| 40 | + - :mod:`~nxt.backend.usb` and, |
| 41 | + - :mod:`~nxt.backend.bluetooth`. |
| 42 | + |
| 43 | +name |
| 44 | + Brick name which is used to find the brick (for example: NXT). The brick |
| 45 | + name can be configured using the NXT brick menus. |
| 46 | + |
| 47 | +host |
| 48 | + Bluetooth address which is used to find the brick (for example: |
| 49 | + 00:16:53:01:02:03). When using Bluetooth backend, this allows a direct |
| 50 | + connection without having to scan to find the brick. For other backends, it |
| 51 | + can be used to select the right brick when several bricks are found. |
| 52 | + |
| 53 | + The address can be found in the "Settings" menu, under "NXT Version" |
| 54 | + screen, it is the last line labeled "ID". Add the colon to separated each |
| 55 | + pair of digits. |
| 56 | + |
| 57 | +server_host |
| 58 | + Server address or name (example: 192.168.1.3, or localhost). |
| 59 | + |
| 60 | + This is used by the :code:`socket` backend. |
| 61 | + |
| 62 | + .. only:: man |
| 63 | + |
| 64 | + The server is provided by the :manpage:`nxt-server(1)` command. |
| 65 | + |
| 66 | + .. only:: not man |
| 67 | + |
| 68 | + The server is provided by the :doc:`nxt-server </commands/nxt-server>` |
| 69 | + command. |
| 70 | + |
| 71 | +server_port |
| 72 | + Server connection port (default: 2727). |
| 73 | + |
| 74 | + This is used by the :code:`socket` backend. |
| 75 | + |
| 76 | + .. only:: man |
| 77 | + |
| 78 | + The server is provided by the :manpage:`nxt-server(1)` command. |
| 79 | + |
| 80 | + .. only:: not man |
| 81 | + |
| 82 | + The server is provided by the :doc:`nxt-server </commands/nxt-server>` |
| 83 | + command. |
| 84 | + |
| 85 | +filename |
| 86 | + Device file name (default is platform specific). |
| 87 | + |
| 88 | + This is used by the :mod:`~nxt.backend.devfile` backend to locate the |
| 89 | + RFCOMM device file. |
| 90 | + |
| 91 | + .. only:: man |
| 92 | + |
| 93 | + Please see NXT-Python documentation for more details on how to use this. |
| 94 | + |
| 95 | +Other values |
| 96 | + Other values are passed as-is to backends. |
| 97 | + |
| 98 | + |
| 99 | +Example |
| 100 | +------- |
| 101 | + |
| 102 | +Given the following configuration file: |
| 103 | + |
| 104 | +.. code:: ini |
| 105 | +
|
| 106 | + [DEFAULT] |
| 107 | + # Defines a fallback for every configuration name. |
| 108 | + backends = usb |
| 109 | +
|
| 110 | + [default] |
| 111 | + # My default NXT, sitting on my desk. |
| 112 | + host = 00:16:53:01:02:03 |
| 113 | + name = NXT |
| 114 | +
|
| 115 | + [lab] |
| 116 | + # When working at the lab, use my second NXT. |
| 117 | + name = NXT2 |
| 118 | +
|
| 119 | + [robot] |
| 120 | + # Use Bluetooth for my third NXT, which is embedded in a robot, but try USB |
| 121 | + # first as this is faster. |
| 122 | + backends = usb bluetooth |
| 123 | + host = 00:16:53:aa:bb:cc |
| 124 | + name = ROBOT |
| 125 | +
|
| 126 | +When using the command line, NXT-Python will connect to my default NXT if I |
| 127 | +do not give more options:: |
| 128 | + |
| 129 | + $ nxt-test |
| 130 | + Finding brick... |
| 131 | + NXT brick name: NXT |
| 132 | + ... |
| 133 | + |
| 134 | +I can request to connect to my robot NXT brick like this:: |
| 135 | + |
| 136 | + $ nxt-test --config robot |
| 137 | + Finding brick... |
| 138 | + NXT brick name: ROBOT |
| 139 | + ... |
| 140 | + |
| 141 | +Or when using a script: |
| 142 | + |
| 143 | +.. code:: python |
| 144 | +
|
| 145 | + import nxt.locator |
| 146 | + b = nxt.locator.find(config="robot") |
| 147 | +
|
| 148 | +
|
| 149 | +Files |
| 150 | +----- |
| 151 | + |
| 152 | +:file:`$HOME/.nxt-python.conf` |
| 153 | + Per user configuration file. |
| 154 | + |
| 155 | +:file:`.nxt-python.conf` |
| 156 | + Configuration file in current directory. |
| 157 | + |
| 158 | + |
| 159 | +.. only:: man |
| 160 | + |
| 161 | + See also |
| 162 | + -------- |
| 163 | + |
| 164 | + :manpage:`nxt-test(1)` |
| 165 | + |
| 166 | + NXT-Python documentation <https://ni.srht.site/nxt-python/latest/> |
0 commit comments