Reputation: 527
So in my MatLab program I open a COM port to broadcast a pulse using the following:
x = serial('COM10','Baudrate',9600);
However the COM port closes after the pulse has been sent. Since I'm going to be sending lots of pulses throughout the execution of the program I want to keep the COM port permanently open so that I don't have to keep reopening it.
I'm unsure how to do this, it was suggested to me that I put the com port variable into a handle in MatLab to keep it permanently open but I'm not sure how to do this.
Any help would be much appreciated.
Thanks.
Upvotes: 0
Views: 208
Reputation: 1466
It should be open until you close it with fclose:
% Creat serial object
x = serial('COM10','Baudrate',9600);
% Open serial port
fopen(x);
% Write to serial port
fprintf(x,'ABC');'
fprintf(x,'DEF');'
% ...
% Close the serial port
fclose(x);
Upvotes: 2