# HG changeset patch
# User Stefan Mahr <dac922@gmx.de>
# Date 1430230935 -7200
#      Tue Apr 28 16:22:15 2015 +0200
# Node ID a3ef948c5ec56b6e6debc347c1fa36a9d6b675b5
# Parent  81a1988f55fc097d791a69821c4810c817b0f567
Change display of serial class object from scalar to text.

* src/serial/serial_class.h: Add new octave_serial_common class, that
  is used as parent by os dependent classes. Display serial class object
  properties instead of printing scalar value of file descriptor. Add
  binary operators equal and not_equal to be able to compare serial
  class objects. Add portPath property to save actual used port.
* src/serial/serial_class_lin.cc, src/serial/serial_class_win32.cc:
  Remove print functions. Set portPath property on open. Get rid of
  get_fd function. Use new fd_is_valid function to check for valid file
  descriptor.
* src/serial/serial_class_lin.h, src/serial/serial_class_win32.h: Use
  new octave_serial_common class as parent. New fd_is_valid function.
  Remove get_fd function. Move print functions to serial_class.h.
* src/serial/serial.cc: Install binary operators on first load.

diff -r 81a1988f55fc -r a3ef948c5ec5 src/serial/serial.cc
--- a/src/serial/serial.cc	Tue Apr 07 13:17:45 2015 +0200
+++ b/src/serial/serial.cc	Tue Apr 28 16:22:15 2015 +0200
@@ -29,6 +29,13 @@
 #include "serial_class.h"
 
 static bool type_loaded = false;
+
+void
+install_serial_ops (void)
+{
+  INSTALL_BINOP (op_eq, octave_serial, octave_serial, eq_serial_serial);
+  INSTALL_BINOP (op_ne, octave_serial, octave_serial, ne_serial_serial);
+}
 #endif
 
 DEFUN_DLD (serial, args, nargout, 
@@ -51,6 +58,7 @@
     if (!type_loaded)
     {
         octave_serial::register_type();
+        install_serial_ops ();
         type_loaded = true;
     }
 
@@ -116,8 +124,7 @@
     octave_serial* retval = new octave_serial();
 
     // Open the interface
-    if (retval->open(path) < 0)
-        return octave_value();
+    retval->open(path);
 
     retval->set_baudrate(baud_rate);
     retval->set_timeout(timeout);
diff -r 81a1988f55fc -r a3ef948c5ec5 src/serial/serial_class.h
--- a/src/serial/serial_class.h	Tue Apr 07 13:17:45 2015 +0200
+++ b/src/serial/serial_class.h	Tue Apr 28 16:22:15 2015 +0200
@@ -16,10 +16,88 @@
 #ifndef SERIAL_CLASS_H
 #define SERIAL_CLASS_H
 
+#include <octave/oct.h>
+#include <octave/ops.h>
+
+#include <string>
+
+#define BITMASK_SET(x,y) ((x) |= (y))
+#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))
+#define BITMASK_TOGGLE(x,y) ((x) ^= (y))
+#define BITMASK_CHECK(x,y) ((x) & (y))
+
+#define DEFBINOP_CLASS_OP(name, t1, t2, op) \
+  BINOPDECL (name, a1, a2) \
+  { \
+    CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
+    return octave_value \
+      (&v1 op &v2); \
+  }
+
+class octave_serial_common : public octave_base_value
+{
+public:
+
+  // 
+  bool fd_is_valid() const { return false; }
+  int get_timeout() const { return 0; }
+  int get_baudrate() const { return 0; }
+  int get_bytesize() const { return 0; }
+  std::string get_parity() const { return "N/A"; }
+  int get_stopbits() const { return 0; }
+
+  // Properties
+  bool is_constant (void) const { return true;}
+  bool is_defined (void) const { return true;}
+  bool is_object (void) const { return true;}
+
+  void print (std::ostream& os, bool pr_as_read_syntax = false)
+  {
+    print_raw(os, pr_as_read_syntax);
+    newline(os);
+  }
+
+  void print (std::ostream& os, bool pr_as_read_syntax = false) const
+  {
+    print_raw(os, pr_as_read_syntax);
+    newline(os);
+  }
+
+  void print_raw (std::ostream& os, bool pr_as_read_syntax) const
+  {
+    os << "isOpen:   " << this->fd_is_valid(); newline(os);
+    os << "Port:     " << this->portPath; newline(os);
+    os << "Baudrate: " << this->get_baudrate(); newline(os);
+    os << "Parity:   " << this->get_parity(); newline(os);
+    os << "Bytesize: " << this->get_bytesize(); newline(os);
+    os << "stopbits: " << this->get_stopbits(); newline(os);
+    os << "Timeout:  " << this->get_timeout(); newline(os);
+    //os << "Mode:     " << blockmode; newline(os);
+  }
+
+  bool operator==(octave_serial_common& other) const
+  {
+    return (this == &other);
+  }
+
+  bool operator!=(octave_serial_common& other) const
+  {
+    return ! (this == &other);
+  }
+
+protected:
+  std::string portPath;
+
+};
+
+
 #ifdef __WIN32__
  #include "serial_class_win32.h"
 #else
  #include "serial_class_lin.h"
 #endif
 
+DEFBINOP_CLASS_OP (eq_serial_serial, serial, serial, ==)
+DEFBINOP_CLASS_OP (ne_serial_serial, serial, serial, !=)
+
 #endif
diff -r 81a1988f55fc -r a3ef948c5ec5 src/serial/serial_class_lin.cc
--- a/src/serial/serial_class_lin.cc	Tue Apr 07 13:17:45 2015 +0200
+++ b/src/serial/serial_class_lin.cc	Tue Apr 28 16:22:15 2015 +0200
@@ -50,7 +50,7 @@
     this->fd = -1;
 }
 
-int octave_serial::open(string path)
+void octave_serial::open(string path)
 {
     int flags = O_RDWR | O_NOCTTY | O_SYNC | O_NDELAY;
     // O_SYNC - All writes immediately effective, no buffering
@@ -58,22 +58,23 @@
     // O_NDELAY - Do not care what state the DCD signal line is in. Used for open only, later disabled.
 
     this->fd = ::open(path.c_str(), flags);
+    this->portPath = path;
 
-    if (this->get_fd() > 0)
+    if (this->fd_is_valid())
     {
         // Check whether fd is an open file descriptor referring to a terminal
         if(!isatty(fd))
         {
             error("serial: Interface does not refer to a terminal: %s\n", strerror(errno));
             this->close();
-            return -1;
+            return;
         }
 
         if (tcgetattr(this->fd, &this->config) < 0)
         {
             error("serial: Failed to get terminal attributes: %s\n", strerror(errno));
             this->close();
-            return -1;
+            return;
         }
 
         // Clear all settings
@@ -83,19 +84,19 @@
         this->config.c_lflag = 0; // Local modes
         this->config.c_cc[VMIN] = 1;
 
-        if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0)
+        if (tcsetattr(this->fd, TCSANOW, &this->config) < 0)
         {
             error("serial: Failed to set default terminal attributes: %s\n", strerror(errno));
             this->close();
-            return -1;
+            return;
         }
 
         // Disable NDELAY
-        if (fcntl(this->get_fd(), F_SETFL, 0) < 0)
+        if (fcntl(this->fd, F_SETFL, 0) < 0)
         {
             error("serial: Failed to disable NDELAY flag: %s\n", strerror(errno));
             this->close();
-            return -1;
+            return;
         }
 
         this->blocking_read = true;
@@ -103,10 +104,8 @@
     else
     {
         error("serial: Error opening the interface: %s\n", strerror(errno));
-        return -1;
+        return;
     }
-
-    return this->get_fd();
 }
 
 octave_serial::~octave_serial()
@@ -114,26 +113,9 @@
     this->close();
 }
 
-void octave_serial::print (std::ostream& os, bool pr_as_read_syntax )
-{
-    print_raw(os, pr_as_read_syntax);
-    newline(os);
-}
-
-void octave_serial::print (std::ostream& os, bool pr_as_read_syntax ) const
-{
-    print_raw(os, pr_as_read_syntax);
-    newline(os);
-}
-
-void octave_serial::print_raw (std::ostream& os, bool pr_as_read_syntax) const
-{
-    os << this->fd;
-}
-
 int octave_serial::read(uint8_t *buf, unsigned int len)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("srl_read: Interface must be opened first...");
         return 0;
@@ -145,7 +127,7 @@
     // While not interrupted in blocking mode
     while (!read_interrupt)
     {
-        read_retval = ::read(this->get_fd(), (void *)(buf + bytes_read), len - bytes_read);
+        read_retval = ::read(this->fd, (void *)(buf + bytes_read), len - bytes_read);
         //printf("read_retval: %d\n\r", read_retval);
 
         if (read_retval < 0)
@@ -170,29 +152,29 @@
 
 int octave_serial::write(string str)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
     }
 
-    return ::write(get_fd(), str.c_str(), str.length());
+    return ::write(this->fd, str.c_str(), str.length());
 }
 
 int octave_serial::write(uint8_t *buf, unsigned int len)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
     }
 
-    return ::write(get_fd(), buf, len);
+    return ::write(this->fd, buf, len);
 }
 
 int octave_serial::set_timeout(short timeout)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -220,7 +202,7 @@
     this->config.c_cc[VMIN] = 0;
     this->config.c_cc[VTIME] = (unsigned) timeout; // Set timeout of 'timeout * 10' seconds
 
-    if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) {
+    if (tcsetattr(this->fd, TCSANOW, &this->config) < 0) {
         error("srl_timeout: error setting timeout...");
         return -1;
     }
@@ -228,7 +210,7 @@
     return 1;
 }
 
-int octave_serial::get_timeout()
+int octave_serial::get_timeout() const
 {
     if (blocking_read)
         return -1;
@@ -238,7 +220,7 @@
 
 int octave_serial::set_stopbits(unsigned short stopbits)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -264,7 +246,7 @@
         return false;
     }
 
-    if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) {
+    if (tcsetattr(this->fd, TCSANOW, &this->config) < 0) {
         error("srl_stopbits: error setting stop bits: %s\n", strerror(errno));
         return false;
     }
@@ -272,9 +254,9 @@
     return true;
 }
 
-int octave_serial::get_stopbits()
+int octave_serial::get_stopbits() const
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -288,7 +270,7 @@
 
 int octave_serial::set_bytesize(unsigned short bytesize)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -314,7 +296,7 @@
     // Apply new
     BITMASK_SET(this->config.c_cflag, c_bytesize);
 
-    if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) {
+    if (tcsetattr(this->fd, TCSANOW, &this->config) < 0) {
         error("srl_bytesize: error setting byte size: %s\n", strerror(errno));
         return false;
     }
@@ -322,9 +304,9 @@
     return true;
 }
 
-int octave_serial::get_bytesize()
+int octave_serial::get_bytesize() const
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -346,7 +328,7 @@
 
 int octave_serial::set_baudrate(unsigned int baud)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -404,7 +386,7 @@
     cfsetispeed(&this->config, baud_rate);
     cfsetospeed(&this->config, baud_rate);
 
-    if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) {
+    if (tcsetattr(this->fd, TCSANOW, &this->config) < 0) {
         error("srl_baudrate: error setting baud rate: %s\n", strerror(errno));
         return false;
     }
@@ -412,9 +394,9 @@
     return true;
 }
 
-int octave_serial::get_baudrate()
+int octave_serial::get_baudrate() const
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -469,7 +451,7 @@
 
 int octave_serial::flush(unsigned short queue_selector)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -493,13 +475,13 @@
         return false;
     }
 
-    return ::tcflush(this->get_fd(), flag);
+    return ::tcflush(this->fd, flag);
 }
 
 
 int octave_serial::set_parity(string parity)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -542,7 +524,7 @@
         return false;
     }
 
-    if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) {
+    if (tcsetattr(this->fd, TCSANOW, &this->config) < 0) {
         error("srl_parity: error setting parity: %s\n", strerror(errno));
         return false;
     }
@@ -550,7 +532,7 @@
     return true;
 }
 
-string octave_serial::get_parity()
+string octave_serial::get_parity() const
 {
     if (!BITMASK_CHECK(this->config.c_cflag, PARENB))
         return "None";
@@ -562,12 +544,12 @@
 
 void octave_serial::get_control_line_status(void)
 {
-  if (this->get_fd() < 0)
+  if (!this->fd_is_valid())
     {
       error("serial: Interface must be opened first...");
       return;
     }
-  ioctl(this->get_fd(), TIOCMGET, &this->status);
+  ioctl(this->fd, TIOCMGET, &this->status);
 }
 
 bool octave_serial::get_control_line(string control_signal)
@@ -614,25 +596,21 @@
   else
     this->status &= ~signal;
 
-  ioctl(this->get_fd(), TIOCMSET, &this->status);
+  ioctl(this->fd, TIOCMSET, &this->status);
 
 }
 
-int octave_serial::get_fd()
+bool octave_serial::fd_is_valid() const
 {
-    return this->fd;
+  return (this->fd >= 0);
 }
 
-int octave_serial::close()
+void octave_serial::close()
 {
-    int retval = -1;
-
-    if (this->get_fd() > 0)
+  if (this->fd_is_valid())
     {
-        retval = ::close(this->get_fd());
-        this->fd = -1;
+      ::close(this->fd);
+      this->fd = -1;
     }
-
-    return retval;
 }
 #endif
diff -r 81a1988f55fc -r a3ef948c5ec5 src/serial/serial_class_lin.h
--- a/src/serial/serial_class_lin.h	Tue Apr 07 13:17:45 2015 +0200
+++ b/src/serial/serial_class_lin.h	Tue Apr 28 16:22:15 2015 +0200
@@ -16,20 +16,12 @@
 #ifndef SERIAL_CLASS_LIN_H
 #define SERIAL_CLASS_LIN_H
 
-#include <octave/oct.h>
-#include <octave/ov-int32.h>
-
 #include <string>
 #include <termios.h>
 
 using std::string;
 
-#define BITMASK_SET(x,y) ((x) |= (y))
-#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))
-#define BITMASK_TOGGLE(x,y) ((x) ^= (y))
-#define BITMASK_CHECK(x,y) ((x) & (y))
-
-class octave_serial : public octave_base_value
+class octave_serial : public octave_serial_common
 {
 public:
     octave_serial();
@@ -40,48 +32,29 @@
 
     int read(uint8_t* /* buffer */, unsigned int /* buffer size */);
 
-    int open(string /* path */);
-    int close();
-    int get_fd();
+    void open(string /* path */);
+    void close();
 
     int flush(unsigned short /* stream select */);
 
     int set_timeout(short /* timeout */);
-    int get_timeout();
+    int get_timeout() const;
 
     int set_baudrate(unsigned int /* baudrate */);
-    int get_baudrate();
+    int get_baudrate() const;
 
     int set_bytesize(unsigned short /* bytesize */);
-    int get_bytesize();
+    int get_bytesize() const;
 
     int set_parity(string /* parity */);
-    string get_parity();
+    string get_parity() const;
 
     int set_stopbits(unsigned short /* stop bits */);
-    int get_stopbits();
+    int get_stopbits() const;
 
     bool get_control_line(string);
     void set_control_line(string, bool);
 
-    // Overloaded base functions
-    double serial_value() const { return (double)this->fd; }
-
-    virtual double scalar_value (bool frc_str_conv = false) const
-    {
-        return (double)this->fd;
-    }
-
-    void print (std::ostream& os, bool pr_as_read_syntax = false);
-    void print (std::ostream& os, bool pr_as_read_syntax = false) const;
-    void print_raw (std::ostream& os, bool pr_as_read_syntax) const;
-
-    // Properties
-    bool is_constant (void) const { return true;}
-    bool is_defined (void) const { return true;}
-    bool print_as_scalar (void) const { return true;}
-
-
 private:
     int fd;
     int status;
@@ -91,6 +64,8 @@
 
     void get_control_line_status(void);
 
+    bool fd_is_valid() const;
+
     DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
 };
 
diff -r 81a1988f55fc -r a3ef948c5ec5 src/serial/serial_class_win32.cc
--- a/src/serial/serial_class_win32.cc	Tue Apr 07 13:17:45 2015 +0200
+++ b/src/serial/serial_class_win32.cc	Tue Apr 28 16:22:15 2015 +0200
@@ -56,14 +56,15 @@
     this->fd = INVALID_HANDLE_VALUE;
 }
 
-int octave_serial::open(string path)
+void octave_serial::open(string path)
 {
    this->fd = CreateFile(path.c_str(), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+   this->portPath = path;
 
-   if (this->fd == INVALID_HANDLE_VALUE)
+   if (!this->fd_is_valid())
    {
        error("serial: Error opening the interface: %s\n", winerror(errno));
-       return -1;
+       return;
    }
 
    // clear any errors that may be on the port
@@ -77,7 +78,7 @@
    {
        error("serial: Failed to get terminal attributes: %s\n", winerror(errno));
        this->close();
-       return -1;
+       return;
    }
 
    this->timeouts.ReadIntervalTimeout = MAXDWORD;
@@ -90,10 +91,10 @@
    {
        error("serial: Failed to disable timeouts: %s\n", winerror(errno));
        this->close();
-       return -1;
+       return;
    }
 
-   return this->get_fd();
+   return;
 }
 
 octave_serial::~octave_serial()
@@ -101,26 +102,9 @@
     this->close();
 }
 
-void octave_serial::print (std::ostream& os, bool pr_as_read_syntax )
-{
-    print_raw(os, pr_as_read_syntax);
-    newline(os);
-}
-
-void octave_serial::print (std::ostream& os, bool pr_as_read_syntax ) const
-{
-    print_raw(os, pr_as_read_syntax);
-    newline(os);
-}
-
-void octave_serial::print_raw (std::ostream& os, bool pr_as_read_syntax) const
-{
-    os << this->fd;
-}
-
 int octave_serial::read(uint8_t *buf, unsigned int len)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("srl_read: Interface must be opened first...");
         return 0;
@@ -161,7 +145,7 @@
 
 int octave_serial::write(string str)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -177,7 +161,7 @@
 
 int octave_serial::write(uint8_t *buf, unsigned int len)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -193,7 +177,7 @@
 
 int octave_serial::set_timeout(short timeout)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -232,7 +216,7 @@
     return 1;
 }
 
-int octave_serial::get_timeout()
+int octave_serial::get_timeout() const
 {
     if (blocking_read)
         return -1;
@@ -242,7 +226,7 @@
 
 int octave_serial::set_stopbits(unsigned short stopbits)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -273,9 +257,9 @@
     return true;
 }
 
-int octave_serial::get_stopbits()
+int octave_serial::get_stopbits() const
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -288,7 +272,7 @@
 
 int octave_serial::set_bytesize(unsigned short bytesize)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -310,9 +294,9 @@
     return true;
 }
 
-int octave_serial::get_bytesize()
+int octave_serial::get_bytesize() const
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -323,7 +307,7 @@
 
 int octave_serial::set_baudrate(unsigned int baud)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -388,9 +372,9 @@
     return true;
 }
 
-int octave_serial::get_baudrate()
+int octave_serial::get_baudrate() const
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -401,7 +385,7 @@
 
 int octave_serial::flush(unsigned short queue_selector)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -428,7 +412,7 @@
 
 int octave_serial::set_parity(string parity)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
         error("serial: Interface must be opened first...");
         return -1;
@@ -471,7 +455,7 @@
     return true;
 }
 
-string octave_serial::get_parity()
+string octave_serial::get_parity() const
 {
     if(this->config.Parity == NOPARITY)
         return "None";
@@ -483,7 +467,7 @@
 
 void octave_serial::get_control_line_status(void)
 {
-    if (this->get_fd() < 0)
+    if (!this->fd_is_valid())
     {
       error("serial: Interface must be opened first...");
       return;
@@ -545,24 +529,17 @@
     SetCommState(this->fd,&this->config);
 }
 
-int octave_serial::get_fd() const
+bool octave_serial::fd_is_valid() const
 {
-    if(this->fd == INVALID_HANDLE_VALUE) return -1;
-    return (int)this->fd;
+  return (this->fd != INVALID_HANDLE_VALUE);
 }
 
-int octave_serial::close()
+void octave_serial::close()
 {
-    int retval = -1;
-
-    if (this->fd != INVALID_HANDLE_VALUE)
+  if (this->fd_is_valid())
     {
-        if(CloseHandle(this->fd))
-           retval = 0;
-
-        this->fd = INVALID_HANDLE_VALUE;
+      CloseHandle(this->fd);
+      this->fd = INVALID_HANDLE_VALUE;
     }
-
-    return retval;
 }
 #endif
diff -r 81a1988f55fc -r a3ef948c5ec5 src/serial/serial_class_win32.h
--- a/src/serial/serial_class_win32.h	Tue Apr 07 13:17:45 2015 +0200
+++ b/src/serial/serial_class_win32.h	Tue Apr 28 16:22:15 2015 +0200
@@ -16,16 +16,12 @@
 #ifndef SERIAL_CLASS_WIN32_H
 #define SERIAL_CLASS_WIN32_H
 
-#include <octave/oct.h>
-#include <octave/ov-int32.h>
-
 #include <windows.h>
-
 #include <string>
 
 using std::string;
 
-class octave_serial : public octave_base_value
+class octave_serial : public octave_serial_common
 {
 public:
     octave_serial();
@@ -36,48 +32,29 @@
 
     int read(uint8_t* /* buffer */, unsigned int /* buffer size */);
 
-    int open(string /* path */);
-    int close();
-    int get_fd() const;
+    void open(string /* path */);
+    void close();
 
     int flush(unsigned short /* stream select */);
 
     int set_timeout(short /* timeout */);
-    int get_timeout();
+    int get_timeout() const;
 
     int set_baudrate(unsigned int /* baudrate */);
-    int get_baudrate();
+    int get_baudrate() const;
 
     int set_bytesize(unsigned short /* bytesize */);
-    int get_bytesize();
+    int get_bytesize() const;
 
     int set_parity(string /* parity */);
-    string get_parity();
+    string get_parity() const;
 
     int set_stopbits(unsigned short /* stop bits */);
-    int get_stopbits();
+    int get_stopbits() const;
 
     bool get_control_line(string);
     void set_control_line(string, bool);
 
-    // Overloaded base functions
-    double serial_value() const { return (double)get_fd(); }
-
-    virtual double scalar_value (bool frc_str_conv = false) const
-    {
-        return (double)get_fd();
-    }
-
-    void print (std::ostream& os, bool pr_as_read_syntax = false);
-    void print (std::ostream& os, bool pr_as_read_syntax = false) const;
-    void print_raw (std::ostream& os, bool pr_as_read_syntax) const;
-
-    // Properties
-    bool is_constant (void) const { return true;}
-    bool is_defined (void) const { return true;}
-    bool print_as_scalar (void) const { return true;}
-
-
 private:
     HANDLE fd;
     DWORD status;
@@ -88,6 +65,8 @@
 
     void get_control_line_status(void);
 
+    bool fd_is_valid() const;
+
     DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
 };
 
