/* * This is an example file showing how to send data to the serial port. * * It does not include error checking. */ #include #include #include #include #include #include #define DEVICE "/dev/ttyS1" int openPort(char *device); void closePort(int fd); int main(int argc, char **argv) { int serial; serial = openPort(DEVICE); if (serial == -1) exit(1); write(serial, "\xFE\x58", 2); /* Clear Screen: 254 88 */ write(serial, "\xFE\x47\x05\x02", 4); /* Goto(5,2): 254 71 5 2 */ write(serial, "Hello World", 11); closePort(serial); return(0); } /*************************************************************************** * Serial functions **************************************************************************/ /* Open raw serial port using: * 8 data bits * 1 stop bit * 19200 bps * no parity */ int openPort(char *device) { struct termios options; int fd; fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { perror("open_port: Unable to open device"); return(-1); } fcntl(fd, F_SETFL, 0); tcgetattr(fd, &options); cfsetispeed(&options, B19200); cfsetospeed(&options, B19200); /* set raw mode, 1 second timeout */ options.c_cflag &= ~(CSIZE | CSTOPB | PARENB); options.c_cflag |= CLOCAL | CREAD | CS8; options.c_lflag &= ~(ICANON | ECHO | ECHOE | IEXTEN | ECHONL | ISIG); options.c_iflag &= ~(IXON | IXOFF | IXANY | IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); options.c_oflag &= ~OPOST; options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 10; tcsetattr(fd, TCSANOW, &options); return (fd); } void closePort(int fd) { close(fd); }