From: <ean...@us...> - 2012-09-09 20:59:22
|
Revision: 10991 http://octave.svn.sourceforge.net/octave/?rev=10991&view=rev Author: eandrius Date: 2012-09-09 20:59:15 +0000 (Sun, 09 Sep 2012) Log Message: ----------- instrument-control: i2c, check if interface is opened before operating on it Modified Paths: -------------- trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc Modified: trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc 2012-09-09 20:56:23 UTC (rev 10990) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_addr.cc 2012-09-09 20:59:15 UTC (rev 10991) @@ -61,6 +61,11 @@ int octave_i2c::set_addr(int addr) { + if (this->get_fd() < 0) + { + error("i2c: Interface must be open first..."); + return -1; + } if (::ioctl(this->get_fd(), I2C_SLAVE, addr) < 0) { @@ -73,5 +78,11 @@ int octave_i2c::get_addr() { + if (this->get_fd() < 0) + { + error("i2c: Interface must be open first..."); + return -1; + } + return this->addr; } \ No newline at end of file Modified: trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc 2012-09-09 20:56:23 UTC (rev 10990) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_close.cc 2012-09-09 20:59:15 UTC (rev 10991) @@ -45,6 +45,12 @@ int octave_i2c::close() { + if (this->get_fd() < 0) + { + error("i2c: Interface must be open first..."); + return -1; + } + int retval = ::close(this->get_fd()); this->fd = -1; Modified: trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc 2012-09-09 20:56:23 UTC (rev 10990) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_read.cc 2012-09-09 20:59:15 UTC (rev 10991) @@ -80,6 +80,12 @@ int octave_i2c::read(char *buf, unsigned int len) { + if (this->get_fd() < 0) + { + error("i2c: Interface must be open first..."); + return -1; + } + int retval = ::read(this->get_fd(), buf, len); if (retval != len) Modified: trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc =================================================================== --- trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc 2012-09-09 20:56:23 UTC (rev 10990) +++ trunk/octave-forge/main/instrument-control/src/i2c/i2c_write.cc 2012-09-09 20:59:15 UTC (rev 10991) @@ -72,6 +72,12 @@ int octave_i2c::write(unsigned char *buf, int len) { + if (this->get_fd() < 0) + { + error("i2c: Interface must be open first..."); + return -1; + } + int retval = ::write(this->get_fd(), buf, len); if (retval < 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |