readline
说明
示例
从 Bluetooth 设备读取和写入 ASCII 数据行
创建到附近的 Bluetooth 设备的连接。在此示例中,HC-06 Bluetooth 模块配置为环回设备。
device = bluetooth("HC-06")
device = bluetooth with properties: Name: "HC-06" Address: "98D331FB3B77" Channel: 1 NumBytesAvailable: 0 NumBytesWritten: 0 Show all properties
检查默认的 ASCII 终止符。
device.Terminator
ans = "LF"
将终止符设置为 "CR" 并写入一个 ASCII 数据字符串。writeline
函数自动将终止符追加到数据中。
configureTerminator(device,"CR") writeline(device,"hello")
写入自动追加了终止符的另一个 ASCII 数据字符串。
writeline(device,"world")
由于设备配置为环回设备,写入设备的数据将返回到 MATLAB。读取一个 ASCII 数据字符串。readline
函数返回数据,直到到达终止符。
readline(device)
ans = "hello"
再次读取一个 ASCII 数据字符串,以返回您写入的第二个字符串。
readline(device)
ans = "world"
清除 Bluetooth 连接。
clear device
输入参数
版本历史记录
在 R2020b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 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)