writeline
설명
예제
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
입력 인수
device
— Bluetooth 장치 연결
bluetooth
객체
Bluetooth 장치 연결로, bluetooth
객체로 지정됩니다.
예: data = writeline(device,data)
는 Bluetooth 연결 device
에 ASCII 데이터를 씁니다.
data
— ASCII 데이터
문자형 벡터 | string형 스칼라
쓰려는 ASCII 데이터로, 텍스트로 구성된 문자형 벡터나 string형 스칼라로 지정됩니다.
예: writeline(device,"helloworld")
는 ASCII 데이터 "helloworld"
를 씁니다.
데이터형: string
버전 내역
R2020b에 개발됨
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 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)