write
설명
예제
Bluetooth 장치로 데이터 쓰기와 읽기
근처 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
값 1:10
을 장치에 씁니다.
write(device,1:10)
장치가 루프백 장치로 구성되어 있으므로 장치에 쓰는 데이터는 MATLAB®으로 반환됩니다. 모든 데이터를 읽어 들입니다.
read(device,10)
ans = 1×10 1 2 3 4 5 6 7 8 9 10
Bluetooth 장치로 쓰고 읽기 위한 데이터형 지정하기
근처 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
문자열 "helloworld"
를 장치에 씁니다.
write(device,"helloworld","string")
장치가 루프백 장치로 구성되었으므로 장치에 쓰는 데이터는 MATLAB에 반환됩니다. 데이터의 처음 5개 값을 string형으로 읽어옵니다.
read(device,5,"string")
ans = "hello"
read
명령을 다시 사용하여 데이터의 그다음 5개 값을 읽어옵니다.
read(device,5,"string")
ans = "world"
입력 인수
device
— Bluetooth 장치 연결
bluetooth
객체
Bluetooth 장치 연결로, bluetooth
객체로 지정됩니다.
예: write(device,10)
은 Bluetooth 연결 device
에 씁니다.
data
— 숫자형 또는 ASCII 데이터
1×N
숫자형 배열 | 문자형 벡터 | string형 스칼라
숫자형 또는 ASCII 데이터로, 숫자형 값으로 구성된 1×N 벡터 또는 텍스트로 구성된 문자형 벡터나 string형 스칼라로 지정됩니다. 숫자형 datatype
유형인 모든 경우에 대해, data
는 값으로 구성된 행 벡터입니다.
예: write(device,300)
은 값 300
을 씁니다.
데이터형: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| char
| string
datatype
— 각 값의 크기와 형식
"uint8"
(디폴트 값) | "int8"
| "uint16"
| "int16"
| "uint32"
| "int32"
| "uint64"
| "int64"
| "single"
| "double"
| "char"
| "string"
각 값의 크기와 형식으로, 문자형 벡터 또는 string형으로 지정됩니다. datatype
은 각 값에 대해 쓸 바이트 수와 해당 바이트에 대한 해석을 MATLAB 데이터형으로 결정합니다.
모든 읽기 작업이나 쓰기 작업에서는 데이터 전송을 위해 데이터형이 uint8
로 변환됩니다. 전송 후 데이터형은 지정된 datatype
으로 되돌아갑니다.
예: write(device,1:5,"double")
은 값 [1,2,3,4,5]
를 double 데이터형으로 씁니다.
데이터형: char
| 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)