MCPcopy Create free account
hub / github.com/brainflow-dev/brainflow / connect_device

Method connect_device

src/board_controller/neuromd/neuromd_board.cpp:647–688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

645}
646
647int NeuromdBoard::connect_device ()
648{
649 if (device == NULL)
650 {
651 safe_logger (spdlog::level::err, "Device is not created.");
652 return (int)BrainFlowExitCodes::BOARD_NOT_CREATED_ERROR;
653 }
654
655#ifndef _WIN32
656 // "Fix" a race condition in BrainBit SDK on MacOS
657 usleep (5000000);
658#endif
659
660 device_connect (device);
661
662 DeviceState device_state = DeviceStateDisconnected;
663 // on Callibri first attemp fails, repeat several times
664 for (int i = 0; (i < 5) && (device_state != DeviceStateConnected); i++)
665 {
666 int return_code = device_read_State (device, &device_state);
667 if (return_code != SDK_NO_ERROR)
668 {
669 char error_msg[1024];
670 sdk_last_error_msg (error_msg, 1024);
671 safe_logger (spdlog::level::err, "device read state error {}", error_msg);
672 return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
673 }
674#ifdef _WIN32
675 Sleep (1000);
676#else
677 usleep (1000000);
678#endif
679 }
680
681 if (device_state != DeviceStateConnected)
682 {
683 safe_logger (spdlog::level::err, "Device is not connected.");
684 return (int)BrainFlowExitCodes::BOARD_NOT_READY_ERROR;
685 }
686
687 return (int)BrainFlowExitCodes::STATUS_OK;
688}
689
690////////////////////////////
691/// Linux Implementation ///

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected