- Device Not Responding: The device might not be responding to your command as expected. It's possible that the device is busy, not powered, or in a state where it's not sending back data.
- Wrong Terminator: You've configured the terminator as a carriage return (`"CR"`). Ensure that this is indeed the correct terminator expected by the device after it sends its response. If the device uses a different terminator, MATLAB will wait indefinitely for a carriage return that never comes.
- Buffer Issues: There might be unread data in the buffer from previous operations that is not being cleared out, which can confuse subsequent read operations.
- Serial Port Settings: Double-check that all serial port settings (baud rate, parity, stop bits, data bits) match the device's requirements.
- Timeout Setting: The default timeout might be too short for the device to respond. You can increase the timeout to give the device more time to reply.
Why do I receive Timeout occurred waiting for the String Terminator error ?
19 views (last 30 days)
Show older comments
I am trying to communicate with a device with serial port interface. Previously, I got true answer for instance when I asked the name of the device but now even though I havent changed anything I get this error .
s = serialport("COM3",115200);
s.Parity = 'Even' ;
configureTerminator(s,"CR") ;
resp = writeread(s,"gname")
Here is my code for asking the name of the device.
Can anyone help me please ?
0 Comments
Answers (1)
Omega
on 26 Dec 2023
Hi Hür Doga Kantoglu,
I understand that you are facing issues whie communicating with a serial port interface device. The error "Timeout occurred waiting for the String Terminator" suggests that MATLAB is trying to read data from the device over the serial port but is not receiving the expected string terminator within the allotted time frame. This can happen for several reasons:
Here's how you can modify your code to troubleshoot and potentially fix the issue:
% Create serial port object
s = serialport("COM3", 115200);
% Set serial port settings
s.Parity = 'Even';
s.StopBits = 1; % Set the StopBits if needed
s.DataBits = 8; % Set the DataBits if needed
s.Timeout = 10; % Increase timeout to 10 seconds
% Configure terminator
configureTerminator(s, "CR");
% Flush the input and output buffer
flush(s);
% Write the command and read the response
resp = writeread(s, "gname");
% Close the serial port connection when done
clear s;
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!