1118
1119 /* Open the device file. */
1120 serial_fd = open (serial_device,
1121 O_RDWR | O_NOCTTY
1122 #if defined(O_SYNC)
1123 /* O_SYNC is used in Linux (and some others?). */
1124 | O_SYNC
1125 #elif defined(O_FSYNC)
1126 /* O_FSYNC is used in FreeBSD. */
1127 | O_FSYNC
1128 #endif
1129 );
1130 if (serial_fd < 0)
1131 return 0;
1132
1133 /* Get the termios parameters. */
1134 if (tcgetattr (serial_fd, &termios))
1135 goto fail;
1136
1137 /* Raw mode. */
1138 #if defined(__sun)
1139 termios.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
1140 termios.c_oflag &= ~OPOST;
1141 termios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
1142 termios.c_cflag &= ~(CSIZE|PARENB);
1143 termios.c_cflag |= CS8;
1144 #else
1145 cfmakeraw (&termios);
1146 #endif
1147
1148 /* Set the speed. */
1149 termios_speed = get_termios_speed (speed);
1150 if (termios_speed == B0)
1151 goto fail;
1152
1153 cfsetispeed (&termios, termios_speed);
1154 cfsetospeed (&termios, termios_speed);
1155
1156 /* Set the word length. */
1157 termios.c_cflag &= ~CSIZE;
1158 switch (word_len)
1159 {
1160 case UART_5BITS_WORD:
1161 termios.c_cflag |= CS5;
1162 break;
1163 case UART_6BITS_WORD:
1164 termios.c_cflag |= CS6;
1165 break;
1166 case UART_7BITS_WORD:
|
1118
1119 /* Open the device file. */
1120 serial_fd = open (serial_device,
1121 O_RDWR | O_NOCTTY
1122 #if defined(O_SYNC)
1123 /* O_SYNC is used in Linux (and some others?). */
1124 | O_SYNC
1125 #elif defined(O_FSYNC)
1126 /* O_FSYNC is used in FreeBSD. */
1127 | O_FSYNC
1128 #endif
1129 );
1130 if (serial_fd < 0)
1131 return 0;
1132
1133 /* Get the termios parameters. */
1134 if (tcgetattr (serial_fd, &termios))
1135 goto fail;
1136
1137 /* Raw mode. */
1138 cfmakeraw (&termios);
1139
1140 /* Set the speed. */
1141 termios_speed = get_termios_speed (speed);
1142 if (termios_speed == B0)
1143 goto fail;
1144
1145 cfsetispeed (&termios, termios_speed);
1146 cfsetospeed (&termios, termios_speed);
1147
1148 /* Set the word length. */
1149 termios.c_cflag &= ~CSIZE;
1150 switch (word_len)
1151 {
1152 case UART_5BITS_WORD:
1153 termios.c_cflag |= CS5;
1154 break;
1155 case UART_6BITS_WORD:
1156 termios.c_cflag |= CS6;
1157 break;
1158 case UART_7BITS_WORD:
|