Browse Source

lowl-vcom: vcom_set_timeout_ms function (increases precision to ms on Windows only)

Luke Dashjr 11 years ago
parent
commit
33265a54bf
2 changed files with 6 additions and 5 deletions
  1. 4 4
      lowl-vcom.c
  2. 2 1
      lowl-vcom.h

+ 4 - 4
lowl-vcom.c

@@ -1,5 +1,5 @@
 /*
- * Copyright 2012-2014 Luke Dashjr
+ * Copyright 2012-2015 Luke Dashjr
  * Copyright 2013 Con Kolivas
  * Copyright 2012 Andrew Smith
  * Copyright 2013 Xiangfu
@@ -1056,19 +1056,19 @@ bool valid_baud(int baud)
 	}
 }
 
-bool vcom_set_timeout(const int fdDev, const uint8_t timeout)
+bool vcom_set_timeout_ms(const int fdDev, const unsigned timeout_ms)
 {
 #ifdef WIN32
 	const HANDLE hSerial = (HANDLE)_get_osfhandle(fdDev);
 	// Code must specify a valid timeout value (0 means don't timeout)
-	const DWORD ctoms = ((DWORD)timeout * 100);
+	const DWORD ctoms = timeout_ms;
 	COMMTIMEOUTS cto = {ctoms, 0, ctoms, 0, ctoms};
 	return (SetCommTimeouts(hSerial, &cto) != 0);
 #else
 	struct termios my_termios;
 	
 	tcgetattr(fdDev, &my_termios);
-	my_termios.c_cc[VTIME] = (cc_t)timeout;
+	my_termios.c_cc[VTIME] = (cc_t)(timeout_ms + 99) / 100;
 	return (tcsetattr(fdDev, TCSANOW, &my_termios) == 0);
 #endif
 }

+ 2 - 1
lowl-vcom.h

@@ -39,7 +39,8 @@ extern ssize_t _serial_read(int fd, char *buf, size_t buflen, char *eol);
 	_serial_read(fd, buf, bufsiz, &eol)
 extern int serial_close(int fd);
 
-extern bool vcom_set_timeout(int fd, uint8_t timeout);
+extern bool vcom_set_timeout_ms(int fd, unsigned timeout_ms);
+#define vcom_set_timeout(fd, timeout)  vcom_set_timeout_ms(fd, (timeout) * 100)
 extern enum bfg_gpio_value get_serial_cts(int fd);
 extern enum bfg_gpio_value set_serial_dtr(int fd, enum bfg_gpio_value dtr);
 extern enum bfg_gpio_value set_serial_rts(int fd, enum bfg_gpio_value rts);