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