/********************************************* OpenZengRealPlayersController(OZRPC) sample program (receiving data) (c) Junichi Akita (akita@fun.ac.jp) *********************************************/ #include #include #include #include #include #include #include #include #define _POSIX_SOURCE 1 main() { unsigned char buf[10]; struct termios tio; int fd; int num, type; fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY); if (fd < 0) {perror("/dev/ttyS0"); exit(1);} bzero((char *)&tio, sizeof(tio)); tio.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD; tio.c_iflag = IGNPAR | ICRNL; tio.c_oflag = 0; tio.c_lflag = 0; tio.c_cc[VMIN] = 7; tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &tio); while(1){ read(fd, buf, 7); type = (buf[0] & 0xf0) >> 4; num = (buf[0] & 0x0f); printf("#%02d [TYPE:%02x] %02x %02x %02x %02x %02x %02x\n", num, type, buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); } close(fd); }