#include #include #include #include #include #include #include #include int main() { int fd; struct termios oldtio, newtio; char buf[255]; fd = open("/dev/rfcomm0", O_RDWR | O_NOCTTY | O_NDELAY); fcntl(fd, F_SETFL, 0); struct termios options; // Get the current options for the port... tcgetattr(fd, &options); // Set the baud rates to 19200... cfsetispeed(&options, B115200); cfsetospeed(&options, B115200); // Enable the receiver and set local mode... options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_cflag |= CSTOPB; // Set the new options for the port... tcsetattr(fd, TCSANOW, &options); /* tcgetattr(fd, &oldtio); */ /* 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; */ /* tcflush(fd, TCIFLUSH); */ /* tcsetattr(fd, TCSANOW, &newtio); */ int i; int res=0; char *cmd = "L,1,2\r"; for(i=0;i<10;i++) { res = write(fd, cmd, strlen(cmd)); printf("Wrote : %d\n", res); res = read(fd, buf, 255); buf[res] = 0; printf("Read : %d\n", res); printf("%s", buf); } tcsetattr(fd, TCSANOW, &oldtio); close(fd); return EXIT_SUCCESS; }