Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Sync paradigma with MRI scanner

Dear All,

Currently i'm investigating possibilities for paradigma presentation in fMRI experiments. The initial idea was to use Cogent, but due to stability / development issues we are investigating the alternative ways.

So far i was able to reproduce the core of the paradigma in OpenSesame, but currently i'm stuck on the synchronization.

The pulse from GE MRI scanner comes to the SyncBox from NordicNeuroLabs and is transmitted to the computer via RS-232 - USB connection. We must use the RS-232 communication, as the other software - nordicActia requires this.

The SyncBox transmits 's' symbol at the beginning of every slice. an we are to start the timing just on the slice.

The generic idea is to make blocking port read on the serial port while the 's' (or any other predefined character) is received. As OpenSesame already has 'srbox' plugin, i thought it will be trivial to create 'syncbox' plugin. Up to the moment

inputbyte1 = ord(inputchar)

As nothing is received on the port, it kills tre paradigma with
TypeError: ord() expected a character, but string of length 0 found

I'm quite new to Python and suppose something wrong is at the lines (see the libsrbox.py):

if inputchar == '':
continue

Any clue for this? How should i denote empty line is Pyton3.5 ?

Comments

  • Hi,

    Python 3 makes a distinction between bytes and str text. (These roughly correspond to str and unicode in Python 2. Confusingly, Python 2 str maps onto Python 3 bytes.)

    I suspect that you get a bytes object when reading from the serial port, and so you need to compare it to a bytes object, otherwise the comparison will always be False. An empty bytes is not identical to an empty str. In other words, the correct comparison would be:

    if inputchar == b'':
    

    However, even better would be to use the fact that empty things are also False, and not assume any particular object type:

    if not inputchar:
    

    Does that make sense?

    In general, I would first read up on how text is handled in Python 3, so that you fully understand the difference between str and bytes. Otherwise you're likely to get stuck or, if you don't, to write code that is likely to break!

    Cheers,
    Sebastiaan

  • Hi Sebastiaan,

    Thank You for the response. It seems to be not so trivial task for me.
    Currently if not inputchar: is not triggered by empty read from the serial port and i'm not sure why.
    I feel like a complete dummy in Python as i'm still unable to print a debug string :)

    BTW: to free the MRI scanner and its interface i've created an Arduino based hardware simulation box. Anyone interested in it?

  • Well, it seems now i can sync the paradigmas using the external signal.
    I've copypasted the new toolbox, called 'syncbox' for this. It holds up the presentation up to a sync character is received on the serial port.

  • edited December 2016

    Hi ejs,

    Thank you for sharing this.

    BTW: to free the MRI scanner and its interface i've created an Arduino based hardware simulation box. Anyone interested in it?

    I'm not interested at this point but if you could upload your files here (assuming they aren't very big) or share a link to them, others can benefit if they stumble upon this discussion in the future.

    Best,
    Jarik

  • Here's the Gihub link to the 'syncbox' plugin and the the fMRI Parrot, an off-scanner sync trigger generator. The last one does not contain the schematics, but the connection and key definitions are obvious from the Arduino sketch.

Sign In or Register to comment.