본문 바로가기
C++ 200제/코딩 IT 정보

socat 리눅스 가상 시리얼 포트(컴포트) 사용법 (RS232 테스트)

by vicddory 2018. 5. 27.

socat 리눅스 가상 시리얼 포트(컴포트) 사용법 (RS232 테스트)



먼저, 가상 시리얼 포트 사용법(RS232 통신 테스트)을 다룬 참조 사이트의 글을 그대로 인용합니다.


You can test socat to create Virtual Serial Port doing the following procedure (tested on Ubuntu 12.04): Open a terminal (let's call it Terminal 0) and execute it: (우분투도 리눅스임)


1
socat --d pty,raw,echo=0 pty,raw,echo=0
cs


The code above returns:


1
2
3
2013/11/01 13:47:27 socat[2506] N PTY is /dev/pts/2
2013/11/01 13:47:27 socat[2506] N PTY is /dev/pts/3
2013/11/01 13:47:27 socat[2506] N starting data transfer loop with FDs [3,3] and [5,5]
cs


Open another terminal and write (Terminal 1): (가상 시리얼 포트를 하나 더 생성)


1
cat < /dev/pts/2
cs


this command's port name can be changed according to the pc. it's depends on the previous output.


1
2
3
2013/11/01 13:47:27 socat[2506] N PTY is /dev/pts/**2**
2013/11/01 13:47:27 socat[2506] N PTY is /dev/pts/**3**
2013/11/01 13:47:27 socat[2506] N starting data transfer loop with FDs 
cs


you should use the number available on highlighted area.


Open another terminal and write (Terminal 2): (여기까지 리눅스 RS232 테스트를 위한 과정)


1
echo "Test" > /dev/pts/3
cs


Now back to Terminal 1 and you'll see the string "Test".


요약해 보면 리눅스 socat에 옵션을 줘서 가상 시리얼 포트(/dev/pts 하단)를 생성하고 터미널 1에선 cat, 터미널 2에선 echo를 이용해 테스트해보라는 것입니다.


그래서, 직접 터미널에서 작업해 봤습니다. 한가지 주의할 건 socat 명령어를 적을 때 띄어쓰기를 딱 맞춰줘야 한다는 것입니다.


리눅스 socat 명령어가 잘 먹질 않는다면 띄어쓰기를 잘못하셨는지를 확인해 보세요.


pty,raw,echo=0... 이 사이엔 공백이 없습니다. 공백 넣으면 명령어 안 먹어요.


1
socat --d pty,raw,echo=0, pty,raw,echo=0
cs


socat -d -d pty raw echo=0 pty raw echo=0socat -d -d pty raw echo=0 pty raw echo=0


cat dev pts 4cat dev pts 4


/dev/pts/n 으로 생성되는 가상 시리얼 포트를 이용해 간단히 테스트를 끝냈습니다.


보드 간 통신 프로그램을 만들 때, 매번 다른 보드에서 테스트하는 것보단, 가상 시리얼 포트로 검증해 놓고 실제 테스트를 진행하는 것이 유리할 겁니다.


socat 리눅스 가상 시리얼 포트(컴포트) 사용법 (RS232 테스트)

댓글