psychopy.org | Reference | Downloads | Github

Sending messages to IOHUB triggers

Hello all,

I am trying to send the messages for my experiment to the IOHUB, so that I can identify when a specific trial, of a specific block was presented on screen, and what information occurred within this time epoch. However, I am having a particular trouble with one specific line of code.

            # Send a msg to the hdf5 file with trial info
            self.hub.sendMessageEvent(text='%.4f  %i %i %i %.6f %.6f %.6f' %(trial, presTime, RT,AorB, RT),sec_time=flip_time) 

The error message I am getting is:

TypeError('float argument required, not TrialType',)
['  File "C:\\Program Files (x86)\\PsychoPy2\\lib\\site-packages\\psychopy\\iohub\\client\\__init__.py", line 1968, in start\n    result=self.run(*sys_argv)\n',
 '  File "E:\\CIT experiment\\Final CIT experiment\\Revised_CIT\\Revised_CIT.py", line 500, in run\n    self.hub.sendMessageEvent(text=\'%.4f  %i %i %i %.6f %.6f %.6f\' %(trial, presTime, RT, AorB, RT),sec_time=flip_time)\n']
ioHub Server Process Completed With Code:  0

I’m not sure, but I suspect it is to do with using the % function with text.

Any help would be hugely welcomed.

Nathan

When in doubt, try:

    print(trial)
    print(type(trial))

The error message is telling you that trial is not a floating point number. You are trying to format it as if it is (i.e. %.4f), but it is actually some other sort of object.

You are also telling the formatted string to expect 7 arguments, but only seem to be passing it 5, which will likely cause another error if you fix the one above.

Hi Michael,

An excellent explanation and solution.
I altered the code to %c, to this:

 # Send a msg to the hdf5 file with trial info
self.hub.sendMessageEvent(text='%c %.6f %.6f %c %.6f' %(trial, presTime, RT,AorB, RT),sec_time=flip_time) 

And then got this error:

TypeError('an integer is required'.)

So, I’m really unsure as to how to change the code accordingly, as I’m not sure which kind of variable ‘trials’ is.

I’ve run the same IOHUB message for RT as the message and this works fine.

Hi Nathan,

Trial is probably an integer, if everything fails you could coerce it to string with str(trial) and then use %s…

You could also try using the alternative method for strings: https://pyformat.info/ which does not require you to declare type:

self.hub.sendMessageEvent(text='{} {:.6f} {:.6f} {} {:.6f}' .format(trial, presTime, RT, AorB, RT), sec_time=flip_time)