writeline
Write line of ASCII data to serial port
Syntax
Description
Examples
Write and Read Line of ASCII Data from Serial Port Device
Create a connection to a serial port device. In this example, the serial port at
COM3
is connected to a loopback device.
device = serialport("COM3",9600)
device = Serialport with properties: Port: "COM3" BaudRate: 9600 NumBytesAvailable: 0 Show all properties, functions
Check the default ASCII terminator.
device.Terminator
ans = "LF"
Set the terminator to "CR"
and write a string of ASCII data. The
writeline
function automatically appends the terminator to the
data.
configureTerminator(device,"CR") writeline(device,"hello")
Write another string of ASCII data with the terminator automatically appended.
writeline(device,"world")
Since the port is connected to a loopback device, the data you write to the device
is returned to MATLAB. Read a string of ASCII data. The readline
function
returns data until it reaches a terminator.
readline(device)
ans = "hello"
Read a string of ASCII data again to return the second string that you wrote.
readline(device)
ans = "world"
Clear the serial port connection.
clear device
Input Arguments
device
— Serial port connection
serialport
object
Serial port connection, specified as a serialport
object.
Example: writeline(device,1:5)
writes to the serial port
connection device
.
data
— ASCII data
character vector | string scalar
ASCII data to write, specified as a character vector or string scalar of text.
Example: writeline(device,"*IDN?")
writes the ASCII string
"*IDN?"
Data Types: char
| string
Version History
Introduced in R2019b
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)