이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.
코드를 tcpserver 인터페이스로 전환하기
tcpip 함수와 그 객체 함수 및 속성은 제거될 예정입니다. 대신 tcpserver 인터페이스를 사용하십시오.
tcpip 인터페이스 | tcpserver 인터페이스 | 예 |
|---|---|---|
tcpip, NetworkRole, 그리고 fopen | tcpserver | TCP/IP 서버 생성 |
instrfind 및 instrfindall | tcpserverfind | 기존 TCP/IP 서버 찾기 |
fwrite | write | 쓰기와 읽기 |
fread | read | |
fprintf | writeline | 종결된 문자열 읽기 |
fscanf | readline | 종결된 문자열 읽기 |
fgetl | 문자열 데이터 읽기 및 구문 분석 | |
fgets | ||
binblockwrite | writebinblock | 이진 블록 프로토콜을 사용한 데이터 쓰기 및 읽기 |
binblockread | readbinblock | |
flushinput 및 flushoutput | flush | 메모리에서 데이터 플러시하기 |
Terminator | configureTerminator | 종결자 설정하기 |
BytesAvailableFcnCount, BytesAvailableFcnMode, 그리고 BytesAvailableFcn | configureCallback | 콜백 함수 설정 |
BytesAvailable | NumBytesAvailable | |
LocalHost | ServerAddress | |
RemoteHost | ClientAddress | |
LocalPort 및 LocalPortMode | ServerPort | |
RemotePort | ||
ErrorFcn | ErrorOccurredFcn | |
fclose | clear 또는 delete | TCP/IP 서버 연결 끊기 |
제거되는 기능
ValuesReceived 속성 및 ValuesSent 속성은 제거될 예정입니다. NumBytesAvailable 속성과 사용할 수 있는 데이터의 데이터형을 사용하여 전송된 값의 개수를 계산할 수 있습니다. 예를 들어, NumBytesAvailable이 20바이트의 uint32 데이터라면 각 uint32 값이 4바이트이므로 전송된 값의 개수는 5입니다.
readasync 및 stopasync 함수와 ReadAsyncMode, TransferDelay, TransferStatus 속성이 제거될 예정입니다. 업데이트된 인터페이스가 비동기식으로 데이터를 읽어옵니다.
BytesToOutput 속성, InputBufferSize 속성 및 OutputBufferSize 속성은 제거될 예정입니다. 버퍼 크기는 자동으로 관리되며 필요에 따라 크기가 조정됩니다.
OutputEmptyFcn 속성은 제거될 예정입니다. 업데이트된 인터페이스에서는 configureCallback를 사용하여 콜백 함수를 설정할 수 있지만, 이 속성에 대해서는 설정할 수 없습니다.
RecordDetail 속성, RecordMode 속성, RecordName 속성 및 RecordStatus 속성은 제거될 예정입니다.
TimerFcn 속성 및 TimerPeriod 속성은 제거될 예정입니다. timer를 대신 사용하십시오.
Name, Type, ObjectVisibility, Status, Tag 속성은 제거될 예정입니다.
기존 TCP/IP 서버 찾기
instrfind와 instrfindall은 제거될 예정입니다. tcpserverfind를 대신 사용하십시오. (R2024a 이후)
TCP/IP 서버 생성
이 예제들은 권장 기능을 사용하여 TCP/IP 서버를 생성하는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
t = tcpip("192.168.2.15",3030,"NetworkRole","server"); fopen(t) 이는 (내부적으로 ) 호스트 | t = tcpserver("0.0.0.0",3030);이는 |
fopen 함수는 업데이트된 인터페이스에서 사용할 수 없습니다. 객체 생성 함수 tcpserver는 객체를 생성하고 연결합니다.
fclose 함수는 업데이트된 인터페이스에서 사용할 수 없습니다. clear 함수는 객체를 작업 공간에서 제거할 때 해당 객체의 연결을 끊습니다.
자세한 내용은 tcpserver 항목을 참조하십시오.
쓰기와 읽기
이러한 예제에서는 권장 기능을 사용하여 이진 쓰기 및 읽기를 수행하는 방법과 종결되지 않은 문자열 데이터를 쓰고 읽는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
% t is a tcpip object
fwrite(t,1:5);
data = fread(t,5)data =
1
2
3
4
5 | % t is a tcpserver object write(t,1:5,"uint8") data = read(t,5) data =
1 2 3 4 5
|
% t is a tcpip object fwrite(t,"hello","char") length = 5; data = fread(t,length,"char") data = 104 101 108 108 111 data = char(data)' data =
'hello' | % t is a tcpserver object write(t,"hello","string"); length = 5; data = read(t,length,"string") data =
"hello" |
종결된 문자열 읽기
이러한 예제에서는 권장 기능을 사용하여 종결된 문자열 데이터를 쓰고 읽는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
% t is a tcpip object t.Terminator = "CR"; fprintf(t,"hello") data = fscanf(t) data =
'hello
' | % t is a tcpserver object configureTerminator(t,"CR"); writeline(t,"hello"); data = readline(t) data =
"hello" |
% t is a tcpip object t.Terminator = "CR"; fprintf(t,"hello") data = fgetl(t) data =
'hello'
| |
% t is a tcpip object t.Terminator = "CR"; fprintf(t,"hello") data = fgets(t) data =
'hello
'
|
문자열 데이터 읽기 및 구문 분석
이 예제에서는 권장 기능을 사용하여 문자열 데이터를 읽고 구문 분석하는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
% t is a tcpip object data = scanstr(t,';') data =
3×1 cell array
{'a'}
{'b'}
{'c'} | % t is a tcpserver object
data = readline(t)data =
"a;b;c"data = strsplit(data,";")data =
1×3 string array
"a" "b" "c" |
자세한 내용은 readline 항목을 참조하십시오.
이진 블록 프로토콜을 사용한 데이터 쓰기 및 읽기
이 예제에서는 권장 기능을 사용하여 IEEE 표준 이진 블록 프로토콜로 데이터를 쓰는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
% t is a tcpip object
binblockwrite(t,1:5);
data = binblockread(t)data =
1
2
3
4
5 | % t is a tcpserver object writebinblock(t,1:5,"uint8"); data = readbinblock(t) data =
1 2 3 4 5
|
자세한 내용은 writebinblock 또는 readbinblock 항목을 참조하십시오.
메모리에서 데이터 플러시하기
다음 예제에서는 권장 기능을 사용하여 버퍼에서 데이터를 플러시하는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
% t is a tcpip object
flushinput(t)
| % t is a tcpserver object flush(t,"input") |
% t is a tcpip object
flushoutput(t)
| % t is a tcpserver object flush(t,"output") |
% t is a tcpip object
flushinput(t)
flushoutput(t)
| % t is a tcpserver object
flush(t) |
자세한 내용은 flush 항목을 참조하십시오.
종결자 설정하기
이러한 예제에서는 권장 기능을 사용하여 종결자를 설정하는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
% t is a tcpip object t.Terminator = "CR/LF"; | % t is a tcpserver object configureTerminator(t,"CR/LF") |
% t is a tcpip object t.Terminator = {"CR/LF" [10]}; | % t is a tcpserver object configureTerminator(t,"CR/LF",10) |
자세한 내용은 configureTerminator 항목을 참조하십시오.
콜백 함수 설정
이 예제에서는 권장 기능을 사용하여 콜백 함수를 설정하는 방법을 보여줍니다.
| 기능 | 대체 기능 |
|---|---|
% t is a tcpip object t.BytesAvailableFcnCount = 5 t.BytesAvailableFcnMode = "byte" t.BytesAvailableFcn = @mycallback function mycallback(src,evt) data = fread(src,src.BytesAvailableFcnCount); disp(evt) disp(evt.Data) end Type: 'BytesAvailable'
Data: [1×1 struct]
AbsTime: [2019 12 21 16 35 9.7032] | % t is a tcpserver object configureCallback(t,"byte",5,@mycallback); function mycallback(src,evt) data = read(src,src.BytesAvailableFcnCount); disp(evt) end ByteAvailableInfo with properties:
BytesAvailableFcnCount: 5
AbsTime: 21-Dec-2019 12:23:01 |
% t is a tcpip object t.Terminator = "CR" t.BytesAvailableFcnMode = "terminator" t.BytesAvailableFcn = @mycallback function mycallback(src,evt) data = fscanf(src); disp(evt) disp(evt.Data) end Type: 'BytesAvailable'
Data: [1×1 struct]
AbsTime: [2019 12 21 16 35 9.7032] | % t is a tcpserver object configureTerminator(t,"CR") configureCallback(t,"terminator",@mycallback); function mycallback(src,evt) data = readline(src); disp(evt) end TerminatorAvailableInfo with properties:
AbsTime: 21-Dec-2019 12:23:01 |
자세한 내용은 configureCallback 항목을 참조하십시오.
TCP/IP 서버 연결 끊기
fclose 함수는 업데이트된 인터페이스에서 사용할 수 없습니다. TCP/IP 서버 연결을 해제하려면, 단일 작업 공간에서 작업 중인지 다중 작업 공간에서 작업 중인지에 따라 clear 또는 delete를 대신 사용하십시오. 자세한 내용은 tcpserver 함수 도움말 페이지의 다음 예제를 참조하십시오.