0

I'm trying to open an utilise a serial port connected to a BBTK USB TTL Module. The code I'm using is as follows:

function [s]=TTLInit

 if ~isempty(instrfind) %Close any open ports
     fclose(instrfind);
     delete(instrfind);
 end


 s=serial('COM3') %Set up serial object 

 try
    fopen(s) %Open serial port
 catch
    disp('TTLInit failed because no port connected')
    s=999;
 end
 if s~=999
    set(s,'BaudRate',115200,'DataBits',8,'StopBits',1,'Parity','none') %Set parameters
    fprintf(s,'RR') %test trigger
 end

This works fine so long as I'm running MATLAB fully. However, I need to be able to utilise this alongside Psychtoolbox which unfortunately means I have to run in No Java Mode. When I try to run this through no java mode it returns the error: "Undefined variable "com" or class "com.mathworks.toolbox.instrument.Instrument.getNonLockedObjects".

My understanding is that this is due to MATLAB needing java to open and control objects (though correct me if I'm wrong!). Therefore, I was wondering if anyone knew a way around this? Is it possible to open serial ports like this and send triggers through them without using the java objects or some other way in no java mode?

Thanks,

Martin

Yoddlenod
  • 41
  • 8

2 Answers2

0

I managed to find a workaround for this. Instead of booting no java mode (which I thought I had to do to get Psychtoolbox to work) I can just boot into no desktop mode. This enables MATLAB to access the java functions it needs (confirming my earlier hypothesis that it was a java issue) but also allows Psychtoolbox to work. So while I didn't find a way to open a serial port without java (and you can continue to discuss this if you like, I would still be interested to learn if there is a way!), I did fix my immediate problem.

Yoddlenod
  • 41
  • 8
0

You typically wouldn't need to boot into no java mode, or no desktop mode for Psychtoolbox to work.

But, if you're using Psychtoolbox, you can use the IOPort function provided by Psychtoolbox for accessing the serial port: http://psychtoolbox.org/docs/IOPort-OpenSerialPort .

This also has the benefit of being designed to work across operating systems and platforms (i.e. both MATLAB and Octave).

DMR
  • 1,479
  • 1
  • 8
  • 11