Skip to content

Commit 4ccb3af

Browse files
authored
added option to specify serial number for ANT device (#778)
* added option to specify serial number for ant device
1 parent f93e79b commit 4ccb3af

File tree

3 files changed

+63
-12
lines changed

3 files changed

+63
-12
lines changed

docs/SupportedBoards.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ Unlike Ganglion board this BrainFlow board does not use BLED112 dongle, so you n
237237
To create such board you need to specify the following board ID and fields of BrainFlowInputParams object:
238238

239239
- :code:`BoardIds.GANGLION_NATIVE_BOARD`
240-
- *optoinal:* :code:`mac_address`, if not provided BrainFlow will try to autodiscover the device
241-
- *optoinal:* :code:`serial_number`, if not provided BrainFlow will try to autodiscover the device
240+
- *optional:* :code:`mac_address`, if not provided BrainFlow will try to autodiscover the device
241+
- *optional:* :code:`serial_number`, if not provided BrainFlow will try to autodiscover the device
242242

243243
Initialization Example:
244244

@@ -1026,6 +1026,11 @@ Ant Neuro has many devices and all of them are supported by BrainFlow:
10261026
- :code:`ANT_NEURO_EE_225_BOARD`
10271027
- :code:`ANT_NEURO_EE_511_BOARD`
10281028

1029+
The following fields of BrainFlowInputParams object are supported:
1030+
1031+
- *optional:* :code:`serial_number`, important if you have multiple devices in the same place, can be found on the amplifier label (if not provided, BrainFlow will try to autodiscover the device)
1032+
1033+
10291034
Initialization example:
10301035

10311036
.. code-block:: python

python_package/examples/tests/eego_impedances_and_eeg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
if __name__ == '__main__':
77
params = BrainFlowInputParams()
8+
# params.serial_number = '123456' # optional, useful if multiple devices are connected
89
board = BoardShim(BoardIds.ANT_NEURO_EE_411_BOARD, params) # 8 channel amplifier
910
board.prepare_session()
1011

src/board_controller/ant_neuro/ant_neuro.cpp

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,60 @@ int AntNeuroBoard::prepare_session ()
9696
safe_logger (spdlog::level::info, "eego sdk version is: {}.{}.{}.{}",
9797
fact->getVersion ().major, fact->getVersion ().minor, fact->getVersion ().micro,
9898
fact->getVersion ().build);
99-
amp = fact->getAmplifier ();
99+
100+
// Iterate through connected amplifiers
101+
std::vector<amplifier *> amplifier_list = fact->getAmplifiers ();
102+
if (amplifier_list.empty ())
103+
{
104+
throw exceptions::notFound ("no ANT amplifiers found.");
105+
}
106+
107+
std::string expected_board_name = board_descr["default"]["name"];
108+
std::string expected_serial_number = params.serial_number;
109+
110+
std::vector<amplifier *>::iterator iter = amplifier_list.begin ();
111+
for (; iter != amplifier_list.end (); ++iter)
112+
{
113+
amplifier *current_amp = *iter;
114+
std::string current_board_name = "AntNeuro" + current_amp->getType ();
115+
std::string current_serial = current_amp->getSerialNumber ();
116+
117+
if ((!expected_board_name.empty () && current_board_name != expected_board_name) ||
118+
(!expected_serial_number.empty () && current_serial != expected_serial_number))
119+
{
120+
safe_logger (spdlog::level::info,
121+
"Found non-matching amplifier (board name {}, serial {})", current_board_name,
122+
current_serial);
123+
delete current_amp;
124+
continue;
125+
}
126+
127+
// Found the matching amplifier
128+
safe_logger (spdlog::level::info, "Found amplifier (board name {}, serial {})!",
129+
current_board_name, current_serial);
130+
amp = current_amp;
131+
break;
132+
}
133+
134+
// Check if amplifier is found
135+
if (amp == NULL)
136+
{
137+
throw exceptions::notFound (
138+
"no amplifier matched the given board name and serial number.");
139+
}
140+
141+
// Clean up remaining amplifiers after the selected one
142+
while (++iter != amplifier_list.end ())
143+
{
144+
amplifier *current_amp = *iter;
145+
std::string current_board_name = "AntNeuro" + current_amp->getType ();
146+
std::string current_serial = current_amp->getSerialNumber ();
147+
safe_logger (spdlog::level::info,
148+
"Found non-matching amplifier (board name {}, serial {})", current_board_name,
149+
current_serial);
150+
delete current_amp;
151+
}
152+
100153
reference_range = amp->getReferenceRangesAvailable ()[0];
101154
bipolar_range = amp->getBipolarRangesAvailable ()[0];
102155
if (sampling_rate < 0)
@@ -105,18 +158,10 @@ int AntNeuroBoard::prepare_session ()
105158
}
106159
impedance_mode = false;
107160
impedance_package_num = 0;
108-
std::string board_name = "AntNeuro" + amp->getType ();
109-
std::string expected_board_name = board_descr["default"]["name"];
110-
if (expected_board_name != board_name)
111-
{
112-
std::string err_msg = "Board name " + expected_board_name +
113-
" does not match board name of connected device " + board_name;
114-
throw exceptions::notFound (err_msg);
115-
}
116161
}
117162
catch (const exceptions::notFound &e)
118163
{
119-
safe_logger (spdlog::level::err, "No devices found, {}", e.what ());
164+
safe_logger (spdlog::level::err, "Device not found, {}", e.what ());
120165
return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
121166
}
122167
catch (const std::runtime_error &e)

0 commit comments

Comments
 (0)