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에서 장치디바이스에서 시리얼통신으로 설정




Posted by 차희빈

차희빈

달력