Can you do the writeline function without the added terminator?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I know that the writeline function adds the '\n' terminator at the end of a string, but I was wondering if there was a way to write strings without the terminator. Lets look at the following example:
s = serialport('COM7', 9600); % Open the serial port
choice = randi(2);
if choice == 1
writeline(s, "Bananas ");
elseif choice == 2
writeline(s, "Apples ");
end
writeline(s, "are good");
delete(s);
Notice how the intended output could either be "Bananas are good" or "Apples are good". However in practice, it becomes "Bananas
are good" or "Apples
are good". Is there any way to just stop this terminator from even activating?
0 Kommentare
Akzeptierte Antwort
Voss
am 23 Apr. 2024
This documentation page:
states that the "Allowed terminator values are "LF" (default), "CR", "CR/LF", and integer values from 0 to 255", so it looks like there's no way to writeline without a terminator character. (But you could choose terminator 32 to use a space instead of a newline, for instance.)
However, in the case of your particular code, you can just construct the entire string you want to write before you write it, i.e.:
s = serialport('COM7', 9600); % Open the serial port
choice = randi(2);
if choice == 1
str = "Bananas ";
else
str = "Apples ";
end
str = str + "are good";
writeline(str);
delete(s);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!