Skip to content
Browse files

support for Windows flush_* methods.

  • Loading branch information...
1 parent 6fee97c commit 08ad7f6241ab683164c5be4cf307252c1709c9a9 @MaG21 MaG21 committed Nov 17, 2013
Showing with 34 additions and 58 deletions.
  1. +2 −0 CHANGELOG
  2. +2 −17 ext/native/posix_serialport_impl.c
  3. +2 −23 ext/native/serialport.c
  4. +0 −1 ext/native/serialport.h
  5. +28 −17 ext/native/win_serialport_impl.c
View
2 CHANGELOG
@@ -1,3 +1,5 @@
+1.2.4 => 11/17/2013: [NEW] flush_input() and flush_output() methods [Manuel A. Güílamo (MaG)]
+
1.2.3 => 11/04/2013: [FIXED] Improved documentation (yard)
1.2.2 => 11/03/2013: [FIXED] warning: already initialized constant VERSION
View
19 ext/native/posix_serialport_impl.c
@@ -741,7 +741,7 @@ VALUE self;
ret = tcflush(fd, TCIFLUSH);
if(ret<0) {
- rb_sys_fail("tcflush");
+ return Qfalse;
}
return Qtrue;
@@ -757,27 +757,12 @@ VALUE self;
ret = tcflush(fd, TCOFLUSH);
if(ret<0) {
- rb_sys_fail("tcflush");
+ return Qfalse;
}
return Qtrue;
}
-VALUE sp_flush_all_data_impl(self)
-VALUE self;
-{
- int fd;
- int ret;
-
- fd = get_fd_helper(self);
-
- ret = tcflush(fd, TCIOFLUSH);
- if(ret<0) {
- rb_sys_fail("tcflush");
- }
-
- return Qtrue;
-}
#endif /* !defined(OS_MSWIN) && !defined(OS_BCCWIN) && !defined(OS_MINGW) */
View
25 ext/native/serialport.c
@@ -492,10 +492,7 @@ static VALUE sp_signals(self)
/**
* Flush data received but not read.
*
- * @return [Boolean] true on success otherwise an error occurs. It causes all
- * errors the tcflush(3) system call causes. The caller should care such
- * errors.
- * @note (Windows) flush_input is not available
+ * @return [Boolean] true on success or false if an error occurs.
*/
static VALUE sp_flush_input_data(self)
VALUE self;
@@ -506,31 +503,14 @@ static VALUE sp_flush_input_data(self)
/**
* Flush data written but not transmitted.
*
- * @return [Boolean] true on success otherwise an error occurs. It causes all
- * errors the tcflush(3) system call causes. The caller should care such
- * errors.
- * @note (Windows) flush_output is not available
+ * @return [Boolean] true on success or false if an error occurs.
*/
static VALUE sp_flush_output_data(self)
VALUE self;
{
return sp_flush_output_data_impl(self);
}
-/**
- * Flush both data received but not read and data written but not transmitted.
- *
- * @return [Boolean] true on success otherwise an error occurs. It causes all
- * errors the tcflush(3) system call causes. The caller should care such
- * errors.
- * @note (Windows) flush is not available
- */
-static VALUE sp_flush_all_data(self)
- VALUE self;
-{
- return sp_flush_all_data_impl(self);
-}
-
void Init_serialport()
{
@@ -595,7 +575,6 @@ void Init_serialport()
rb_define_method(cSerialPort, "flush_input", sp_flush_input_data, 0);
rb_define_method(cSerialPort, "flush_output", sp_flush_output_data, 0);
- rb_define_method(cSerialPort, "flush", sp_flush_all_data, 0);
/*
* 0
View
1 ext/native/serialport.h
@@ -96,6 +96,5 @@ VALUE RB_SERIAL_EXPORT sp_get_dtr_impl(VALUE self);
VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(VALUE self);
VALUE RB_SERIAL_EXPORT sp_flush_output_data_impl(VALUE self);
-VALUE RB_SERIAL_EXPORT sp_flush_all_data_impl(VALUE self);
#endif
View
45 ext/native/win_serialport_impl.c
@@ -620,29 +620,40 @@ VALUE RB_SERIAL_EXPORT sp_get_dtr_impl(self)
return self;
}
-VALUE
-sp_flush_input_data_impl(self)
-VALUE self;
+#define PURGE_RXABORT 0x02
+#define PURGE_RXCLEAR 0x08
+VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(self)
+ VALUE self;
{
- rb_noimplement();
- return self;
-}
+ BOOL ret;
+ HANDLE fh;
-VALUE
-sp_flush_output_data_impl(self)
-VALUE self;
-{
- rb_noimplement();
- return self;
+ fh = get_handle_helper(self);
+
+ ret = PurgeComm(fh, (DWORD)(PURGE_RXCLEAR | PURGE_RXABORT));
+ if(!ret) {
+ return Qfalse;
+ }
+ return Qtrue;
}
-VALUE
-sp_flush_all_data_impl(self)
-VALUE self;
+#define PURGE_TXABORT 0x01
+#define PURGE_TXCLEAR 0x04
+VALUE RB_SERIAL_EXPORT sp_flush_output_data_impl(self)
+ VALUE self;
{
- rb_noimplement();
- return self;
+ BOOL ret;
+ HANDLE fh;
+
+ fh = get_handle_helper(self);
+
+ ret = PurgeComm(fh, (DWORD)(PURGE_TXCLEAR | PURGE_TXABORT));
+ if(!ret) {
+ return Qfalse;
+ }
+ return Qtrue;
}
+
#endif /* defined(OS_MSWIN) || defined(OS_BCCWIN) || defined(OS_MINGW) */

0 comments on commit 08ad7f6

Please sign in to comment.
Something went wrong with that request. Please try again.