Usb2ttl8 triggers with IOPort

Hi All,

Im using a USB2TTL8 device (LabHackers Research Equipment : USB2TTL8 Adapter) to send TTL triggers to our EEG amp. This works fine when using matlabs serial and serialport functions, but IOPort wont generate a trigger. Calling ‘OpenSerialPort’ is successful, but the call to ‘Write’ doesn’t produce a trigger. This is using Matlab 2021b on a windows 10. An example of the PTB code I’ve used is below. For context, the text string sent to the ttl device has format of ‘WRITE value [duration] [next_value]\n’

Any help would be greatly appreciated.


params = 'BaudRate=128000 DTR=1 Terminator=10'

[com err] = IOPort('OpenSerialPort', 'COM5', params)

IOPort('Write', com, 'WRITE 10 200 0\n')  

IOPort('Close', com)
1 Like

Probably, because \n only has meaning in a sprintf or fprintf statement etc.,
whereas here \n would just mean the character \ followed by the letter n. Try

IOPort('Write', com, ['WRITE 10 200 0' char(10)])

To encode the \n newline explicitly as ASCII code 10.


That did the trick, thanks Mario!