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