728x90

원문 링크 : http://www.armadeus.com/wiki/index.php?title=Serial_ports_usage_on_Linux


http://unix.stackexchange.com/questions/117037/how-to-send-data-to-a-serial-port-and-see-any-answer


Changing port parameters


To get current parameters

# stty -F /dev/ttyUSB0

speed 115200 baud;

intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ^J;

eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;

lnext = ^V; flush = ^O; min = 1; time = 0;

-brkint ixoff -imaxbel

-iexten -echoctl


To only get actual speed:

# stty -F /dev/ttySMX0 speed

115200


By default serial ports are configured as terminal emulator. If you want to use them as "raw" serial port you will have to do first (example for port 1):

# stty -F /dev/ttyUSB1 raw

# stty -F /dev/ttyUSB1 -echo -echoe -echok


To change baudrate of port 2 to 115200 :

# stty -F /dev/ttyUSB2 115200

stty -speed 19200 < /dev/ttyS1
stty -speed 19200 -f /dev/ttyS1


Sending/Receiving data

Send

# echo "HELLO" > /dev/ttyUSB0

echo -e "\x7E\x03\xD0\xAF und normaler Text" > /dev/ttyS0

The echo -e command enables the interpretation of backslash escapes.


To receive data (ASCII in that case):

# cat /dev/ttyUSB0



728x90

'Programming > linux왕초보' 카테고리의 다른 글

use vim like as source insight  (0) 2016.04.06
[ubuntu] change default shell  (0) 2016.03.22
GDB를 사용한 CORE 파일의 분석  (0) 2016.02.05
kernel make menuconfig error  (0) 2016.01.21
Caching your GitHub password in Git  (0) 2016.01.08
process 종료  (0) 2015.05.28
fork  (0) 2015.05.26
Linux SSD 최적화  (0) 2015.04.17
fflush, fileno  (0) 2015.04.07
[Linux] stream write  (0) 2015.03.26

+ Recent posts