diff options
author | Konrad M. Kruczynski <konrad.kruczynski@gmail.com> | 2011-05-01 16:20:54 +0400 |
---|---|---|
committer | Konrad M. Kruczynski <konrad.kruczynski@gmail.com> | 2011-05-01 16:20:54 +0400 |
commit | 718b24e6aeafd97907b6308b0e05bf525adad56b (patch) | |
tree | f7766f6de1968f166dfa84cc201bf5626a10b0cd /support | |
parent | 5d57a9d85e2d57a8ea7e29a55fc83ad6e3fe5549 (diff) |
Added exception in case of using nonstandard baud rate on POSIX boxes, which is not supported by termios. OutOfRange rather than NotSupported exception due to interface compatibility.
Diffstat (limited to 'support')
-rw-r--r-- | support/serial.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/support/serial.c b/support/serial.c index a6ad9551792..6a1705fccca 100644 --- a/support/serial.c +++ b/support/serial.c @@ -148,19 +148,14 @@ get_bytes_in_buffer (int fd, gboolean input) } gboolean -set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake) +is_baud_rate_legal (int baud_rate) { - struct termios newtio; - - if (tcgetattr (fd, &newtio) == -1) - return FALSE; - - newtio.c_cflag |= (CLOCAL | CREAD); - newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN ); - newtio.c_oflag &= ~(OPOST); - newtio.c_iflag = IGNBRK; + return setup_baud_rate (baud_rate) != -1; +} - /* setup baudrate */ +int +setup_baud_rate (int baud_rate) +{ switch (baud_rate) { /*Some values are not defined on OSX and *BSD */ @@ -228,9 +223,27 @@ set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStop case 50: case 0: default: - baud_rate = B9600; + baud_rate = -1; break; } + return baud_rate; +} + +gboolean +set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake) +{ + struct termios newtio; + + if (tcgetattr (fd, &newtio) == -1) + return FALSE; + + newtio.c_cflag |= (CLOCAL | CREAD); + newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN ); + newtio.c_oflag &= ~(OPOST); + newtio.c_iflag = IGNBRK; + + /* setup baudrate */ + baud_rate = setup_baud_rate (baud_rate); /* char lenght */ newtio.c_cflag &= ~CSIZE; |