putty 프로그램과 리눅스 c언어로 시리얼 통신하기
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 | #include <unistd.h> #include <fcntl.h> #include <assert.h> #include <termio.h> #include <string.h> int main(void) { int fd; fd=open("/dev/ttyS1", O_RDWR | O_NOCTTY ); // 컨트롤 c 로 취소안되게 하기 | O_NOCTTY assert(fd != -1); struct termios newtio; // newtio <-- serial port setting. memset(&newtio, 0, sizeof(struct termios)); newtio.c_cflag = B115200 | CS8 | CLOCAL | CREAD; newtio.c_iflag = IGNPAR | ICRNL; newtio.c_oflag = 0; newtio.c_lflag = ~(ICANON | ECHO | ECHOE | ISIG); tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &newtio); // const char *str = "hello, first serial program. \n"; write(fd, str, strlen(str)+1); close(fd); return 0; } |
Configure Virtual Serial Port Driver 으로 가상 포트 com7과 com8을 설정했으며
com7은 windows에서 사용
com8은 vm에서 장치디바이스에서 시리얼통신으로 설정
'Study > 리눅스' 카테고리의 다른 글
리눅스 파일 open, close 로 디바이스 장치 올리기 (0) | 2014.12.03 |
---|---|
프로세서기반 임베디드 리눅스 디바이스 드라이버 (1) (0) | 2014.10.01 |
리눅스로 c언어 컴파일하기 Java (2) (0) | 2014.09.19 |
리눅스로 c언어 컴파일하기 Java (1) (0) | 2014.09.19 |
리눅스로 c언어 컴파일하기 Linked List (2) (0) | 2014.09.19 |