From: <ean...@us...> - 2012-09-09 21:47:51
|
Revision: 10992 http://octave.svn.sourceforge.net/octave/?rev=10992&view=rev Author: eandrius Date: 2012-09-09 21:47:44 +0000 (Sun, 09 Sep 2012) Log Message: ----------- instrument-control: serial, check if interface is open before operating on it Modified Paths: -------------- trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc trunk/octave-forge/main/instrument-control/src/serial/srl_stopbits.cc trunk/octave-forge/main/instrument-control/src/serial/srl_timeout.cc trunk/octave-forge/main/instrument-control/src/serial/srl_write.cc Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_baudrate.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -83,6 +83,12 @@ int octave_serial::set_baudrate(unsigned int baud) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + speed_t baud_rate = 0; switch (baud) @@ -145,6 +151,12 @@ int octave_serial::get_baudrate() { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + int retval = -1; speed_t baudrate = cfgetispeed(&this->config); Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_bytesize.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -80,6 +80,12 @@ int octave_serial::set_bytesize(unsigned short bytesize) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + tcflag_t c_bytesize = 0; switch (bytesize) @@ -110,6 +116,12 @@ int octave_serial::get_bytesize() { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + int retval = -1; if (BITMASK_CHECK(this->config.c_cflag, CS5)) Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_close.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -61,7 +61,14 @@ int octave_serial::close() { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + int retval = ::close(this->get_fd()); this->fd = -1; + return retval; } \ No newline at end of file Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_flush.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -78,6 +78,12 @@ int octave_serial::flush(unsigned short queue_selector) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + /* * TCIOFLUSH Flush both pending input and untransmitted output. * TCOFLUSH Flush untransmitted output. Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_parity.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -80,6 +80,12 @@ int octave_serial::set_parity(string parity) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + // Convert string to lowercase std::transform(parity.begin(), parity.end(), parity.begin(), ::tolower); Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_read.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -34,7 +34,6 @@ #include "serial.h" -// PKG_ADD: autoload ("srl_read", "instrument-control.oct"); DEFUN_DLD (srl_read, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{data}, @var{count}] = } srl_read (@var{serial}, @var{n})\n \ @@ -106,5 +105,11 @@ int octave_serial::read(char *buf, unsigned int len) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + return ::read(get_fd(), buf, len); } \ No newline at end of file Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_stopbits.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_stopbits.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_stopbits.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -33,7 +33,6 @@ #include "serial.h" -// PKG_ADD: autoload ("srl_stopbits", "instrument-control.oct"); DEFUN_DLD (srl_stopbits, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {} srl_stopbits (@var{serial}, @var{stopb})\n \ @@ -78,6 +77,12 @@ int octave_serial::set_stopbits(unsigned short stopbits) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + /* * CSTOPB Send two stop bits, else one. */ @@ -108,6 +113,12 @@ int octave_serial::get_stopbits() { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + if (BITMASK_CHECK(this->config.c_cflag, CSTOPB)) return 2; else Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_timeout.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_timeout.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_timeout.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -33,7 +33,6 @@ #include "serial.h" -// PKG_ADD: autoload ("srl_timeout", "instrument-control.oct"); DEFUN_DLD (srl_timeout, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {} srl_timeout (@var{serial}, @var{timeout})\n \ @@ -78,6 +77,12 @@ int octave_serial::set_timeout(short timeout) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + if (timeout < 0 || timeout > 255) { error("srl_timeout: timeout value must be between [0..255]..."); Modified: trunk/octave-forge/main/instrument-control/src/serial/srl_write.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/serial/srl_write.cc 2012-09-09 20:59:15 UTC (rev 10991) +++ trunk/octave-forge/main/instrument-control/src/serial/srl_write.cc 2012-09-09 21:47:44 UTC (rev 10992) @@ -33,7 +33,6 @@ #include "serial.h" -// PKG_ADD: autoload ("srl_write", "instrument-control.oct"); DEFUN_DLD (srl_write, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{n} = } srl_write (@var{serial}, @var{data})\n \ @@ -86,10 +85,22 @@ int octave_serial::write(string str) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + return ::write(get_fd(), str.c_str(), str.length()); } int octave_serial::write(unsigned char *buf, int len) { + if (this->get_fd() < 0) + { + error("serial: Interface must be opened first..."); + return -1; + } + return ::write(get_fd(), buf, len); } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |