Brainflow's get_board_data() throws error 13 when called twice

I'm trying to use brainflow in Matlab for a P300 matrix speller. I need to get the data after a few trials such that: (1) start_stream() --> (2) Run trials (change color of rows and columns) --> (3) get_board_data() --> (4) process data --> (5) repeat 2-4

But,
get_board_data() is what I need (return all data in the buffer, empty buffer) but seems I can't call it twice (eg: data=get_board_data(); pause(2); data2=get_board_data() throws error 13).

get_current_board_data() could be used but I don't know how many samples are in the buffer (I need all of them) and I want to delete them.

What's the solution? What am I missing?

Comments

  • Andrey1994Andrey1994 Moscow
    edited March 24

    I can reproduce this behaviour if streaming is not running, roughly speaking smth like that throws an error:

    BoardShim.set_log_file('brainflow.log');
    BoardShim.enable_dev_board_logger();
    
    params = BrainFlowInputParams();
    board_shim = BoardShim(int32(BoardIDs.SYNTHETIC_BOARD), params);
    board_shim.prepare_session();
    a = board_shim.config_board('~6');
    board_shim.start_stream(45000, '');
    pause(5);
    board_shim.stop_stream();
    data = board_shim.get_board_data();
    pause(5);
    data2 = board_shim.get_board_data();
    disp(data);
    board_shim.release_session();
    

    While smth like that works fine:

    BoardShim.set_log_file('brainflow.log');
    BoardShim.enable_dev_board_logger();
    
    params = BrainFlowInputParams();
    board_shim = BoardShim(int32(BoardIDs.SYNTHETIC_BOARD), params);
    board_shim.prepare_session();
    a = board_shim.config_board('~6');
    board_shim.start_stream(45000, '');
    pause(5);
    data = board_shim.get_board_data();
    pause(5);
    data2 = board_shim.get_board_data();
    board_shim.stop_stream();
    disp(data);
    board_shim.release_session();
    

    Difference is that get_board_data removes data from the buffer, so its empty when you call it second time(if streaming is stopped) and for empty buffer it throws such error.

    There is a method get_board_data_count(); which you can use to check the current size of the buffer and make sure that you call stop_stream only in the end

  • Yes, that's correct! I noticed I had by mistake stop_stream() at the beginning of my code. First time I was calling get_board_samples(), it returned samples (so didn't throw any error), second time the buffer was empty so it threw the error. Thanks!

Sign In or Register to comment.