Hello,
So the problem that I'm having is when writing values to an external device using a serial port. The serial port is set up as follows:
handles.s = serial('COM1');
handles.s.BaudRate = 115200;
handles.s.DataBits = 8;
handles.s.StopBits = 1;
handles.s.Parity = 'NONE';
handles.s.InputBufferSize = (1024*100);
handles.s.Timeout = 3;
fopen(handles.s);
And this code works most of the time. I output values in a loop that uses the function show below to grab them from a GUI and output through the serial port:
function setValue(i, num, hObject, handles, negative)
string = strcat('Setting values (',num2str(i),')');
set(handles.status,'String',string);
fwrite(handles.s,255);
fwrite(handles.s,num);
if(negative == 0)
fwrite(handles.s,floor(str2double(get(hObject,'String'))/256));
fwrite(handles.s,mod(str2double(get(hObject,'String')),256));
else
fwrite(handles.s,floor(-str2double(get(hObject,'String'))/256));
fwrite(handles.s,mod(-str2double(get(hObject,'String')),256));
end
pause(.01);
The problem is that sometimes, unpredictably, the values will stop writing because of a timeout error. This requires me to shut down matlab and my hardware components, restart the machinery, and then reconnect matlab. If matlab could just try writing the value again, I could program my hardware components to ignore bad data and accept the new values... but matlab refuses to work after there has been a timeout error unless it is restarted.
I have read while searching for a solution that there may be "handshake pins" that need to be provided a steady voltage for serial communication to work properly... perhaps this is the solution? If so, where are these magical pins?
Thanks,
Erich