#include /* Standard input/output definitions */ #include /* String function definitions */ #include /* UNIX standard function definitions */ #include /* File control definitions */ #include /* Error number definitions */ #include /* POSIX terminal control definitions */ /* pass a char number to be sent to serial port /dev/com2 */ int main(int argc, char *argv[]) { int fd2 = 0; char temp; //open serial port for writing fd2 = init_serial(); temp = atoi(argv[1]); //printf("value is %d\n",temp); send_to_serial(fd2,temp); close(fd2); return 0; } int send_to_serial(int fd, int temp) /* I - Serial port file */ { char buffer; buffer = temp; write(fd, &buffer, 1); /***send to infrared through file descriptor***/ fflush(stdout); return 1; } int init_serial(void) /***open the serial port for writing****/ { int fd; /* File descriptor for the port */ struct termios options; /* open the port */ fd = open("/dev/com2", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { perror("open_port: Unable to open /dev/.... - "); } fcntl(fd, F_SETFL, 0); /* get the current options */ tcgetattr(fd, &options); /* Set to 9600 Baud */ cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); /* set raw input, 1 second timeout */ options.c_cflag |= (CLOCAL | CREAD); options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_oflag &= ~OPOST; options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 10; /* set the options */ tcsetattr(fd, TCSANOW, &options); return fd; }