writeline stuck on busy when serial device connected to port not turned on.
I have a serial connection to an external device, which works perfect if the unit is connected and on, but if the unit is off or disconnected, the check on the serial port using writeline, writeread, or fprintf all result in Matlab getting stuck on busy. My PC is using a PCIe serial card, so the COM PORTs are present and the serialport function sets up the COM PORT for communication.
SComPort = 17;
SBaudRate = 9600;
SDataBits = 8;
SParity = "none";
SStopBits = 1;
SFlowControl = "hardware";
STimeout = 1;
SWriteTerminator = "CR";
SReadTerminator = "CR/LF";
try
SComm = serialport(sprintf(‘COM%i’,SComPort), SBaudRate,’Timeout’, STimeout);
SComm.DataBits = SDataBits;
SComm.Parity = SParity;
SComm.StopBits = SStopBits;
SComm.FlowControl = SFlowControl;
bSComm = true;
objS_IO.Valid = true;
configureTerminator(SComm, SReadTerminator, SWriteTerminator)
catch
disp(‘Unable to find S comm port!’);
bSComm = false;
SComm = [];
s = -1;
end
% All of these functions error out with the device disconnected or turned off.
response = writeread(SComm,"version");
writeline(SComm, "version");I have a serial connection to an external device, which works perfect if the unit is connected and on, but if the unit is off or disconnected, the check on the serial port using writeline, writeread, or fprintf all result in Matlab getting stuck on busy. My PC is using a PCIe serial card, so the COM PORTs are present and the serialport function sets up the COM PORT for communication.
SComPort = 17;
SBaudRate = 9600;
SDataBits = 8;
SParity = "none";
SStopBits = 1;
SFlowControl = "hardware";
STimeout = 1;
SWriteTerminator = "CR";
SReadTerminator = "CR/LF";
try
SComm = serialport(sprintf(‘COM%i’,SComPort), SBaudRate,’Timeout’, STimeout);
SComm.DataBits = SDataBits;
SComm.Parity = SParity;
SComm.StopBits = SStopBits;
SComm.FlowControl = SFlowControl;
bSComm = true;
objS_IO.Valid = true;
configureTerminator(SComm, SReadTerminator, SWriteTerminator)
catch
disp(‘Unable to find S comm port!’);
bSComm = false;
SComm = [];
s = -1;
end
% All of these functions error out with the device disconnected or turned off.
response = writeread(SComm,"version");
writeline(SComm, "version"); I have a serial connection to an external device, which works perfect if the unit is connected and on, but if the unit is off or disconnected, the check on the serial port using writeline, writeread, or fprintf all result in Matlab getting stuck on busy. My PC is using a PCIe serial card, so the COM PORTs are present and the serialport function sets up the COM PORT for communication.
SComPort = 17;
SBaudRate = 9600;
SDataBits = 8;
SParity = "none";
SStopBits = 1;
SFlowControl = "hardware";
STimeout = 1;
SWriteTerminator = "CR";
SReadTerminator = "CR/LF";
try
SComm = serialport(sprintf(‘COM%i’,SComPort), SBaudRate,’Timeout’, STimeout);
SComm.DataBits = SDataBits;
SComm.Parity = SParity;
SComm.StopBits = SStopBits;
SComm.FlowControl = SFlowControl;
bSComm = true;
objS_IO.Valid = true;
configureTerminator(SComm, SReadTerminator, SWriteTerminator)
catch
disp(‘Unable to find S comm port!’);
bSComm = false;
SComm = [];
s = -1;
end
% All of these functions error out with the device disconnected or turned off.
response = writeread(SComm,"version");
writeline(SComm, "version"); writeline, readwrite, serialport MATLAB Answers — New Questions