Brainflow: "failed to Open Ganglion Device" error [resolved]

edited December 2021 in Ganglion

Hi, I'm trying to connect my Ganglion board to BrainFlow for the first time. My code is almost an exact copy of the one from the BrainFlow docs, except I added "COM3" as the default serial port and GANGLION_BOARD as the default board:

import argparse
import time
import numpy as np

import brainflow
from brainflow.board_shim import BoardShim, BrainFlowInputParams, BoardIds
from brainflow.data_filter import DataFilter, FilterTypes, AggOperations

# 'Ganglion-C97F'


def main():
    BoardShim.enable_dev_board_logger()

    parser = argparse.ArgumentParser()
    # use docs to check which parameters are required for specific board, e.g. for Cyton - set serial port
    parser.add_argument('--timeout', type=int, help='timeout for device discovery or connection', required=False,
                        default=0)
    parser.add_argument('--ip-port', type=int, help='ip port', required=False, default=0)
    parser.add_argument('--ip-protocol', type=int, help='ip protocol, check IpProtocolType enum', required=False,
                        default=0)
    parser.add_argument('--ip-address', type=str, help='ip address', required=False, default='')
    parser.add_argument('--serial-port', type=str, help='serial port', required=False, default='COM3')
    parser.add_argument('--mac-address', type=str, help='mac address', required=False, default='')
    parser.add_argument('--other-info', type=str, help='other info', required=False, default='')
    parser.add_argument('--streamer-params', type=str, help='streamer params', required=False, default='')
    parser.add_argument('--serial-number', type=str, help='serial number', required=False, default='')
    parser.add_argument('--board-id', type=int, help='board id, check docs to get a list of supported boards',
                        required=False, default=BoardIds.GANGLION_BOARD)
    parser.add_argument('--file', type=str, help='file', required=False, default='')
    args = parser.parse_args()

    params = BrainFlowInputParams()
    params.ip_port = args.ip_port
    params.serial_port = args.serial_port
    params.mac_address = args.mac_address
    params.other_info = args.other_info
    params.serial_number = args.serial_number
    params.ip_address = args.ip_address
    params.ip_protocol = args.ip_protocol
    params.timeout = args.timeout
    params.file = args.file

    board = BoardShim(args.board_id, params)
    board.prepare_session()

    # board.start_stream () # use this for default options
    board.start_stream(45000, args.streamer_params)
    time.sleep(10)
    # data = board.get_current_board_data (256) # get latest 256 packages or less, doesnt remove them from internal buffer
    data = board.get_board_data()  # get all data and remove it from internal buffer
    board.stop_stream()
    board.release_session()

    print(data)


if __name__ == "__main__":
    main()

I run with: sudeo python record.py and get the result:

[2021-12-20 10:58:09.826] [board_logger] [trace] Board object created 1
[2021-12-20 10:58:09.829] [board_logger] [debug] Library is loaded
[2021-12-20 10:58:09.829] [board_logger] [info] use 15 as a timeout for device discovery and for callbacks
[2021-12-20 10:58:09.829] [board_logger] [debug] ganglionlib initialized
[2021-12-20 10:58:09.829] [board_logger] [info] mac address is not specified, try to find ganglion without it
[2021-12-20 10:58:09.829] [board_logger] [error] Make sure you provided correct port name and have permissions to open it(run with sudo/admin). And close all other apps using this port.
[2021-12-20 10:58:09.829] [board_logger] [error] failed to Open Ganglion Device 18

I don't know how to verify that I have the correct port name, but I do know no other app is open that is recording from the ganglion. Earlier I was able to successfully record data using OpenBCI GUI but that app is now closed. I couldn't yet find a straightforward tutorial to get me past this issue. What can I try next?

Comments

  • wjcroftwjcroft Mount Shasta, CA

    Matt, hi.

    It is best to ask Brainflow questions on their Slack. Signup with link on this page:

    https://brainflow.org/

    Have you used the Windows Device Manager to look at all your serial COM ports? One of them should display as 'Bluegiga' device, which is the BLED112 dongle. If you have picked the wrong COM port, Brainflow will not be able to connect.

    William

  • Hi wjcroft. I should have clarified I am using a mac.

  • I will take this to the brainflow slack if if there's no quick solution, thanks!

  • wjcroftwjcroft Mount Shasta, CA

    "COM3" or COM+anynumber are device names used on Windows. Mac uses ports which show up in the directory /dev. As you plug / unplug the BLED112, you will see entries appear / disappear in dev.

  • wjcroftwjcroft Mount Shasta, CA

    You should also be able to see which device name is being used, by seeing what the OpenBCI_GUI picks when you start it up.

  • Oops, I forgot all about that. Ok, I used ls /dev/tty.usb* and the result was only a single line: /dev/tty.usbmodem11. So I replaced COM3 with that. Next, I used "Ganglion-C97F" (from OpenBCI GUI) as the default value for mac-address (is that the right one for device name?). The results I get are now:

    [2021-12-20 14:34:29.929] [board_logger] [trace] Board object created 1
    [2021-12-20 14:34:29.930] [board_logger] [debug] Library is loaded
    [2021-12-20 14:34:29.930] [board_logger] [info] use 15 as a timeout for device discovery and for callbacks
    [2021-12-20 14:34:29.930] [board_logger] [debug] ganglionlib initialized
    [2021-12-20 14:34:29.930] [board_logger] [info] search for Ganglion-C97F
    

    And it hangs there forever.

  • wjcroftwjcroft Mount Shasta, CA

    Are you sure you are seeing all the dev entries that appear / disappear when plugged / unplugged? I believe you want the cu* entry.

    https://openbci.com/forum/index.php?p=/discussion/2815/brainflow-serial-port-name-on-raspberry-vs-mac

  • Another step in the right direction, thanks!
    The correct one seems to be /dev/cu.usbmodem11
    Now rather than hanging, I immediately get an error:

    [2021-12-20 15:11:24.307] [board_logger] [debug] use dyn lib: /Users/matt/miniconda3/envs/eeg/lib/python3.9/site-packages/brainflow/lib/libGanglionLib.dylib
    [2021-12-20 15:11:24.307] [board_logger] [trace] Board object created 1
    [2021-12-20 15:11:24.308] [board_logger] [debug] Library is loaded
    [2021-12-20 15:11:24.309] [board_logger] [info] use 15 as a timeout for device discovery and for callbacks
    [2021-12-20 15:11:24.309] [board_logger] [debug] ganglionlib initialized
    [2021-12-20 15:11:24.309] [board_logger] [info] search for Ganglion-C97F
    [2021-12-20 15:11:25.325] [board_logger] [error] failed to Open Ganglion Device 17
    Traceback (most recent call last):
      File "/Users/matt/Desktop/eeg/record.py", line 58, in <module>
        main()
      File "/Users/matt/Desktop/eeg/record.py", line 42, in main
        board.prepare_session()
      File "/Users/matt/miniconda3/envs/eeg/lib/python3.9/site-packages/brainflow/board_shim.py", line 899, in prepare_session
        raise BrainFlowError('unable to prepare streaming session', res)
    brainflow.board_shim.BrainFlowError: GENERAL_ERROR:17 unable to prepare streaming session
    
  • Wjcroft, I'll head straight to slack if the solution is not obvious to you. Thanks for your help.

  • wjcroftwjcroft Mount Shasta, CA

    Do you have OS permission to open that device? Can be done either by owner or group. You can place your userid in the appropriate group for access.

    https://superuser.com/questions/1160608/c-program-cannot-open-serial-port-on-os-x-when-user-is-member-of-wheel

  • I'm guessing this is not the issue since I get the same error even if I run with sudo?

  • wjcroftwjcroft Mount Shasta, CA

    Please post on the Brainflow slack, as previously suggested.

  • Just did and they figured it out. All I had to do was leave "Mac Address" blank. I mistakenly thought mac address and device name were the same.

    It works now.

    Thanks again.

Sign In or Register to comment.