Main Content

writeline

Bluetooth 장치에 ASCII 데이터 라인 쓰기

R2020b 이후

설명

예제

writeline(device,data)는 지정된 Bluetooth® 장치에 ASCII 텍스트 data와 그 뒤에 이어서 종결자를 씁니다. 함수는 데이터와 종결자를 쓸 때까지 MATLAB® 실행을 일시 중단합니다.

예제

모두 축소

근처 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

입력 인수

모두 축소

Bluetooth 장치 연결로, bluetooth 객체로 지정됩니다.

예: data = writeline(device,data)는 Bluetooth 연결 device에 ASCII 데이터를 씁니다.

쓰려는 ASCII 데이터로, 텍스트로 구성된 문자형 벡터나 string형 스칼라로 지정됩니다.

예: writeline(device,"helloworld")는 ASCII 데이터 "helloworld"를 씁니다.

데이터형: string

버전 내역

R2020b에 개발됨

참고 항목

함수