@feliphegaliza The code seems to be opening the device immediately after closing the device in lines 106-108. Since the NCS device re-enumerates from USB 2 to USB 3 with a call to OpenDevice() and from USB 3 to USB 2 with CloseDevice, the device may be in mid-transition when the OpenDevice() call is being made. This is likely the cause of the failure.
Although dynamic allocation/deallocation is not yet working with the current NCSDK (1.12), we are working on a release candidate at the moment.
Introducing a slight delay before each OpenDevice() may be a work around in the meantime although I know this is not an optimal solution.