본문 바로가기

etc

리눅스 가상 시리얼 포트 열기

sudo socat PTY,link=/dev/ttyS10 PTY,link=/dev/ttyS08 하면 /dev/ttyS08 이 열림

minicom -D /dev/ttyS08 해서 시리얼 열고 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <termios.h>
#include <fcntl.h>
 
int main( void)
{
   int fd;
 
   struct termios newtio;
 
   fd = open( "/dev/ttyS8", O_RDWR | O_NOCTTY | O_NONBLOCK );
 
   if (fd == -1) {
       puts("open error");
       return 0;
   }
 
 
   memset( &newtio, 0sizeof(newtio) );
 
 
   newtio.c_cflag = B115200;
   newtio.c_cflag |= CS8;
   newtio.c_cflag |= CLOCAL;
   newtio.c_cflag |= CREAD;
   newtio.c_iflag = 0;
   newtio.c_oflag = 0;
   newtio.c_lflag = 0;
   newtio.c_cc[VTIME] = 0;
   newtio.c_cc[VMIN] = 1;
 
   tcflush (fd, TCIFLUSH );
   tcsetattr(fd, TCSANOW, &newtio );
 
   write( fd, "Hello, World!"13);
 
   close( fd);
 
   return 0;
}
cs

일케 소스 짜서 돌리면 minicom으로 Hello, World!가 옴

'etc' 카테고리의 다른 글

BMP File Header  (0) 2015.11.13