Mercurial > forge
changeset 11959:67a04ee2da6a octave-forge
instrument-control: moved to a separate mercurial repo
author | carandraug |
---|---|
date | Wed, 24 Jul 2013 19:45:43 +0000 |
parents | 2c699bc8b2c3 |
children | 326f9d3bb6f6 |
files | main/instrument-control/COPYING main/instrument-control/DESCRIPTION main/instrument-control/INDEX main/instrument-control/NEWS main/instrument-control/devel/README main/instrument-control/devel/testtcp.m main/instrument-control/src/Makefile.in main/instrument-control/src/bootstrap main/instrument-control/src/config.h.in main/instrument-control/src/configure.ac main/instrument-control/src/gpib/Makefile.in main/instrument-control/src/gpib/gpib.cc main/instrument-control/src/gpib/gpib_class.cc main/instrument-control/src/gpib/gpib_class.h main/instrument-control/src/gpib/gpib_close.cc main/instrument-control/src/gpib/gpib_read.cc main/instrument-control/src/gpib/gpib_timeout.cc main/instrument-control/src/gpib/gpib_write.cc main/instrument-control/src/i2c/Makefile.in main/instrument-control/src/i2c/i2c.cc main/instrument-control/src/i2c/i2c_addr.cc main/instrument-control/src/i2c/i2c_class.cc main/instrument-control/src/i2c/i2c_class.h main/instrument-control/src/i2c/i2c_close.cc main/instrument-control/src/i2c/i2c_read.cc main/instrument-control/src/i2c/i2c_write.cc main/instrument-control/src/parallel/Makefile.in main/instrument-control/src/parallel/parallel.cc main/instrument-control/src/parallel/parallel_class.cc main/instrument-control/src/parallel/parallel_class.h main/instrument-control/src/parallel/pp_close.cc main/instrument-control/src/parallel/pp_ctrl.cc main/instrument-control/src/parallel/pp_data.cc main/instrument-control/src/parallel/pp_datadir.cc main/instrument-control/src/parallel/pp_stat.cc main/instrument-control/src/serial/Makefile.in main/instrument-control/src/serial/serial.cc main/instrument-control/src/serial/serial_class.cc main/instrument-control/src/serial/serial_class.h main/instrument-control/src/serial/srl_baudrate.cc main/instrument-control/src/serial/srl_bytesize.cc main/instrument-control/src/serial/srl_close.cc main/instrument-control/src/serial/srl_flush.cc main/instrument-control/src/serial/srl_parity.cc main/instrument-control/src/serial/srl_read.cc main/instrument-control/src/serial/srl_stopbits.cc main/instrument-control/src/serial/srl_timeout.cc main/instrument-control/src/serial/srl_write.cc main/instrument-control/src/tcp/Makefile.in main/instrument-control/src/tcp/tcp.cc main/instrument-control/src/tcp/tcp_class.cc main/instrument-control/src/tcp/tcp_class.h main/instrument-control/src/tcp/tcp_close.cc main/instrument-control/src/tcp/tcp_read.cc main/instrument-control/src/tcp/tcp_timeout.cc main/instrument-control/src/tcp/tcp_write.cc main/instrument-control/src/usbtmc/Makefile.in main/instrument-control/src/usbtmc/usbtmc.cc main/instrument-control/src/usbtmc/usbtmc_class.cc main/instrument-control/src/usbtmc/usbtmc_class.h main/instrument-control/src/usbtmc/usbtmc_close.cc main/instrument-control/src/usbtmc/usbtmc_read.cc main/instrument-control/src/usbtmc/usbtmc_write.cc main/instrument-control/src/vxi11/Makefile.in main/instrument-control/src/vxi11/vxi11.cc main/instrument-control/src/vxi11/vxi11.x main/instrument-control/src/vxi11/vxi11_class.cc main/instrument-control/src/vxi11/vxi11_class.h main/instrument-control/src/vxi11/vxi11_close.cc main/instrument-control/src/vxi11/vxi11_read.cc main/instrument-control/src/vxi11/vxi11_write.cc |
diffstat | 71 files changed, 0 insertions(+), 6869 deletions(-) [+] |
line wrap: on
line diff
--- a/main/instrument-control/COPYING Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -src/serial/srl_baudrate.cc GPLv3+ -src/serial/srl_stopbits.cc GPLv3+ -src/serial/srl_read.cc GPLv3+ -src/serial/srl_write.cc GPLv3+ -src/serial/serial.cc GPLv3+ -src/serial/srl_close.cc GPLv3+ -src/serial/serial_class.h GPLv3+ -src/serial/srl_parity.cc GPLv3+ -src/serial/serial_class.cc GPLv3+ -src/serial/srl_timeout.cc GPLv3+ -src/serial/srl_bytesize.cc GPLv3+ -src/serial/srl_flush.cc GPLv3+ -src/gpib/gpib_read.cc GPLv3+ -src/gpib/gpib_close.cc GPLv3+ -src/gpib/gpib.cc GPLv3+ -src/gpib/gpib_timeout.cc GPLv3+ -src/gpib/gpib_write.cc GPLv3+ -src/gpib/gpib_class.h GPLv3+ -src/gpib/gpib_class.cc GPLv3+ -src/tcp/tcp_timeout.cc GPLv3+ -src/tcp/tcp.cc GPLv3+ -src/tcp/tcp_read.cc GPLv3+ -src/tcp/tcp_close.cc GPLv3+ -src/tcp/tcp_write.cc GPLv3+ -src/tcp/tcp_class.h GPLv3+ -src/tcp/tcp_class.cc GPLv3+ -src/parallel/parallel_class.h GPLv3+ -src/parallel/pp_stat.cc GPLv3+ -src/parallel/pp_close.cc GPLv3+ -src/parallel/pp_ctrl.cc GPLv3+ -src/parallel/parallel.cc GPLv3+ -src/parallel/pp_data.cc GPLv3+ -src/parallel/parallel_class.cc GPLv3+ -src/parallel/pp_datadir.cc GPLv3+ -src/vxi11/vxi11_class.cc GPLv3+ -src/vxi11/vxi11.x public domain -src/vxi11/vxi11_class.h GPLv3+ -src/vxi11/vxi11_read.cc GPLv3+ -src/vxi11/vxi11_write.cc GPLv3+ -src/vxi11/vxi11_close.cc GPLv3+ -src/vxi11/vxi11.cc GPLv3+ -src/i2c/i2c_class.h GPLv3+ -src/i2c/i2c_write.cc GPLv3+ -src/i2c/i2c_read.cc GPLv3+ -src/i2c/i2c.cc GPLv3+ -src/i2c/i2c_addr.cc GPLv3+ -src/i2c/i2c_close.cc GPLv3+ -src/i2c/i2c_class.cc GPLv3+ -src/usbtmc/usbtmc_close.cc GPLv3+ -src/usbtmc/usbtmc_class.cc GPLv3+ -src/usbtmc/usbtmc_read.cc GPLv3+ -src/usbtmc/usbtmc.cc GPLv3+ -src/usbtmc/usbtmc_class.h GPLv3+ -src/usbtmc/usbtmc_write.cc GPLv3+
--- a/main/instrument-control/DESCRIPTION Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -Name: instrument-control -Version: 0.2.0 -Date: 2013-04-08 -Author: Andrius Sutas <andrius.sutas@gmail.com>, Stefan Mahr <dac922@gmx.de> -Maintainer: Andrius Sutas <andrius.sutas@gmail.com>, Stefan Mahr <dac922@gmx.de> -Title: Instrument Control Toolbox -Description: Low level I/O functions for serial, i2c, parallel, tcp, gpib, vxi11 and usbtmc interfaces. -Categories: instrument-control -Depends: octave (>= 3.2.0) -Autoload: no -License: GPLv3+
--- a/main/instrument-control/INDEX Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -instrument-control >> Low level I/O functions -Serial - serial - srl_read - srl_write - srl_baudrate - srl_bytesize - srl_flush - srl_parity - srl_stopbits - srl_timeout - srl_close -I2C - i2c - i2c_addr - i2c_read - i2c_write - i2c_close -Parallel - parallel - pp_datadir - pp_data - pp_ctrl - pp_stat - pp_close -TCP - tcp - tcp_read - tcp_write - tcp_timeout - tcp_close -USBTMC - usbtmc - usbtmc_read - usbtmc_write - usbtmc_close -GPIB - gpib - gpib_read - gpib_write - gpib_timeout - gpib_close -VXI11 - vxi11 - vxi11_read - vxi11_write - vxi11_close
--- a/main/instrument-control/NEWS Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -Summary of important user-visible changes for instrument-control 0.2.0: -------------------------------------------------------------------- - - ** Support for TCP interface I/O - - ** Support for USBTMC interface I/O - - ** Support for GPIB interface I/O - - ** Support for VXI11 interface I/O - - ** The following functions are new: - tcp - tcp_read - tcp_write - tcp_timeout - tcp_close - usbtmc - usbtmc_read - usbtmc_write - usbtmc_close - gpib - gpib_read - gpib_write - gpib_timeout - gpib_close - vxi11 - vxi11_read - vxi11_write - vxi11_close - - ** Interfaces are now compiled seperately (i.e. failed compilation of one - interface does not mean fail of whole package) - - ** Parallel and i2c interface support for FreeBSD platform - - ** i2c_write no longer accepts strings for data parameter - - -Summary of important user-visible changes for instrument-control 0.1.0: -------------------------------------------------------------------- - - ** Initial release - - ** Support for Parallel interface I/O - - ** Support for Serial interface I/O - - ** Support for i2c interface I/O - - ** The following functions are new: - serial - srl_close - srl_read - srl_write - srl_baudrate - srl_flush - srl_stopbits - srl_bytesize - srl_parity - srl_timeout - i2c - i2c_addr - i2c_read - i2c_close - i2c_write - parallel - pp_ctrl - pp_stat - pp_close - pp_data - pp_datadir -
--- a/main/instrument-control/devel/README Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -This directory contains functions that have been used to develop, test or debug -some of the instrument control functions in the parent directory. This files are -not needed at runtime for them to work, so they are not installed.
--- a/main/instrument-control/devel/testtcp.m Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -function testtcp - -ip="127.0.0.1"; -port=8000; -echostr="echotest\n"; - -timeout=1000; -tol=0.1; % 10 percent tolerance - -% test error -fd=tcp(ip,port); - -% test connect, write and read -system ("killall socat 2>/dev/null; socat PIPE TCP4-LISTEN:8000 &",0); -sleep(1); - -fd=tcp(ip,port); - -% test read timeout1 -start=tic; -result = tcp_read(fd,10000,1000); -timeout1 = double(tic - start)/1000 -testresult1 = tol > abs(1 - timeout1/timeout); - -% write to socat -tcp_write(fd,echostr); - -% read 4 chars, no timeout -start=tic; -result = tcp_read(fd,4,1000); -timeout2 = double(tic - start)/1000; -testresult2 = timeout2 < timeout; - -% check read result -result = char(result); -testresult3 = strcmp(echostr(1:4),result); - -% close tcp -tcp_close(fd); - -%system ("killall socat"); - - -% -printf("timeout test 1: %d (%f)\n",testresult1,timeout1); -printf("timeout test 2: %d (%f)\n",testresult2,timeout2); -printf("timeout test 3: %d\n",testresult3); -
--- a/main/instrument-control/src/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ - -SUBDIRS = serial parallel i2c usbtmc tcp gpib vxi11 - -MKOCTFILE ?= mkoctfile - -.PHONY: clean -.PHONY: realclean -.PHONY: distclean - -all: - @for dir in $(SUBDIRS); do $(MAKE) -i -C $$dir; done - -clean: - @for dir in $(SUBDIRS); do $(MAKE) -i -C $$dir clean; done - -realclean: - rm -f *.oct - -distclean: realclean - @for dir in $(SUBDIRS); do $(MAKE) -i -C $$dir distclean; done - rm -rf autom4te.cache - rm -f Makefile config.status config.log config.h configure
--- a/main/instrument-control/src/bootstrap Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#!/bin/bash -## Octave-Forge: video package bootstrap script -## Run this to generate the configure script - -set -e # halt if unhandled error -autoconf # generate configure script
--- a/main/instrument-control/src/config.h.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -/* build SERIAL interface functions */ -#undef BUILD_SERIAL - -/* build I2C interface functions */ -#undef BUILD_I2C - -/* build PARALLEL interface functions */ -#undef BUILD_PARALLEL - -/* build GPIB interface functions */ -#undef BUILD_GPIB - -/* build TCP interface functions */ -#undef BUILD_TCP - -/* build USBTMC interface functions */ -#undef BUILD_USBTMC - -/* build VISA interface functions */ -#undef BUILD_VISA - -/* build VXI11 interface functions */ -#undef BUILD_VXI11
--- a/main/instrument-control/src/configure.ac Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -AC_PREREQ([2.67]) -AC_INIT([octave instrument control package], [0.0.0+]) -AC_CONFIG_HEADERS([config.h]) - -# Checks for programs. -AC_PROG_CXX -AC_LANG(C++) - -# Define macros needed -#AC_DEFINE(__STDC_CONSTANT_MACROS, [], [workaround for C++ programs to use C99 macros]) - -AC_CHECK_PROG([HAVE_MKOCTFILE], [mkoctfile], [yes], [no]) -if [test $HAVE_MKOCTFILE = "no"]; then - AC_MSG_ERROR([mkoctfile required to install $PACKAGE_NAME]) -fi - -build_parallel=no -build_serial=no -build_i2c=no -build_usbtmc=no -build_tcp=no -build_gpib=no -build_vxi11=no -build_visa=no - -# check for i2c -# if linux/i2c-dev.h exists we are probably under linux, so build usbtmc as well -AC_CHECK_HEADERS([linux/i2c-dev.h],[build_i2c=yes build_usbtmc=yes]) -AC_CHECK_HEADERS([dev/iicbus/iic.h],[build_i2c=yes]) - -# check for serial -AC_CHECK_HEADERS([termios.h],[build_serial=yes]) - -# check for parallel -AC_CHECK_HEADERS([linux/parport.h linux/ppdev.h],[build_parallel=yes]) -AC_CHECK_HEADERS([dev/ppbus/ppi.h dev/ppbus/ppbconf.h],[build_parallel=yes]) - -# build tcp, available for most platforms -AC_CHECK_HEADERS([sys/socket.h],[build_tcp=yes]) - -# Check for winsock2 and ws2_32 -AC_CHECK_HEADERS([winsock2.h], - [AC_SEARCH_LIBS([_head_libws2_32_a], [ws2_32], - [AC_SUBST(TCPLIBS, ["-lws2_32"]) build_tcp=yes] , [] )] , []) - - -# Checks for GPIB -AC_CHECK_HEADERS([gpib/ib.h], - [AC_SEARCH_LIBS([ibrd], [gpib], [build_gpib=yes], [])] , [] ) - -if test "x$ac_cv_search_ibrd" != "xnone required"; then - AC_SUBST(GPIBLIBS, [$ac_cv_search_ibrd]) -fi - - -# Checks for RPC/VXI11 -AC_ARG_WITH([tirpcinclude], - [AC_HELP_STRING([--with-tirpcinclude=DIR], - [use TI-RPC headers in DIR])], - [tirpc_header_dir=$withval], - [tirpc_header_dir=/usr/include/tirpc]) - -AC_CHECK_PROG([HAVE_RPCGEN], [rpcgen], [yes], [no]) -if test "x$HAVE_RPCGEN" = "xyes"; then - AC_SEARCH_LIBS([clnt_create], [tirpc], [build_vxi11=yes]) - AC_CHECK_HEADERS([rpc/rpc.h],[], - [AC_CHECK_HEADERS([${tirpc_header_dir}/netconfig.h], - [AC_SUBST([RPCINCLUDE], ["-I${tirpc_header_dir}"])],[build_vxi11=no])]) - - if test "x$ac_cv_search_clnt_create" != "xnone required"; then - AC_SUBST(RPCLIBS, [$ac_cv_search_clnt_create]) - fi - -fi - - -# Checks for openvisa -AC_CHECK_HEADERS([visa/visa.h], - [AC_SEARCH_LIBS([viOpenDefaultRM], [openvisa], [build_vxi11=yes], [])] , [] ) - -if test "x$ac_cv_search_viOpenDefaultRM" != "xnone required"; then - AC_SUBST(VISALIBS, [$ac_cv_search_viOpenDefaultRM]) -fi - - -# - -if test $build_parallel = yes; then - AC_DEFINE([BUILD_PARALLEL], [], [build PARALLEL interface functions]) -fi - -if test $build_serial = yes; then - AC_DEFINE([BUILD_SERIAL], [], [build SERIAL interface functions]) -fi - -if test $build_i2c = yes; then - AC_DEFINE([BUILD_I2C], [], [build I2C interface functions]) -fi - -if test $build_usbtmc = yes; then - AC_DEFINE([BUILD_USBTMC], [], [build USBTMC interface functions]) -fi - -if test $build_tcp = yes; then - AC_DEFINE([BUILD_TCP], [], [build TCP interface functions]) -fi - -if test $build_gpib = yes; then - AC_DEFINE([BUILD_GPIB], [], [build GPIB interface functions]) -fi - -if test $build_vxi11 = yes; then - AC_DEFINE([BUILD_VXI11], [], [build VXI11 interface functions]) - AC_SUBST([BUILD_VXI11], [1], [build VXI11 interface functions]) -fi - -if test $build_visa = yes; then - AC_DEFINE([BUILD_VISA], [], [build VISA interface functions]) -fi - - -# all done - -AC_CONFIG_FILES([Makefile gpib/Makefile tcp/Makefile vxi11/Makefile usbtmc/Makefile serial/Makefile parallel/Makefile i2c/Makefile]) -AC_OUTPUT - -AC_MSG_NOTICE([ - -$PACKAGE_NAME is now configured with - - BUILD SERIAL: $build_serial - BUILD PARALLEL: $build_parallel - BUILD I2C: $build_i2c - BUILD TCP: $build_tcp - BUILD USBTMC: $build_usbtmc - BUILD GPIB: $build_gpib - BUILD VXI11: $build_vxi11 - - GPIB LIBS: $GPIBLIBS - VXI11 LIBS: $RPCLIBS - VXI11 INCLUDE: $RPCINCLUDE - VISA LIBS: $VISALIBS - -])
--- a/main/instrument-control/src/gpib/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -OCT := gpib.oct gpib_timeout.oct gpib_write.oct gpib_close.oct gpib_read.oct -OBJ := gpib_class.o - -MKOCTFILE ?= mkoctfile - -CFLAGS = @DEFS@ -LFLAGS = @GPIBLIBS@ - -all: $(OBJ) $(OCT) - -%.o: %.cc - $(MKOCTFILE) $(CFLAGS) -c $^ - -%.oct: %.o - $(MKOCTFILE) $^ $(OBJ) $(LFLAGS) -o ../$@ - -clean: - rm -f *.oct *.o - -distclean: clean - rm Makefile - -.PHONY: all clean
--- a/main/instrument-control/src/gpib/gpib.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_GPIB -#include <errno.h> -//#include <fcntl.h> - -#include "gpib_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (gpib, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{gpib} = } gpib ([@var{gpibid}], [@var{timeout}])\n \ -\n\ -Open gpib interface.\n \ -\n\ -@var{gpibid} - the interface number.@* \ -@var{timeout} - the interface timeout value. If omitted defaults to blocking call.\n \ -\n\ -The gpib() shall return instance of @var{octave_gpib} class as the result @var{gpib}.\n \ -@end deftypefn") -{ -#ifndef BUILD_GPIB - error("gpib: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_gpib::register_type(); - type_loaded = true; - } - - // Do not open interface if return value is not assigned - if (nargout != 1) - { - print_usage(); - return octave_value(); - } - - // Default values - int gpibid; - const int minor = 0; - int timeout = -1; - const int secid = 0; - const int send_eoi = 1; - const int eos_mode = 0; - - - // Parse the function arguments - if (args.length() > 0) - { - if (args(0).is_integer_type() || args(0).is_float_type()) - { - gpibid = args(0).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - else - { - print_usage(); - return octave_value(); - } - - // is_float_type() is or'ed to allow expression like ("", 123), without user - // having to use ("", int32(123)), as we still only take "int_value" - if (args.length() > 1) - { - if (args(1).is_integer_type() || args(1).is_float_type()) - { - timeout = args(1).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - // Open the interface - octave_gpib* retval = new octave_gpib(); - - retval->open(minor, gpibid, secid, timeout, send_eoi, eos_mode); - - //retval->set_timeout(timeout); - //retval->set_sad(eot); - //retval->set_send_eoi(eot); - //retval->set_eos_mode(eot); - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/gpib/gpib_class.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,277 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_GPIB -#include <iostream> -#include <string> -#include <algorithm> - -#include <stdio.h> -#include <unistd.h> -#include "gpib/ib.h" - -#define GPIB_USEBLOCKREAD - -using std::string; - -#include "gpib_class.h" - -volatile bool read_interrupt = false; - -DEFINE_OCTAVE_ALLOCATOR (octave_gpib); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_gpib, "octave_gpib", "octave_gpib"); - -octave_gpib::octave_gpib() -{ - this->minor = -1; -} - -octave_gpib::~octave_gpib() -{ - this->close(); -} - -void octave_gpib::print (std::ostream& os, bool pr_as_read_syntax ) const -{ - print_raw(os, pr_as_read_syntax); - newline(os); -} - -void octave_gpib::print_raw (std::ostream& os, bool pr_as_read_syntax) const -{ - os << this->gpibid; -} - -int octave_gpib::open(int minor, int gpibid, int sad, int timeout, int send_eoi, int eos_mode) -{ - this->minor = minor; - this->gpibid = gpibid; - this->sad = sad; - this->timeout = timeout; - this->send_eoi = send_eoi; - this->eos_mode = eos_mode; - - return 1; -} - -int octave_gpib::read(uint8_t *buf, unsigned int len) -{ - int gperr,fd; - int bytes_read = 0, read_retval = -1; - - if (this->minor < 0) - { - error("gpib_read: Interface must be opened first..."); - return -1; - } - - fd = ibdev(this->minor, this->gpibid, this->sad, this->timeout, this->send_eoi, this->eos_mode); - if (fd < 0) - { - error("gpib_read: error opening gpib device..."); - return -1; - } - -#if defined(GPIB_USEBLOCKREAD) - // blocking read - not interruptable - gperr = ibrd(fd,(void *)buf,len); - if (gperr & ERR) - { - if (gperr & TIMO) - { - warning("gpib_read: read timeout"); - } - else - { - int localiberr = ThreadIberr(); - error("gpib_read: Error while reading: %d - %d\n", gperr, localiberr); - if (localiberr == 0) - { - localiberr = ThreadIbcnt(); - warning("gpib_read: failed system call: %d - %s\n", localiberr, strerror(localiberr)); - } - ibonl(fd,0); - return -1; - } - } - -#else - // async read - not interruptable as well - gperr = ibrda(fd,(void *)buf,len); - - if (gperr & ERR) - { - error("gpib_read: Error while reading: %d\n", ThreadIberr()); - ibonl(fd,0); - return -1; - } - - while (!read_interrupt) - { - gperr = ibwait(fd,CMPL); - warning("gpib_read: read timeout %d - %d - %d",gperr, ThreadIberr(),ThreadIbcnt()); - if (gperr & ERR) - { - if (gperr & TIMO) - { - warning("gpib_read: read timeout"); - } - else - { - int localiberr = ThreadIberr(); - error("gpib_read: Error while reading: %d - %d\n", gperr, localiberr); - if (localiberr == 0) - { - localiberr = ThreadIbcnt(); - warning("gpib_read: failed system call: %d - %s\n", localiberr, strerror(localiberr)); - } - ibonl(fd,0); - return -1; - } - } - } -#endif - - bytes_read = ThreadIbcnt(); - - ibonl(fd,0); - - return bytes_read; - -} - -int octave_gpib::write(string str) -{ - int gperr,fd; - - if (this->minor < 0) - { - error("gpib_write: Interface must be opened first..."); - return -1; - } - - fd = ibdev(this->minor, this->gpibid, this->sad, this->timeout, this->send_eoi, this->eos_mode); - if (fd < 0) - { - error("gpib_read: error opening gpib device..."); - return -1; - } - - gperr = ibwrt(fd,str.c_str(),str.length()); - if (gperr & ERR) { - // warning: can not write - if (ThreadIberr() != ENOL) { - // ENOL is handled by library - error("gpib: can not write gpib data to device"); - } - } - - ibonl(fd,0); - - return gperr; -} - -int octave_gpib::write(uint8_t *buf, unsigned int len) -{ - int gperr,fd; - - if (this->minor < 0) - { - error("gpib_write: Interface must be opened first..."); - return -1; - } - - fd = ibdev(this->minor, this->gpibid, this->sad, this->timeout, this->send_eoi, this->eos_mode); - if (fd < 0) - { - error("gpib_read: error opening gpib device..."); - return -1; - } - - gperr = ibwrt(fd,buf,len); - if (gperr & ERR) { - // warning: can not write - if (ThreadIberr() != ENOL) { - // ENOL is handled by library - error("gpib: can not write gpib data to device"); - } - } - - ibonl(fd,0); - - return gperr; -} - -int octave_gpib::set_timeout(int timeout) -{ - if (this->minor < 0) - { - error("gpib_timeout: Interface must be opened first..."); - return -1; - } - - if (timeout < 0 || timeout > 17) - { - error("gpib_timeout: timeout must be between 0 and 17"); - return -1; - } - - this->timeout = timeout; - - return 1; -} - -int octave_gpib::get_timeout() -{ - return this->timeout; -} - -int octave_gpib::close() -{ - int fd,gperr; - - if (this->minor > -1) - { - fd = ibdev(this->minor, this->gpibid, this->sad, this->timeout, this->send_eoi, this->eos_mode); - if (fd < 0) - { - error("gpib_close: error opening gpib device..."); - return -1; - } - - gperr = ibclr(fd); - if (gperr & ERR) { - error("gpib_close: can not clear device"); - } - - gperr = ibloc(fd); - if (gperr & ERR) { - error("gpib_close: can not set device to local"); - } - - ibonl(fd,0); - } - - this->minor = -1; - return -1; -} -#endif
--- a/main/instrument-control/src/gpib/gpib_class.h Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifndef GPIB_CLASS_H -#define GPIB_CLASS_H - -#include <octave/oct.h> -#include <octave/ov-int32.h> - -#include <string> - -using std::string; - -class octave_gpib : public octave_base_value -{ -public: - octave_gpib(); - ~octave_gpib(); - - int write(string); - int write(uint8_t*, unsigned int); - - int read(uint8_t*, unsigned int); - - int open(int, int, int, int, int, int); - int close(); - - int set_timeout(int); - int get_timeout(); - - //int set_sad(int); - //int set_send_eoi(int); - //int set_eos_mode(int); - - // Overloaded base functions - double gpib_value() const { return (double)this->gpibid; } - - virtual double scalar_value (bool frc_str_conv = false) const - { - return (double)this->gpibid; - } - - 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 minor; - int gpibid; - int sad; - int timeout; - int send_eoi; - int eos_mode; - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - -#endif
--- a/main/instrument-control/src/gpib/gpib_close.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_GPIB -#include "gpib_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (gpib_close, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} gpib_close (@var{gpib})\n \ -\n\ -Close the interface and release a file descriptor.\n \ -\n\ -@var{gpib} - instance of @var{octave_gpib} class.\n \ -@end deftypefn") -{ -#ifndef BUILD_GPIB - error("gpib: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_gpib::register_type(); - type_loaded = true; - } - - if (args.length() != 1 || args(0).type_id() != octave_gpib::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_gpib* gpib = NULL; - - const octave_base_value& rep = args(0).get_rep(); - gpib = &((octave_gpib &)rep); - - gpib->close(); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/gpib/gpib_read.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_GPIB -#include <octave/uint8NDArray.h> -#include <octave/sighandlers.h> - -#include <errno.h> - -#include "gpib_class.h" - -extern bool read_interrupt; -static bool type_loaded = false; - -void read_sighandler(int sig) -{ - printf("gpib_read: Interrupting...\n\r"); - read_interrupt = true; -} -#endif - -DEFUN_DLD (gpib_read, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[@var{data}, @var{count}] = } gpib_read (@var{gpib}, @var{n})\n \ -\n\ -Read from gpib interface.\n \ -\n\ -@var{gpib} - instance of @var{octave_gpib} class.@* \ -@var{n} - number of bytes to attempt to read of type Integer.\n \ -\n\ -The gpib_read() shall return number of bytes successfully read in @var{count} as Integer and the bytes themselves in @var{data} as uint8 array.\n \ -@end deftypefn") -{ -#ifndef BUILD_GPIB - error("gpib: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_gpib::register_type(); - type_loaded = true; - } - - if (args.length() < 2 || args.length() > 3 || args(0).type_id() != octave_gpib::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - unsigned int buffer_len = 0; - - if ( !(args(1).is_integer_type() || args(1).is_float_type())) - { - print_usage(); - return octave_value(-1); - } - - buffer_len = args(1).int_value(); - - uint8_t *buffer = NULL; - buffer = new uint8_t[buffer_len + 1]; - - if (buffer == NULL) - { - error("gpib_read: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - octave_gpib* gpib = NULL; - - const octave_base_value& rep = args(0).get_rep(); - gpib = &((octave_gpib &)rep); - - // Register custom interrupt signal handler - octave_set_signal_handler(SIGINT, read_sighandler); - read_interrupt = false; - - // Read data - int bytes_read = gpib->read(buffer, buffer_len); - - // Restore default signal handling - // TODO: a better way? - install_signal_handlers(); - - // Convert data to octave type variables - octave_value_list return_list; - uint8NDArray data( dim_vector(1, bytes_read) ); - - for (int i = 0; i < bytes_read; i++) - data(i) = buffer[i]; - - return_list(0) = data; - return_list(1) = bytes_read; - - delete[] buffer; - - return return_list; -#endif -}
--- a/main/instrument-control/src/gpib/gpib_timeout.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_GPIB - -#include "gpib_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (gpib_timeout, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} gpib_timeout (@var{gpib}, @var{timeout})\n \ -@deftypefnx {Loadable Function} {@var{t} = } gpib_timeout (@var{gpib})\n \ -\n\ -Set new or get existing gpib interface timeout parameter. The timeout value is valid from 0 to 17.\n \ -\n\ -@var{gpib} - instance of @var{octave_gpib} class.@* \ -@var{timeout} - Value of 0 means never timeout, 11 means one second and 17 means 1000 seconds (see GPIB documentation (ibtmo) for further details)\n \ -\n\ -If @var{timeout} parameter is omitted, the gpib_timeout() shall return current timeout value as the result @var{t}.\n \ -@end deftypefn") -{ -#ifndef BUILD_GPIB - error("gpib: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_gpib::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_gpib::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_gpib* gpib = NULL; - - const octave_base_value& rep = args(0).get_rep(); - gpib = &((octave_gpib &)rep); - - // Setting new timeout - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - gpib->set_timeout(args(1).int_value()); - - return octave_value(); // Should it return by default? - } - - // Returning current timeout - return octave_value(gpib->get_timeout()); -#endif -}
--- a/main/instrument-control/src/gpib/gpib_write.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_GPIB -#include <errno.h> - -#include "gpib_class.h" - - -static bool type_loaded = false; -#endif - - -DEFUN_DLD (gpib_write, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{n} = } gpib_write (@var{gpib}, @var{data})\n \ -\n\ -Write data to a gpib interface.\n \ -\n\ -@var{gpib} - instance of @var{octave_gpib} class.@* \ -@var{data} - data to be written to the gpib interface. Can be either of String or uint8 type.\n \ -\n\ -Upon successful completion, gpib_write() shall return the number of bytes written as the result @var{n}.\n \ -@end deftypefn") -{ -#ifndef BUILD_GPIB - error("gpib: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_gpib::register_type(); - type_loaded = true; - } - - if (args.length() != 2 || args(0).type_id() != octave_gpib::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_gpib* gpib = NULL; - int retval; - - const octave_base_value& rep = args(0).get_rep(); - gpib = &((octave_gpib &)rep); - - if (args(1).is_string()) // String - { - retval = gpib->write(args(1).string_value()); - } - else if (args(1).byte_size() == args(1).numel()) // uint8_t - { - NDArray data = args(1).array_value(); - uint8_t* buf = NULL; - buf = new uint8_t[data.length()]; - - if (buf == NULL) - { - error("gpib_write: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - for (int i = 0; i < data.length(); i++) - buf[i] = static_cast<uint8_t>(data(i)); - - retval = gpib->write(buf, data.length()); - - delete[] buf; - } - else - { - print_usage(); - return octave_value(-1); - } - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/i2c/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -OCT := i2c.oct i2c_close.oct i2c_addr.oct i2c_write.oct i2c_read.oct -OBJ := i2c_class.o - -MKOCTFILE ?= mkoctfile - -CFLAGS = @DEFS@ - -all: $(OBJ) $(OCT) - -%.o: %.cc - $(MKOCTFILE) $(CFLAGS) -c $^ - -%.oct: %.o - $(MKOCTFILE) $^ $(OBJ) -o ../$@ - -clean: - rm -f *.oct *.o - -distclean: clean - rm Makefile - -.PHONY: all clean
--- a/main/instrument-control/src/i2c/i2c.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_I2C -#include <fcntl.h> - -using std::string; - -#include "i2c_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (i2c, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{i2c} = } i2c ([@var{path}], [@var{address}])\n \ -\n\ -Open i2c interface.\n \ -\n\ -@var{path} - the interface path of type String. If omitted defaults to '/dev/i2c-0'. @*\ -@var{address} - the slave device address. If omitted must be set using i2c_addr() call.\n \ -\n\ -The i2c() shall return instance of @var{octave_i2c} class as the result @var{i2c}.\n \ -@end deftypefn") -{ -#ifndef BUILD_I2C - error("i2c: Your system doesn't support the I2C interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_i2c::register_type(); - type_loaded = true; - } - - // Do not open interface if return value is not assigned - if (nargout != 1) - { - print_usage(); - return octave_value(); - } - - // Default values - int oflags = O_RDWR; - string path("/dev/i2c-0"); - int addr = -1; - - // Parse the function arguments - if (args.length() > 0) - { - if (args(0).is_string()) - { - path = args(0).string_value(); - } - else - { - print_usage(); - return octave_value(); - } - - } - - // is_float_type() is or'ed to allow expression like ("", 123), without user - // having to use ("", int32(123)), as we still only take "int_value" - if (args.length() > 1) - { - if (args(1).is_integer_type() || args(1).is_float_type()) - { - addr = args(1).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - octave_i2c* retval = new octave_i2c(); - - // Open the interface - if (retval->open(path, oflags) < 0) - return octave_value(); - - if (addr > 0) - retval->set_addr(addr); - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/i2c/i2c_addr.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_I2C -#include "i2c_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (i2c_addr, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} i2c_addr (@var{i2c}, @var{address})\n \ -@deftypefnx {Loadable Function} {@var{addr} = } i2c_addr (@var{i2c})\n \ -\n\ -Set new or get existing i2c slave device address.\n \ -\n\ -@var{i2c} - instance of @var{octave_i2c} class.@*\ -@var{address} - i2c slave device address of type Integer. \ -The address is passed in the 7 or 10 lower bits of the argument.\n \ -\n\ -If @var{address} parameter is omitted, the i2c_addr() shall return \ -current i2c slave device address as the result @var{addr}.\n \ -@end deftypefn") -{ -#ifndef BUILD_I2C - error("i2c: Your system doesn't support the I2C interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_i2c::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_i2c::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_i2c* i2c = NULL; - - const octave_base_value& rep = args(0).get_rep(); - i2c = &((octave_i2c &)rep); - - - // Setting new slave address - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - i2c->set_addr(args(1).int_value()); - - return octave_value(); - } - - // Returning current slave address - return octave_value(i2c->get_addr()); -#endif -}
--- a/main/instrument-control/src/i2c/i2c_class.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,200 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_I2C -#include <stdio.h> -#include <stdlib.h> -#include <string> - -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/ioctl.h> - - -#if defined (__linux__) -#include <linux/i2c-dev.h> -#endif - -// Platform specific header files -#if defined (__FreeBSD__) -#include <dev/iicbus/iic.h> -#endif - - -using std::string; - -#include "i2c_class.h" - -DEFINE_OCTAVE_ALLOCATOR (octave_i2c); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_i2c, "octave_i2c", "octave_i2c"); - -octave_i2c::octave_i2c() -{ - this->fd = -1; -} - -octave_i2c::~octave_i2c() -{ - this->close(); -} - -int octave_i2c::get_fd() -{ - return this->fd; -} - -void octave_i2c::print (std::ostream& os, bool pr_as_read_syntax ) const -{ - print_raw(os, pr_as_read_syntax); - newline(os); -} - -void octave_i2c::print_raw (std::ostream& os, bool pr_as_read_syntax) const -{ - os << this->fd; -} - -int octave_i2c::open(string path, int flags) -{ - this->fd = ::open(path.c_str(), flags, 0); - - if (this->get_fd() < 0) - { - error("i2c: Error opening the interface: %s\n", strerror(errno)); - return -1; - } - - return this->get_fd(); -} - - -int octave_i2c::set_addr(int addr) -{ - if (this->get_fd() < 0) - { - error("i2c: Interface must be open first..."); - return -1; - } - -#if defined (__linux__) - if (::ioctl(this->get_fd(), I2C_SLAVE, addr) < 0) - { - error("i2c: Error setting slave address: %s\n", strerror(errno)); - return -1; - } -#endif - - return 1; -} - -int octave_i2c::get_addr() -{ - if (this->get_fd() < 0) - { - error("i2c: Interface must be open first..."); - return -1; - } - - return this->addr; -} - -int octave_i2c::read(uint8_t *buf, unsigned int len) -{ - if (this->get_fd() < 0) - { - error("i2c: Interface must be open first..."); - return -1; - } - - int retval = -1; - -#if defined (__linux__) - retval = ::read(this->get_fd(), buf, len); -#endif - -#if defined (__FreeBSD__) - // Populate FreeBSD-specific structure - struct iiccmd i2c_slave; - - i2c_slave.slave = static_cast<uint8_t>(this->get_addr()); - i2c_slave.count = len; - i2c_slave.last = 0; // No additional reads will follow for this transaction - i2c_slave.buf = buf; - - ::ioctl(this->get_fd(), I2CSTART, &i2c_slave); - retval = ::ioctl(this->get_fd(), I2CREAD, &i2c_slave); - ::ioctl(this->get_fd(), I2CSTOP); -#endif - - if (retval < 0) - error("i2c: Failed to read from the i2c bus: %s\n", strerror(errno)); - - return retval; -} - -int octave_i2c::write(uint8_t *buf, unsigned int len) -{ - if (this->get_fd() < 0) - { - error("i2c: Interface must be open first..."); - return -1; - } - - int retval = -1; - -#if defined (__linux__) - retval = ::write(this->get_fd(), buf, len); -#endif - -#if defined (__FreeBSD__) - // Populate FreeBSD-specific structure - struct iiccmd i2c_slave; - - i2c_slave.slave = static_cast<uint16_t>(this->get_addr()); - i2c_slave.count = len; - i2c_slave.last = 0; // No additional writes will follow for this transaction - i2c_slave.buf = buf; - - ::ioctl(this->get_fd(), I2CSTART, &i2c_slave); - retval = ::ioctl(this->get_fd(), I2CWRITE, &i2c_slave); - ::ioctl(this->get_fd(), I2CSTOP); -#endif - - if (retval < 0) - error("i2c: Failed to write to the i2c bus: %s\n", strerror(errno)); - - return retval; -} - -int octave_i2c::close() -{ - int retval = -1; - - if (this->get_fd() > 0) - { - retval = ::close(this->get_fd()); - this->fd = -1; - } - - return retval; -} -#endif
--- a/main/instrument-control/src/i2c/i2c_class.h Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifndef I2C_CLASS_H -#define I2C_CLASS_H - -#include <octave/oct.h> - -#include <string> - -using std::string; - -class octave_i2c : public octave_base_value -{ -public: - octave_i2c(); - ~octave_i2c(); - - int open(string /* path */, int /* open flags */); - int close(); - int get_fd(); - - int set_addr(int /* slave ddress */); - int get_addr(); - - // Simple i2c commands - int write(uint8_t* /* buffer */, unsigned int /* buffer size */); - int read(uint8_t* /* buffer */, unsigned int /* buffer size */); - - - // Overloaded base functions - double i2c_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) 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 addr; - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - - -#endif
--- a/main/instrument-control/src/i2c/i2c_close.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_I2C -#include "i2c_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (i2c_close, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} i2c_close (@var{i2c})\n \ -\n\ -Close the interface and release a file descriptor.\n \ -\n\ -@var{i2c} - instance of @var{octave_i2c} class.@*\ -@end deftypefn") -{ -#ifndef BUILD_I2C - error("i2c: Your system doesn't support the I2C interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_i2c::register_type(); - type_loaded = true; - } - - - if (args.length() != 1 || args(0).type_id() != octave_i2c::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_i2c* i2c = NULL; - - const octave_base_value& rep = args(0).get_rep(); - i2c = &((octave_i2c &)rep); - - i2c->close(); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/i2c/i2c_read.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> -#include <octave/uint8NDArray.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_I2C -#include <errno.h> - -#include "i2c_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (i2c_read, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[@var{data}, @var{count}] = } i2c_read (@var{i2c}, @var{n})\n \ -\n\ -Read from i2c slave device.\n \ -\n\ -@var{i2c} - instance of @var{octave_i2c} class.@*\ -@var{n} - number of bytes to attempt to read of type Integer.\n \ -\n\ -The i2c_read() shall return number of bytes successfully read in @var{count} as Integer and the bytes themselves in @var{data} as uint8 array.\n \ -@end deftypefn") -{ -#ifndef BUILD_I2C - error("i2c: Your system doesn't support the I2C interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_i2c::register_type(); - type_loaded = true; - } - - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_i2c::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - uint8_t *buffer = NULL; - unsigned int buffer_len = 1; - - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - buffer_len = args(1).int_value(); - } - - buffer = new uint8_t [buffer_len + 1]; - - if (buffer == NULL) - { - error("i2c_read: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - octave_i2c* i2c = NULL; - - const octave_base_value& rep = args(0).get_rep(); - i2c = &((octave_i2c &)rep); - - int retval; - - retval = i2c->read(buffer, buffer_len); - - octave_value_list return_list; - uint8NDArray data( dim_vector(1, retval) ); - - for (int i = 0; i < retval; i++) - data(i) = buffer[i]; - - return_list(0) = data; - return_list(1) = retval; - - delete[] buffer; - - return return_list; -#endif -}
--- a/main/instrument-control/src/i2c/i2c_write.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_I2C -#include <errno.h> - -#include "i2c_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (i2c_write, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{n} = } i2c_write (@var{i2c}, @var{data})\n \ -\n\ -Write data to a i2c slave device.\n \ -\n\ -@var{i2c} - instance of @var{octave_i2c} class.@*\ -@var{data} - data, of type uint8, to be written to the slave device.\n \ -\n\ -Upon successful completion, i2c_write() shall return the number of bytes written as the result @var{n}.\n \ -@end deftypefn") -{ -#ifndef BUILD_I2C - error("i2c: Your system doesn't support the I2C interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_i2c::register_type(); - type_loaded = true; - } - - if (args.length() != 2 || args(0).type_id() != octave_i2c::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_i2c* i2c = NULL; - int retval; - - const octave_base_value& rep = args(0).get_rep(); - i2c = &((octave_i2c &)rep); - - if (args(1).byte_size() == args(1).numel()) // uint8_t - { - NDArray data = args(1).array_value(); - uint8_t *buf = NULL; - buf = new uint8_t[data.length()]; - - if (buf == NULL) - { - error("i2c_write: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - for (int i = 0; i < data.length(); i++) - buf[i] = static_cast<uint8_t>(data(i)); - - retval = i2c->write(buf, data.length()); - - delete[] buf; - } - else - { - print_usage(); - return octave_value(-1); - } - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/parallel/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -OCT := parallel.oct pp_close.oct pp_datadir.oct pp_data.oct pp_stat.oct pp_ctrl.oct -OBJ := parallel_class.o - -MKOCTFILE ?= mkoctfile - -CFLAGS = @DEFS@ - -all: $(OBJ) $(OCT) - -%.o: %.cc - $(MKOCTFILE) $(CFLAGS) -c $^ - -%.oct: %.o - $(MKOCTFILE) $^ $(OBJ) -o ../$@ - -clean: - rm -f *.oct *.o - -distclean: clean - rm Makefile - -.PHONY: all clean
--- a/main/instrument-control/src/parallel/parallel.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_PARALLEL -#include <octave/ov-int32.h> - -#include <iostream> -#include <string> -#include <algorithm> - -#ifndef __WIN32__ -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#endif - -using std::string; - -#include "parallel_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (parallel, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{parallel} = } parallel ([@var{path}], [@var{direction}])\n \ -\n\ -Open Parallel interface.\n \ -\n\ -@var{path} - the interface path of type String. If omitted defaults to '/dev/parport0'.@*\ -@var{direction} - the direction of interface drivers of type Integer, see: PP_DATADIR for more info. \ -If omitted defaults to 1 (Input).\n \ -\n\ -The parallel() shall return instance of @var{octave_parallel} class as the result @var{parallel}.\n \ -@end deftypefn") -{ -#ifndef BUILD_PARALLEL - error("parallel: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_parallel::register_type(); - type_loaded = true; - } - - // Do not open interface if return value is not assigned - if (nargout != 1) - { - print_usage(); - return octave_value(); - } - - // Default values - int oflags = O_RDWR; - int dir = 1; // Input - string path("/dev/parport0"); - - // Parse the function arguments - if (args.length() > 0) - { - if (args(0).is_string()) - { - path = args(0).string_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - // is_float_type() is or'ed to allow expression like ("", 123), without user - // having to use ("", int32(123)), as we still only take "int_value" - if (args.length() > 1) - { - if (args(1).is_integer_type() || args(1).is_float_type()) - { - dir = args(1).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - octave_parallel* retval = new octave_parallel(); - - // Open the interface - if (retval->open(path, oflags) < 0) - return octave_value(); - - // Set direction - retval->set_datadir(dir); - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/parallel/parallel_class.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,285 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_PARALLEL -#include <octave/oct.h> -#include <octave/ov-int32.h> - -#include <iostream> -#include <string> -#include <algorithm> - -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> - -#if defined (__linux__) -#include <linux/parport.h> -#include <linux/ppdev.h> -#endif - -// Platform specific header files -#if defined (__FreeBSD__) -#include <dev/ppbus/ppi.h> -#include <dev/ppbus/ppbconf.h> - -// And constants -#define PPWCONTROL PPISCTRL -#define PPRCONTROL PPIGCTRL -#define PPWSTATUS PPISSTATUS -#define PPRSTATUS PPIGSTATUS -#define PPWDATA PPISDATA -#define PPRDATA PPIGDATA -#endif - -using std::string; - -#include "parallel_class.h" - -DEFINE_OCTAVE_ALLOCATOR (octave_parallel); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_parallel, "octave_parallel", "octave_parallel"); - -octave_parallel::octave_parallel() -{ - this->fd = -1; -} - -octave_parallel::~octave_parallel() -{ - this->close(); -} - -int octave_parallel::open(string path, int flags) -{ - this->fd = ::open(path.c_str(), flags, 0); - - if (this->get_fd() < 0) - { - error("parallel: Error opening the interface: %s\n", strerror(errno)); - return -1; - } - - // Claim control of parallel port - // Not used with FreeBSD -#if !defined(__FreeBSD__) - - if (ioctl(this->get_fd(), PPCLAIM) < 0) - { - error("parallel: Error when claiming the interface: %s\n", strerror(errno)); - - ::close(this->get_fd()); - this->fd = -1; - - return -1; - } - -#endif - - return this->get_fd(); -} - -int octave_parallel::get_fd() -{ - return this->fd; -} - -void octave_parallel::print(std::ostream& os, bool pr_as_read_syntax ) const -{ - print_raw(os, pr_as_read_syntax); - newline(os); -} - -void octave_parallel::print_raw(std::ostream& os, bool pr_as_read_syntax) const -{ - os << this->fd; -} - -int octave_parallel::set_datadir(int dir) -{ - if (this->get_fd() < 0) - { - error("parallel: Open the interface first..."); - return -1; - } - - if (dir < 0 || 1 < dir) - { - error("parallel: Unsupported data direction..."); - return -1; - } - - // The ioctl parameter is a pointer to an int. - // If the int is zero, the drivers are turned on (forward/output direction); - // if non-zero, the drivers are turned off (reverse/input direction). - // Not used with FreeBSD -#if !defined(__FreeBSD__) - - if (ioctl(this->get_fd(), PPDATADIR, &dir) < 0) - { - error("pp_datadir: error setting data direction: %s\n", strerror(errno)); - return false; - } - -#endif - - this->dir = dir; - - return 1; -} - -int octave_parallel::get_datadir() -{ - if (this->get_fd() < 0) - { - error("parallel: Open the interface first..."); - return false; - } - - return this->dir; -} - -int octave_parallel::get_stat() -{ - if (this->get_fd() < 0) - { - error("parallel: Open the interface first..."); - return -1; - } - - uint8_t status; - - if (ioctl(this->get_fd(), PPRSTATUS, &status) < 0) - { - error("parallel: Error while reading from Status register: %s\n", strerror(errno)); - return -1; - } - - return status; -} - -int octave_parallel::set_data(uint8_t data) -{ - if (this->get_fd() < 0) - { - error("parallel: Open the interface first..."); - return -1; - } - - /* - if (this->get_dir() == 1) - { - error("parallel: Trying to output data while in Input mode, this can result in hardware damage! \ - Use override if you know what you are doing..."); - return false; - } - */ - - if (ioctl(this->get_fd(), PPWDATA, &data) < 0) - { - error("parallel: Error while writing to Data register: %s\n", strerror(errno)); - return -1; - } - - return 1; -} - -int octave_parallel::get_data() -{ - if (this->get_fd() < 0) - { - error("parallel: Open the interface first..."); - return -1; - } - - uint8_t data; - - if (ioctl(this->get_fd(), PPRDATA, &data) < 0) - { - error("parallel: Error while reading from Data register: %s\n", strerror(errno)); - return -1; - } - - return data; -} - -int octave_parallel::set_ctrl(uint8_t ctrl) -{ - if (this->get_fd() < 0) - { - error("parallel: Open the interface first..."); - return -1; - } - - if (ioctl(this->get_fd(), PPWCONTROL, &ctrl) < 0) - { - error("parallel: Error while writing to Control register: %s\n", strerror(errno)); - return -1; - } - - return 1; -} - -int octave_parallel::get_ctrl() -{ - if (this->get_fd() < 0) - { - error("parallel: Open the interface first..."); - return -1; - } - - uint8_t ctrl; - - if (ioctl(this->get_fd(), PPRCONTROL, &ctrl) < 0) - { - error("parallel: Error while reading from Control register: %s\n", strerror(errno)); - return -1; - } - - return ctrl; -} - -int octave_parallel::close() -{ - if (this->get_fd() > 0) - { - // Release parallel port - // Not used with FreeBSD -#if !defined(__FreeBSD__) - - if (ioctl(this->get_fd(), PPRELEASE) < 0) - error("parallel: error releasing parallel port: %s\n", strerror(errno)); - -#endif - - int retval = ::close(this->get_fd()); - this->fd = -1; - - return retval; - } - - return -1; -} -#endif
--- a/main/instrument-control/src/parallel/parallel_class.h Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifndef PARALLEL_CLASS_H -#define PARALLEL_CLASS_H - -#include <octave/oct.h> -#include <octave/ov-int32.h> - -#include <string> - -using std::string; - -class octave_parallel : public octave_base_value -{ -public: - octave_parallel(); - ~octave_parallel(); - - int open(string /* path */, int /* open flags */); - int close(); - int get_fd(); - - int get_datadir(); - int set_datadir(int /* direction */); - - int get_data(); - int set_data(uint8_t /* value */); - - int get_stat(); - //int set_stat(uint8_t); - - int get_ctrl(); - int set_ctrl(uint8_t /* value */); - - // Overloaded base functions - double parallel_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) 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; - - // 1 - Input - // 0 - Output - int dir; - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - - -#endif
--- a/main/instrument-control/src/parallel/pp_close.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_PARALLEL -#include "parallel_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (pp_close, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} pp_close (@var{parallel})\n \ -\n\ -Close the interface and release a file descriptor.\n \ -\n\ -@var{parallel} - instance of @var{octave_serial} class.@*\ -@end deftypefn") -{ -#ifndef BUILD_PARALLEL - error("parallel: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_parallel::register_type(); - type_loaded = true; - } - - if (args.length() != 1 || args(0).type_id() != octave_parallel::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_parallel* parallel = NULL; - - const octave_base_value& rep = args(0).get_rep(); - parallel = &((octave_parallel &)rep); - - parallel->close(); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/parallel/pp_ctrl.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_PARALLEL -#include "parallel_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (pp_ctrl, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} pp_ctrl (@var{parallel}, @var{ctrl})\n \ -@deftypefnx {Loadable Function} {@var{c} = } pp_ctrl (@var{parallel})\n \ -\n\ -Sets or Read the Control lines.\ -\n\ -@var{parallel} - instance of @var{octave_parallel} class.@*\ -@var{ctrl} - control parameter to be set of type Byte.\n \ -\n\ -If @var{ctrl} parameter is omitted, the pp_ctrl() shall return current Control lines state as the result @var{c}.\n \ -@end deftypefn") -{ -#ifndef BUILD_PARALLEL - error("parallel: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_parallel::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_parallel::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_parallel* parallel = NULL; - - const octave_base_value& rep = args(0).get_rep(); - parallel = &((octave_parallel &)rep); - - // Set new Control register value - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - parallel->set_ctrl(args(1).int_value()); - - return octave_value(); - } - - // Return current Control register value on port - return octave_value(parallel->get_ctrl()); -#endif -}
--- a/main/instrument-control/src/parallel/pp_data.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_PARALLEL -#include "parallel_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (pp_data, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} pp_data (@var{parallel}, @var{data})\n \ -@deftypefnx {Loadable Function} {@var{d} = } pp_data (@var{parallel})\n \ -\n\ -Sets or Read the Data lines.\ -\n\ -@var{parallel} - instance of @var{octave_parallel} class.@*\ -@var{data} - data parameter to be set of type Byte.\n \ -\n\ -If @var{data} parameter is omitted, the pp_data() shall return current Data lines state as the result @var{d}.\n \ -@end deftypefn") -{ -#ifndef BUILD_PARALLEL - error("parallel: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_parallel::register_type(); - type_loaded = true; - } - - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_parallel::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_parallel* parallel = NULL; - - const octave_base_value& rep = args(0).get_rep(); - parallel = &((octave_parallel &)rep); - - // Set new Data register value - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - parallel->set_data(args(1).int_value()); - - return octave_value(); - } - - // Return current Data register value on port - return octave_value(parallel->get_data()); -#endif -}
--- a/main/instrument-control/src/parallel/pp_datadir.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_PARALLEL -#include "parallel_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (pp_datadir, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} pp_datadir (@var{parallel}, @var{direction})\n \ -@deftypefnx {Loadable Function} {@var{dir} = } pp_datadir (@var{parallel})\n \ -\n\ -Controls the Data line drivers. Normally the computer's parallel port will drive the data lines, \ -but for byte-wide transfers from the peripheral to the host it is useful to turn off those drivers \ -and let the peripheral drive the signals. (If the drivers on the computer's parallel port are left \ -on when this happens, the port might be damaged.)\n \ -\n\ -@var{parallel} - instance of @var{octave_parallel} class.@*\ -@var{direction} - direction parameter of type Integer. Supported values: 0 - the drivers are turned on \ -(Output/Forward direction); 1 - the drivers are turned off (Input/Reverse direction).\n \ -\n\ -If @var{direction} parameter is omitted, the pp_datadir() shall return current Data direction as the result @var{dir}.\n \ -@end deftypefn") -{ -#ifndef BUILD_PARALLEL - error("parallel: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_parallel::register_type(); - type_loaded = true; - } - - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_parallel::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_parallel* parallel = NULL; - - const octave_base_value& rep = args(0).get_rep(); - parallel = &((octave_parallel &)rep); - - // Set new direction - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - parallel->set_datadir(args(1).int_value()); - - return octave_value(); - } - - // Return current direction - return octave_value(parallel->get_datadir()); -#endif -}
--- a/main/instrument-control/src/parallel/pp_stat.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_PARALLEL -#include "parallel_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (pp_stat, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{stat} = } pp_stat (@var{parallel})\n \ -\n\ -Reads the Status lines.\n \ -\n\ -@var{parallel} - instance of @var{octave_parallel} class.@*\ -\n\ -The pp_stat() shall return current Status lines state as the result @var{stat}.\n \ -@end deftypefn") -{ -#ifndef BUILD_PARALLEL - error("parallel: Your system doesn't support the GPIB interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_parallel::register_type(); - type_loaded = true; - } - - - if (args.length() != 1 || args(0).type_id() != octave_parallel::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_parallel* parallel = NULL; - - const octave_base_value& rep = args(0).get_rep(); - parallel = &((octave_parallel &)rep); - - // Return current Status register value on port - return octave_value(parallel->get_stat()); -#endif -}
--- a/main/instrument-control/src/serial/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -OCT := serial.oct srl_baudrate.oct srl_timeout.oct srl_bytesize.oct srl_flush.oct \ - srl_parity.oct srl_stopbits.oct srl_write.oct srl_close.oct srl_read.oct -OBJ := serial_class.o - -MKOCTFILE ?= mkoctfile - -CFLAGS = @DEFS@ - -all: $(OBJ) $(OCT) - -%.o: %.cc - $(MKOCTFILE) $(CFLAGS) -c $^ - -%.oct: %.o - $(MKOCTFILE) $^ $(OBJ) -o ../$@ - -clean: - rm -f *.oct *.o - -distclean: clean - rm Makefile - -.PHONY: all clean
--- a/main/instrument-control/src/serial/serial.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -// TODO: Implement Flow Control -// TODO: Implement H/W handshaking - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include <errno.h> -#include <fcntl.h> - -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (serial, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{serial} = } serial ([@var{path}], [@var{baudrate}], [@var{timeout}])\n \ -\n\ -Open serial interface.\n \ -\n\ -@var{path} - the interface path of type String. If omitted defaults to '/dev/ttyUSB0'. @*\ -@var{baudrate} - the baudrate of interface. If omitted defaults to 115200. @*\ -@var{timeout} - the interface timeout value. If omitted defaults to blocking call.\n \ -\n\ -The serial() shall return instance of @var{octave_serial} class as the result @var{serial}.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - // Do not open interface if return value is not assigned - if (nargout != 1) - { - print_usage(); - return octave_value(); - } - - // Default values - string path("/dev/ttyUSB0"); - unsigned int baud_rate = 115200; - short timeout = -1; - - unsigned short bytesize = 8; - string parity("N"); - unsigned short stopbits = 1; - int oflags = O_RDWR | O_NOCTTY | O_SYNC | O_NDELAY; - // O_SYNC - All writes immediately effective, no buffering - // O_NOCTTY - Do not make serial terminal the controlling terminal for the process - // O_NDELAY - Do not care what state the DCD signal line is in. Used for open only, later disabled. - - // Parse the function arguments - if (args.length() > 0) - { - if (args(0).is_string()) - { - path = args(0).string_value(); - } - else - { - print_usage(); - return octave_value(); - } - - } - - // is_float_type() is or'ed to allow expression like ("", 123), without user - // having to use ("", int32(123)), as we still only take "int_value" - if (args.length() > 1) - { - if (args(1).is_integer_type() || args(1).is_float_type()) - { - baud_rate = args(1).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - if (args.length() > 2) - { - if (args(2).is_integer_type() || args(2).is_float_type()) - { - timeout = args(2).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - - octave_serial* retval = new octave_serial(); - - // Open the interface - if (retval->open(path, oflags) < 0) - return octave_value(); - - retval->set_baudrate(baud_rate); - retval->set_timeout(timeout); - retval->set_parity(parity); - retval->set_bytesize(bytesize); - retval->set_stopbits(stopbits); - - //retval->flush(2); - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/serial/serial_class.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,565 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include <iostream> -#include <string> -#include <algorithm> - -#ifndef __WIN32__ -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <termios.h> -#include <unistd.h> -#endif - -using std::string; - -#include "serial_class.h" - -volatile bool read_interrupt = false; - -DEFINE_OCTAVE_ALLOCATOR (octave_serial); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_serial, "octave_serial", "octave_serial"); - -octave_serial::octave_serial() -{ - this->fd = -1; -} - -int octave_serial::open(string path, int flags) -{ - this->fd = ::open(path.c_str(), flags); - - if (this->get_fd() > 0) - { - // 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; - } - - if (tcgetattr(this->fd, &this->config) < 0) - { - error("serial: Failed to get terminal attributes: %s\n", strerror(errno)); - this->close(); - return -1; - } - - // Clear all settings - this->config.c_iflag = 0; // Input modes - this->config.c_oflag = 0; // Output modes - this->config.c_cflag = CS8 | CREAD | CLOCAL; // Control modes, 8n1 - this->config.c_lflag = 0; // Local modes - this->config.c_cc[VMIN] = 1; - - if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) - { - error("serial: Failed to set default terminal attributes: %s\n", strerror(errno)); - this->close(); - return -1; - } - - // Disable NDELAY - if (fcntl(this->get_fd(), F_SETFL, 0) < 0) - { - error("serial: Failed to disable NDELAY flag: %s\n", strerror(errno)); - this->close(); - return -1; - } - - this->blocking_read = true; - } - else - { - error("serial: Error opening the interface: %s\n", strerror(errno)); - return -1; - } - - return this->get_fd(); -} - -octave_serial::~octave_serial() -{ - this->close(); -} - -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) - { - error("srl_read: Interface must be opened first..."); - return 0; - } - - int bytes_read = 0, read_retval = -1; - - // While not interrupted in blocking mode - while (!read_interrupt) - { - read_retval = ::read(this->get_fd(), (void *)(buf + bytes_read), len - bytes_read); - //printf("read_retval: %d\n\r", read_retval); - - if (read_retval < 0) - { - error("srl_read: Error while reading: %s\n", strerror(errno)); - break; - } - - bytes_read += read_retval; - - // Required number of bytes read - if (bytes_read >= len) - break; - - // Timeout while in non-blocking mode - if (read_retval == 0 && !this->blocking_read) - break; - } - - return bytes_read; -} - -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(uint8_t *buf, unsigned int len) -{ - if (this->get_fd() < 0) - { - error("serial: Interface must be opened first..."); - return -1; - } - - return ::write(get_fd(), buf, len); -} - -int octave_serial::set_timeout(short timeout) -{ - if (this->get_fd() < 0) - { - error("serial: Interface must be opened first..."); - return -1; - } - - if (timeout < -1 || timeout > 255) - { - error("srl_timeout: timeout value must be between [-1..255]..."); - return -1; - } - - // Disable custom timeout, enable blocking read - if (timeout < 0) - { - this->blocking_read = true; - timeout = 5; - } - // Enable custom timeout, disable blocking read - else - { - this->blocking_read = false; - } - - BITMASK_CLEAR(this->config.c_lflag, ICANON); // Set non-canonical mode - 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) { - error("srl_timeout: error setting timeout..."); - return -1; - } - - return 1; -} - -int octave_serial::get_timeout() -{ - if (blocking_read) - return -1; - else - return this->config.c_cc[VTIME]; -} - -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. - */ - - if (stopbits == 1) - { - // Set to one stop bit - BITMASK_CLEAR(this->config.c_cflag, CSTOPB); - } - else if (stopbits == 2) - { - // Set to two stop bits - BITMASK_SET(this->config.c_cflag, CSTOPB); - } - else - { - error("srl_stopbits: Only 1 or 2 stop bits are supported..."); - return false; - } - - if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) { - error("srl_stopbits: error setting stop bits: %s\n", strerror(errno)); - return false; - } - - return true; -} - -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 - return 1; -} - -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) - { - case 5: c_bytesize = CS5; break; - case 6: c_bytesize = CS6; break; - case 7: c_bytesize = CS7; break; - case 8: c_bytesize = CS8; break; - - default: - error("srl_bytesize: expecting value between [5..8]..."); - return false; - } - - // Clear bitmask CSIZE - BITMASK_CLEAR(this->config.c_cflag, CSIZE); - - // Apply new - BITMASK_SET(this->config.c_cflag, c_bytesize); - - if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) { - error("srl_bytesize: error setting byte size: %s\n", strerror(errno)); - return false; - } - - return true; -} - -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)) - retval = 5; - else if (BITMASK_CHECK(this->config.c_cflag, CS6)) - retval = 6; - else if (BITMASK_CHECK(this->config.c_cflag, CS7)) - retval = 7; - else if (BITMASK_CHECK(this->config.c_cflag, CS8)) - retval = 8; - - return retval; -} - -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) - { - case 0: - baud_rate = B0; break; - case 50: - baud_rate = B50; break; - case 75: - baud_rate = B75; break; - case 110: - baud_rate = B110; break; - case 134: - baud_rate = B134; break; - case 150: - baud_rate = B150; break; - case 200: - baud_rate = B200; break; - case 300: - baud_rate = B300; break; - case 600: - baud_rate = B600; break; - case 1200: - baud_rate = B1200; break; - case 1800: - baud_rate = B1800; break; - case 2400: - baud_rate = B2400; break; - case 4800: - baud_rate = B4800; break; - case 9600: - baud_rate = B9600; break; - case 19200: - baud_rate = B19200; break; - case 38400: - baud_rate = B38400; break; - case 57600: - baud_rate = B57600; break; - case 115200: - baud_rate = B115200; break; - case 230400: - baud_rate = B230400; break; - default: - error("srl_baudrate: currently only 0, 50, 75, 110, \ - 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, \ - 9600 19200, 38400, 57600, 115200 and 230400 baud rates are supported..."); - return false; - } - - cfsetispeed(&this->config, baud_rate); - cfsetospeed(&this->config, baud_rate); - - if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) { - error("srl_baudrate: error setting baud rate: %s\n", strerror(errno)); - return false; - } - - return true; -} - -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); - - if (baudrate == B0) - retval = 0; - else if (baudrate == B50) - retval = 50; - else if (baudrate == B75) - retval = 75; - else if (baudrate == B110) - retval = 110; - else if (baudrate == B134) - retval = 134; - else if (baudrate == B150) - retval = 150; - else if (baudrate == B200) - retval = 200; - else if (baudrate == B300) - retval = 300; - else if (baudrate == B600) - retval = 600; - else if (baudrate == B1200) - retval = 1200; - else if (baudrate == B1800) - retval = 1800; - else if (baudrate == B2400) - retval = 2400; - else if (baudrate == B4800) - retval = 4800; - else if (baudrate == B9600) - retval = 9600; - else if (baudrate == B19200) - retval = 19200; - else if (baudrate == B38400) - retval = 38400; - else if (baudrate == B57600) - retval = 57600; - else if (baudrate == B115200) - retval = 115200; - else if (baudrate == B230400) - retval = 230400; - - return retval; - -} - -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. - * TCIFLUSH Flush pending input. - */ - - int flag; - - switch (queue_selector) - { - case 0: flag = TCOFLUSH; break; - case 1: flag = TCIFLUSH; break; - case 2: flag = TCIOFLUSH; break; - default: - error("srl_flush: only [0..2] values are accepted..."); - return false; - } - - return ::tcflush(this->get_fd(), flag); -} - - -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); - - /* - * PARENB Enable parity generation on output and parity checking for input. - * PARODD If set, then parity for input and output is odd; otherwise even parity is used. - */ - - if (parity == "n" || parity == "none") - { - // Disable parity generation/checking - BITMASK_CLEAR(this->config.c_cflag, PARENB); - } - else if (parity == "e" || parity == "even") - { - // Enable parity generation/checking - BITMASK_SET(this->config.c_cflag, PARENB); - - // Set to Even - BITMASK_CLEAR(this->config.c_cflag, PARODD); - - } - else if (parity == "o" || parity == "odd") - { - // Enable parity generation/checking - BITMASK_SET(this->config.c_cflag, PARENB); - - // Set to Odd - BITMASK_SET(this->config.c_cflag, PARODD); - - } - else - { - error("srl_parity: Only [N]one, [E]ven or [O]dd parities are supported..."); - return false; - } - - if (tcsetattr(this->get_fd(), TCSANOW, &this->config) < 0) { - error("srl_parity: error setting parity: %s\n", strerror(errno)); - return false; - } - - return true; -} - -string octave_serial::get_parity() -{ - if (!BITMASK_CHECK(this->config.c_cflag, PARENB)) - return "None"; - else if (BITMASK_CHECK(this->config.c_cflag, PARODD)) - return "Odd"; - else - return "Even"; -} - -int octave_serial::get_fd() -{ - return this->fd; -} - -int octave_serial::close() -{ - int retval = -1; - - if (this->get_fd() > 0) - { - retval = ::close(this->get_fd()); - this->fd = -1; - } - - return retval; -} -#endif
--- a/main/instrument-control/src/serial/serial_class.h Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifndef SERIAL_CLASS_H -#define SERIAL_CLASS_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 -{ -public: - octave_serial(); - ~octave_serial(); - - int write(string /* buffer */); - int write(uint8_t* /* buffer */, unsigned int /* buffer size */); - - int read(uint8_t* /* buffer */, unsigned int /* buffer size */); - - int open(string /* path */, int /* open flags */); - int close(); - int get_fd(); - - int flush(unsigned short /* stream select */); - - int set_timeout(short /* timeout */); - int get_timeout(); - - int set_baudrate(unsigned int /* baudrate */); - int get_baudrate(); - - int set_bytesize(unsigned short /* bytesize */); - int get_bytesize(); - - int set_parity(string /* parity */); - string get_parity(); - - int set_stopbits(unsigned short /* stop bits */); - int get_stopbits(); - - - // 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) 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; - struct termios config; - - volatile bool blocking_read; - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - -#endif
--- a/main/instrument-control/src/serial/srl_baudrate.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_baudrate, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} srl_baudrate (@var{serial}, @var{baudrate})\n \ -@deftypefnx {Loadable Function} {@var{br} = } srl_baudrate (@var{serial})\n \ -\n\ -Set new or get existing serial interface baudrate parameter. Only standard values are supported.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{baudrate} - the baudrate value used. Supported values: 0, 50, 75, 110, \ -134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600 19200, 38400, 57600, \ -115200 and 230400.\n \ -\n\ -If @var{baudrate} parameter is omitted, the srl_baudrate() shall return current baudrate value as the result @var{br}.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || - args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - // Setting new baudrate - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - error("srl_baudrate: expecting second argument of type integer..."); - return octave_value(-1); - } - - serial->set_baudrate(args(1).int_value()); - - return octave_value(); - } - - // Returning current baud rate - return octave_value(serial->get_baudrate()); -#endif -}
--- a/main/instrument-control/src/serial/srl_bytesize.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_bytesize, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} srl_bytesize (@var{serial}, @var{bsize})\n \ -@deftypefnx {Loadable Function} {@var{bs} = } srl_bytesize (@var{serial})\n \ -\n\ -Set new or get existing serial interface byte size parameter.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{bsize} - byte size of type Integer. Supported values: 5/6/7/8.\n \ -\n\ -If @var{bsize} parameter is omitted, the srl_bytesize() shall return current byte size value or in case of unsupported setting -1, as the result @var{bs}.\n \ -@end deftypefn") -{ - #ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - // Setting new byte size - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - serial->set_bytesize(args(1).int_value()); - - return octave_value(); - } - - // Returning current byte size - return octave_value(serial->get_bytesize()); -#endif -}
--- a/main/instrument-control/src/serial/srl_close.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_close, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} srl_close (@var{serial})\n \ -\n\ -Close the interface and release a file descriptor.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() != 1 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - serial->close(); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/serial/srl_flush.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_flush, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} srl_flush (@var{serial}, [@var{q}])\n \ -\n\ -Flush the pending input/output.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{q} - queue selector of type Integer. Supported values: 0 - flush untransmitted output, \ -1 - flush pending input, 2 - flush both pending input and untransmitted output.\n \ -\n\ -If @var{q} parameter is omitted, the srl_flush() shall flush both, input and output buffers.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - // Default arguments - int queue_selector = 2; // Input and Output - - if (args.length() > 1) - { - if (!(args(1).is_integer_type() || args(1).is_float_type())) - { - print_usage(); - return octave_value(-1); - } - - queue_selector = args(1).int_value(); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - serial->flush(queue_selector); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/serial/srl_parity.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_parity, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} srl_parity (@var{serial}, @var{parity})\n \ -@deftypefnx {Loadable Function} {@var{p} = } srl_parity (@var{serial})\n \ -\n\ -Set new or get existing serial interface parity parameter. Even/Odd/None values are supported.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{parity} - parity value of type String. Supported values: Even/Odd/None (case insensitive, can be abbreviated to the first letter only).\n \ -\n\ -If @var{parity} parameter is omitted, the srl_parity() shall return current parity value as the result @var{p}.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - // Setting new parity - if (args.length() > 1) - { - if ( !(args(1).is_string()) ) - { - print_usage(); - return octave_value(-1); - } - - serial->set_parity(args(1).string_value()); - - return octave_value(); - } - - // Returning current parity - return octave_value(serial->get_parity()); -#endif -}
--- a/main/instrument-control/src/serial/srl_read.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include <octave/uint8NDArray.h> -#include <octave/sighandlers.h> - -#include <errno.h> - -#include "serial_class.h" - -extern bool read_interrupt; -static bool type_loaded = false; - -void read_sighandler(int sig) -{ - printf("srl_read: Interrupting...\n\r"); - read_interrupt = true; -} -#endif - -DEFUN_DLD (srl_read, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[@var{data}, @var{count}] = } srl_read (@var{serial}, @var{n})\n \ -\n\ -Read from serial interface.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{n} - number of bytes to attempt to read of type Integer.\n \ -\n\ -The srl_read() shall return number of bytes successfully read in @var{count} as Integer and the bytes themselves in @var{data} as uint8 array.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() != 2 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - unsigned int buffer_len = 0; - - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - buffer_len = args(1).int_value(); - - uint8_t *buffer = NULL; - buffer = new uint8_t[buffer_len + 1]; - - if (buffer == NULL) - { - error("srl_read: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - // Register custom interrupt signal handler - octave_set_signal_handler(SIGINT, read_sighandler); - read_interrupt = false; - - // Read data - int bytes_read = serial->read(buffer, buffer_len); - - // Restore default signal handling - // TODO: a better way? - install_signal_handlers(); - - // Convert data to octave type variables - octave_value_list return_list; - uint8NDArray data( dim_vector(1, bytes_read) ); - - for (int i = 0; i < bytes_read; i++) - data(i) = buffer[i]; - - return_list(0) = data; - return_list(1) = bytes_read; - - delete[] buffer; - - return return_list; -#endif -}
--- a/main/instrument-control/src/serial/srl_stopbits.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_stopbits, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} srl_stopbits (@var{serial}, @var{stopb})\n \ -@deftypefnx {Loadable Function} {@var{sb} = } srl_stopbits (@var{serial})\n \ -\n\ -Set new or get existing serial interface stop bits parameter. Only 1 or 2 stop bits are supported.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{stopb} - number of stop bits used. Supported values: 1, 2.\n \ -\n\ -If @var{stopb} parameter is omitted, the srl_stopbits() shall return current stop bits value as the result @var{sb}.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - // Setting new stop bits - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - serial->set_stopbits(args(1).int_value()); - - return octave_value(); - } - - // Returning current stop bits - return octave_value(serial->get_stopbits()); -#endif -}
--- a/main/instrument-control/src/serial/srl_timeout.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_timeout, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} srl_timeout (@var{serial}, @var{timeout})\n \ -@deftypefnx {Loadable Function} {@var{t} = } srl_timeout (@var{serial})\n \ -\n\ -Set new or get existing serial interface timeout parameter used for srl_read() requests. The timeout value is specified in tenths of a second.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{timeout} - srl_read() timeout value in tenths of a second. Value of -1 means a blocking call. Maximum value of 255 (i.e. 25.5 seconds).\n \ -\n\ -If @var{timeout} parameter is omitted, the srl_timeout() shall return current timeout value as the result @var{t}.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_serial* serial = NULL; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - // Setting new timeout - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - serial->set_timeout(args(1).int_value()); - - return octave_value(); // Should it return by default? - } - - // Returning current timeout - return octave_value(serial->get_timeout()); -#endif -}
--- a/main/instrument-control/src/serial/srl_write.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_SERIAL -#include "serial_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (srl_write, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{n} = } srl_write (@var{serial}, @var{data})\n \ -\n\ -Write data to a serial interface.\n \ -\n\ -@var{serial} - instance of @var{octave_serial} class.@*\ -@var{data} - data to be written to the serial interface. Can be either of String or uint8 type.\n \ -\n\ -Upon successful completion, srl_write() shall return the number of bytes written as the result @var{n}.\n \ -@end deftypefn") -{ -#ifndef BUILD_SERIAL - error("serial: Your system doesn't support the SERIAL interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_serial::register_type(); - type_loaded = true; - } - - if (args.length() != 2 || args(0).type_id() != octave_serial::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_serial *serial = NULL; - int retval; - - const octave_base_value& rep = args(0).get_rep(); - serial = &((octave_serial &)rep); - - if (args(1).is_string()) // String - { - retval = serial->write(args(1).string_value()); - } - else if (args(1).byte_size() == args(1).numel()) // uint8_t - { - NDArray data = args(1).array_value(); - uint8_t *buf = NULL; - buf = new uint8_t[data.length()]; - - if (buf == NULL) - { - error("srl_write: cannot allocate requested memory"); - return octave_value(-1); - } - - for (int i = 0; i < data.length(); i++) - buf[i] = static_cast<uint8_t>(data(i)); - - retval = serial->write(buf, data.length()); - - delete[] buf; - } - else - { - print_usage(); - return octave_value(-1); - } - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/tcp/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -OCT := tcp.oct tcp_timeout.oct tcp_write.oct tcp_close.oct tcp_read.oct -OBJ := tcp_class.o - -MKOCTFILE ?= mkoctfile - -CFLAGS = @DEFS@ -LFLAGS = @TCPLIBS@ - -all: $(OBJ) $(OCT) - -%.o: %.cc - $(MKOCTFILE) $(CFLAGS) -c $^ - -%.oct: %.o - $(MKOCTFILE) $^ $(OBJ) $(LFLAGS) $(TCPLIBS) -o ../$@ - -clean: - rm -f *.oct *.o - -distclean: clean - rm Makefile - -.PHONY: all clean
--- a/main/instrument-control/src/tcp/tcp.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_TCP -#include "tcp_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (tcp, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{tcp} = } tcp ([@var{ipaddress}], [@var{port}], [@var{timeout}])\n \ -\n\ -Open tcp interface.\n \ -\n\ -@var{ipaddress} - the ip address of type String. If omitted defaults to '127.0.0.1'.@* \ -@var{port} - the port number to connect. If omitted defaults to 23.@* \ -@var{timeout} - the interface timeout value. If omitted defaults to blocking call.\n \ -\n\ -The tcp() shall return instance of @var{octave_tcp} class as the result @var{tcp}.\n \ -@end deftypefn") -{ -#ifndef BUILD_TCP - error("tcp: Your system doesn't support the TCO interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_tcp::register_type(); - type_loaded = true; - } - - // Do not open interface if return value is not assigned - if (nargout != 1) - { - print_usage(); - return octave_value(); - } - - // Default values - string address("127.0.0.1"); - int port = 23; - int timeout = -1; - - // Parse the function arguments - if (args.length() > 0) - { - if (args(0).is_string()) - { - address = args(0).string_value(); - } - else - { - print_usage(); - return octave_value(); - } - - } - - // is_float_type() is or'ed to allow expression like ("", 123), without user - // having to use ("", int32(123)), as we still only take "int_value" - if (args.length() > 1) - { - if (args(1).is_integer_type() || args(1).is_float_type()) - { - port = args(1).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - if (args.length() > 2) - { - if (args(2).is_integer_type() || args(2).is_float_type()) - { - timeout = args(2).int_value(); - } - else - { - print_usage(); - return octave_value(); - } - } - - // Open the interface and connect - octave_tcp* retval = new octave_tcp(); - - if (retval->open(address, port) < 0) - { - return octave_value(); - } - - retval->set_timeout(timeout); - - //retval->flush(2); - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/tcp/tcp_class.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,252 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_TCP -#include <iostream> -#include <string> -#include <algorithm> - -#ifndef __WIN32__ -#include <unistd.h> -#include <errno.h> -#include <netinet/in.h> -#include <sys/socket.h> -#include <netdb.h> -#include <arpa/inet.h> -#else -#include <winsock2.h> -#endif - -#ifndef __WIN32__ -#define SOCKETERR errno -#define STRSOCKETERR strerror(errno) -#else -#define SOCKETERR WSAGetLastError() -#define STRSOCKETERR "" -#endif - -using std::string; - -#include "tcp_class.h" - -volatile bool read_interrupt = false; - -DEFINE_OCTAVE_ALLOCATOR (octave_tcp); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_tcp, "octave_tcp", "octave_tcp"); - -octave_tcp::octave_tcp() -{ - this->fd = -1; -} - -int octave_tcp::open(string address, int port) -{ - struct sockaddr_in sin; - int sockerr; - -#ifdef __WIN32__ - WORD wVersionRequested; - WSADATA wsaData; - int err; - - wVersionRequested = MAKEWORD( 2, 2 ); - err = WSAStartup( wVersionRequested, &wsaData ); - if ( err != 0 ) - { - error( "could not initialize winsock library" ); - return -1; - } -#endif - - sin.sin_addr.s_addr = inet_addr(address.c_str()); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - memset(&(sin.sin_zero),0,8*sizeof(char)); - - this->fd = socket(AF_INET, SOCK_STREAM,0); - if (this->fd < 0) - { - error("tcp: error opening socket : %d - %s\n", SOCKETERR, STRSOCKETERR); - octave_tcp::close(); - return -1; - } - - sockerr = connect(this->fd,(struct sockaddr*)&sin, sizeof(struct sockaddr)); - if (sockerr < 0) - { - error("tcp: error on connect : %d - %s\n", SOCKETERR, STRSOCKETERR); - octave_tcp::close(); - return -1; - } - return this->get_fd(); -} - -octave_tcp::~octave_tcp() -{ - this->close(); -} - -void octave_tcp::print (std::ostream& os, bool pr_as_read_syntax ) const -{ - print_raw(os, pr_as_read_syntax); - newline(os); -} - -void octave_tcp::print_raw (std::ostream& os, bool pr_as_read_syntax) const -{ - os << this->fd; -} - -int octave_tcp::read(uint8_t *buf, unsigned int len, int timeout) -{ - - struct timeval tv; - struct timeval *ptv; - - fd_set readfds; - - if (this->get_fd() < 0) - { - error("tcp_read: Interface must be opened first..."); - return 0; - } - - int bytes_read = 0, read_retval = -1; - - // While not interrupted in blocking mode - while (!read_interrupt) - { - /* tv.tv_sec = timeout / 1000; - * tv.tv_usec = (timeout % 1000) * 1000; - */ - - ptv = &tv; - tv.tv_sec = 0; - tv.tv_usec = timeout * 1000; - - // blocking read - if (timeout < 0) - { - ptv = NULL; - } - - FD_ZERO(&readfds); - FD_SET(this->get_fd(),&readfds); - if (::select(this->get_fd()+1,&readfds,NULL,NULL,ptv) < 0) - { - error("tcp_read: Error while reading/select: %d - %s\n", SOCKETERR, STRSOCKETERR); - break; - } - - if (FD_ISSET(this->get_fd(),&readfds)) - { - read_retval = ::recv(get_fd(),reinterpret_cast<char *>((buf + bytes_read)),len - bytes_read,0); - if (read_retval < 0) - { - error("tcp_read: Error while reading: %d - %s\n", SOCKETERR, STRSOCKETERR); - break; - } - } else { - // Timeout - break; - } - - bytes_read += read_retval; - - // Required number of bytes read - if (bytes_read >= len) - break; - - } - - return bytes_read; - -} - -int octave_tcp::write(string str) -{ - if (this->get_fd() < 0) - { - error("tcp: Interface must be opened first..."); - return -1; - } - - return ::send(get_fd(),str.c_str(),str.length(),0); -} - -int octave_tcp::write(uint8_t *buf, unsigned int len) -{ - if (this->get_fd() < 0) - { - error("tcp: Interface must be opened first..."); - return -1; - } - - return ::send(get_fd(), reinterpret_cast<const char *>(buf), len, 0); -} - -int octave_tcp::set_timeout(int timeout) -{ - if (this->get_fd() < 0) - { - error("tcp: Interface must be opened first..."); - return -1; - } - - if (timeout < -1 ) - { - error("tcp_timeout: timeout value must be -1 or positive"); - return -1; - } - - this->timeout = timeout; - - return 1; -} - -int octave_tcp::get_timeout() -{ - return this->timeout; -} - -int octave_tcp::get_fd() -{ - return this->fd; -} - -int octave_tcp::close() -{ - int retval = -1; - - if (this->get_fd() > 0) - { -#ifndef __WIN32__ - retval = ::close(this->get_fd()); -#else - retval = ::closesocket(this->get_fd()); -#endif - this->fd = -1; - } - - return retval; -} -#endif
--- a/main/instrument-control/src/tcp/tcp_class.h Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifndef TCP_CLASS_H -#define TCP_CLASS_H - -#include <octave/oct.h> -#include <octave/ov-int32.h> - -#include <string> - -using std::string; - -class octave_tcp : public octave_base_value -{ -public: - octave_tcp(); - ~octave_tcp(); - - int write(string); - int write(uint8_t *, unsigned int); - - int read(uint8_t *, unsigned int, int); - - int open(string, int); - int close(); - int get_fd(); - - int set_timeout(int); - int get_timeout(); - - // Overloaded base functions - double tcp_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) 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 timeout; - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - -#endif
--- a/main/instrument-control/src/tcp/tcp_close.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_TCP -#include "tcp_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (tcp_close, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} tcp_close (@var{tcp})\n \ -\n\ -Close the interface and release a file descriptor.\n \ -\n\ -@var{tcp} - instance of @var{octave_tcp} class.\n \ -@end deftypefn") -{ -#ifndef BUILD_TCP - error("tcp: Your system doesn't support the TCP interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_tcp::register_type(); - type_loaded = true; - } - - if (args.length() != 1 || args(0).type_id() != octave_tcp::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_tcp* tcp = NULL; - - const octave_base_value& rep = args(0).get_rep(); - tcp = &((octave_tcp &)rep); - - tcp->close(); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/tcp/tcp_read.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_TCP -#include <octave/uint8NDArray.h> -#include <octave/sighandlers.h> - -#include <errno.h> - -#include "tcp_class.h" - -extern bool read_interrupt; -static bool type_loaded = false; - -void read_sighandler(int sig) -{ - printf("tcp_read: Interrupting...\n\r"); - read_interrupt = true; -} -#endif - -DEFUN_DLD (tcp_read, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[@var{data}, @var{count}] = } tcp_read (@var{tcp}, @var{n}, @var{timeout})\n \ -\n\ -Read from tcp interface.\n \ -\n\ -@var{tcp} - instance of @var{octave_tcp} class.@* \ -@var{n} - number of bytes to attempt to read of type Integer@* \ -@var{timeout} - timeout in ms if different from default of type Integer\n \ -\n\ -The tcp_read() shall return number of bytes successfully read in @var{count} as Integer and the bytes themselves in @var{data} as uint8 array.\n \ -@end deftypefn") -{ -#ifndef BUILD_TCP - error("tcp: Your system doesn't support the TCP interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_tcp::register_type(); - type_loaded = true; - } - - if (args.length() < 2 || args.length() > 3 || args(0).type_id() != octave_tcp::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - unsigned int buffer_len = 0; - - if ( !(args(1).is_integer_type() || args(1).is_float_type())) - { - print_usage(); - return octave_value(-1); - } - - if ( args.length() > 2 ) - { - if ( !(args(2).is_integer_type() || args(2).is_float_type())) - { - print_usage(); - return octave_value(-1); - } - } - - buffer_len = args(1).int_value(); - - uint8_t *buffer = NULL; - buffer = new uint8_t[buffer_len + 1]; - - if (buffer == NULL) - { - error("tcp_read: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - octave_tcp* tcp = NULL; - - const octave_base_value& rep = args(0).get_rep(); - tcp = &((octave_tcp &)rep); - - int timeout = tcp->get_timeout(); - if (args.length() == 3) - { - timeout = args(2).int_value(); - } - - // Register custom interrupt signal handler - octave_set_signal_handler(SIGINT, read_sighandler); - read_interrupt = false; - - // Read data - int bytes_read = tcp->read(buffer, buffer_len, timeout); - - // Restore default signal handling - // TODO: a better way? - install_signal_handlers(); - - // Convert data to octave type variables - octave_value_list return_list; - uint8NDArray data( dim_vector(1, bytes_read) ); - - for (int i = 0; i < bytes_read; i++) - data(i) = buffer[i]; - - return_list(0) = data; - return_list(1) = bytes_read; - - delete[] buffer; - - return return_list; -#endif -}
--- a/main/instrument-control/src/tcp/tcp_timeout.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_TCP -#include "tcp_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (tcp_timeout, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} tcp_timeout (@var{tcp}, @var{timeout})\n \ -@deftypefnx {Loadable Function} {@var{t} = } tcp_timeout (@var{tcp})\n \ -\n\ -Set new or get existing tcp interface timeout parameter used for tcp_read() requests. The timeout value is specified in milliseconds.\n \ -\n\ -@var{tcp} - instance of @var{octave_tcp} class.@* \ -@var{timeout} - tcp_read() timeout value in milliseconds. Value of -1 means a blocking call.\n \ -\n\ -If @var{timeout} parameter is omitted, the tcp_timeout() shall return current timeout value as the result @var{t}.\n \ -@end deftypefn") -{ -#ifndef BUILD_TCP - error("tcp: Your system doesn't support the TCP interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_tcp::register_type(); - type_loaded = true; - } - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_tcp::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_tcp* tcp = NULL; - - const octave_base_value& rep = args(0).get_rep(); - tcp = &((octave_tcp &)rep); - - // Setting new timeout - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - tcp->set_timeout(args(1).int_value()); - - return octave_value(); // Should it return by default? - } - - // Returning current timeout - return octave_value(tcp->get_timeout()); -#endif -}
--- a/main/instrument-control/src/tcp/tcp_write.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_TCP -#include "tcp_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (tcp_write, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{n} = } tcp_write (@var{tcp}, @var{data})\n \ -\n\ -Write data to a tcp interface.\n \ -\n\ -@var{tcp} - instance of @var{octave_tcp} class.@* \ -@var{data} - data to be written to the tcp interface. Can be either of String or uint8 type.\n \ -\n\ -Upon successful completion, tcp_write() shall return the number of bytes written as the result @var{n}.\n \ -@end deftypefn") -{ -#ifndef BUILD_TCP - error("tcp: Your system doesn't support the TCP interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_tcp::register_type(); - type_loaded = true; - } - - if (args.length() != 2 || args(0).type_id() != octave_tcp::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_tcp *tcp = NULL; - int retval; - - const octave_base_value& rep = args(0).get_rep(); - tcp = &((octave_tcp &)rep); - - if (args(1).is_string()) // String - { - retval = tcp->write(args(1).string_value()); - } - else if (args(1).byte_size() == args(1).numel()) // uint8_t - { - NDArray data = args(1).array_value(); - uint8_t *buf = NULL; - buf = new uint8_t[data.length()]; - - // memcpy? - if (buf == NULL) - { - error("tcp_write: cannot allocate requested memory"); - return octave_value(-1); - } - - for (int i = 0; i < data.length(); i++) - buf[i] = static_cast<uint8_t>(data(i)); - - retval = tcp->write(buf, data.length()); - - delete[] buf; - } - else - { - print_usage(); - return octave_value(-1); - } - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/usbtmc/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -OCT := usbtmc.oct usbtmc_close.oct usbtmc_write.oct usbtmc_read.oct -OBJ := usbtmc_class.o - -MKOCTFILE ?= mkoctfile - -CFLAGS = @DEFS@ - -all: $(OBJ) $(OCT) - -%.o: %.cc - $(MKOCTFILE) $(CFLAGS) -c $^ - -%.oct: %.o - $(MKOCTFILE) $^ $(OBJ) -o ../$@ - -clean: - rm -f *.oct *.o - -distclean: clean - rm Makefile - -.PHONY: all clean
--- a/main/instrument-control/src/usbtmc/usbtmc.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_USBTMC -#include <fcntl.h> - -using std::string; - -#include "usbtmc_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (usbtmc, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{usbtmc} = } usbtmc (@var{path})\n \ -\n\ -Open usbtmc interface.\n \ -\n\ -@var{path} - the interface path of type String. If omitted defaults to '/dev/usbtmc0'.\n \ -\n\ -The usbtmc() shall return instance of @var{octave_usbtmc} class as the result @var{usbtmc}.\n \ -@end deftypefn") -{ -#ifndef BUILD_USBTMC - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_usbtmc::register_type(); - type_loaded = true; - } - - // Do not open interface if return value is not assigned - if (nargout != 1) - { - print_usage(); - return octave_value(); - } - - // Default values - int oflags = O_RDWR; - string path("/dev/usbtmc0"); - - // Parse the function arguments - if (args.length() > 0) - { - if (args(0).is_string()) - { - path = args(0).string_value(); - } - else - { - print_usage(); - return octave_value(); - } - - } - - octave_usbtmc* retval = new octave_usbtmc(); - - // Open the interface - if (retval->open(path, oflags) < 0) - return octave_value(); - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/usbtmc/usbtmc_class.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_USBTMC -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> - -#include <string> - -using std::string; - -#include "usbtmc_class.h" - -DEFINE_OCTAVE_ALLOCATOR (octave_usbtmc); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_usbtmc, "octave_usbtmc", "octave_usbtmc"); - -octave_usbtmc::octave_usbtmc() -{ - this->fd = -1; -} - -octave_usbtmc::~octave_usbtmc() -{ - this->close(); -} - -int octave_usbtmc::get_fd() -{ - return this->fd; -} - -void octave_usbtmc::print (std::ostream& os, bool pr_as_read_syntax ) const -{ - print_raw(os, pr_as_read_syntax); - newline(os); -} - -void octave_usbtmc::print_raw (std::ostream& os, bool pr_as_read_syntax) const -{ - os << this->fd; -} - -int octave_usbtmc::open(string path, int flags) -{ - this->fd = ::open(path.c_str(), flags, 0); - - if (this->get_fd() < 0) - { - error("usbtmc: Error opening the interface: %s\n", strerror(errno)); - return -1; - } - - return this->get_fd(); -} - -int octave_usbtmc::read(uint8_t *buf, unsigned int len) -{ - if (this->get_fd() < 0) - { - error("usbtmc: Interface must be open first..."); - return -1; - } - - int retval = ::read(get_fd(), buf, len); - - if (retval < 0) - error("usbtmc: Failed to read from the usbtmc bus: %s\n", strerror(errno)); - - return retval; -} - -int octave_usbtmc::write(uint8_t *buf, unsigned int len) -{ - if (this->get_fd() < 0) - { - error("usbtmc: Interface must be open first..."); - return -1; - } - - int retval = ::write(get_fd(), buf, len); - - if (retval < 0) - error("usbtmc: Failed to write to the usbtmc bus: %s\n", strerror(errno)); - - return retval; -} - -int octave_usbtmc::close() -{ - int retval = -1; - - if (this->get_fd() > 0) - { - retval = ::close(this->get_fd()); - this->fd = -1; - } - - return retval; -#endif -}
--- a/main/instrument-control/src/usbtmc/usbtmc_class.h Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifndef USBTMC_CLASS_H -#define USBTMC_CLASS_H - -#include <octave/oct.h> - -#include <string> - -using std::string; - -class octave_usbtmc : public octave_base_value -{ -public: - octave_usbtmc(); - ~octave_usbtmc(); - - int open(string, int); - int close(); - int get_fd(); - - // Simple usbtmc commands - int write(uint8_t*, unsigned int); - int read(uint8_t*, unsigned int); - - - // Overloaded base functions - double usbtmc_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) 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; - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - - -#endif
--- a/main/instrument-control/src/usbtmc/usbtmc_close.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_USBTMC -#include "usbtmc_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (usbtmc_close, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} usbtmc_close (@var{usbtmc})\n \ -\n\ -Close the interface and release a file descriptor.\n \ -\n\ -@var{usbtmc} - instance of @var{octave_usbtmc} class.\n \ -@end deftypefn") -{ -#ifndef BUILD_USBTMC - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_usbtmc::register_type(); - type_loaded = true; - } - - - if (args.length() != 1 || args(0).type_id() != octave_usbtmc::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_usbtmc* usbtmc = NULL; - - const octave_base_value& rep = args(0).get_rep(); - usbtmc = &((octave_usbtmc &)rep); - - usbtmc->close(); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/usbtmc/usbtmc_read.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_USBTMC -#include <octave/uint8NDArray.h> - -#include <errno.h> - -#include "usbtmc_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (usbtmc_read, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[@var{data}, @var{count}] = } usbtmc_read (@var{usbtmc}, @var{n})\n \ -\n\ -Read from usbtmc slave device.\n \ -\n\ -@var{usbtmc} - instance of @var{octave_usbtmc} class.@* \ -@var{n} - number of bytes to attempt to read of type Integer.\n \ -\n\ -The usbtmc_read() shall return number of bytes successfully read in @var{count} as Integer and the bytes themselves in @var{data} as uint8 array.\n \ -@end deftypefn") -{ -#ifndef BUILD_USBTMC - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_usbtmc::register_type(); - type_loaded = true; - } - - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_usbtmc::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - uint8_t *buffer = NULL; - unsigned int buffer_len = 1; - - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - buffer_len = args(1).int_value(); - } - - buffer = new uint8_t [buffer_len + 1]; - - if (buffer == NULL) - { - error("usbtmc_read: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - octave_usbtmc* usbtmc = NULL; - - const octave_base_value& rep = args(0).get_rep(); - usbtmc = &((octave_usbtmc &)rep); - - int retval; - - retval = usbtmc->read(buffer, buffer_len); - - octave_value_list return_list; - uint8NDArray data( dim_vector(1, retval) ); - - for (int i = 0; i < retval; i++) - data(i) = buffer[i]; - - return_list(0) = data; - return_list(1) = retval; - - delete[] buffer; - - return return_list; -#endif -}
--- a/main/instrument-control/src/usbtmc/usbtmc_write.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_USBTMC -#include <errno.h> - -#include "usbtmc_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (usbtmc_write, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{n} = } usbtmc_write (@var{usbtmc}, @var{data})\n \ -\n\ -Write data to a usbtmc slave device.\n \ -\n\ -@var{usbtmc} - instance of @var{octave_usbtmc} class.@* \ -@var{data} - data, of type uint8, to be written to the slave device.\n \ -\n\ -Upon successful completion, usbtmc_write() shall return the number of bytes written as the result @var{n}.\n \ -@end deftypefn") -{ -#ifndef BUILD_USBTMC - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_usbtmc::register_type(); - type_loaded = true; - } - - if (args.length() != 2 || args(0).type_id() != octave_usbtmc::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_usbtmc* usbtmc = NULL; - int retval; - - const octave_base_value& rep = args(0).get_rep(); - usbtmc = &((octave_usbtmc &)rep); - - const octave_base_value& data = args(1).get_rep(); - - if (data.is_string()) - { - string buf = data.string_value(); - retval = usbtmc->write((uint8_t*)buf.c_str(), buf.length()); - } - else if (data.byte_size() == data.numel()) - { - NDArray dtmp = data.array_value(); - uint8_t *buf = NULL; - buf = new uint8_t[dtmp.length()]; - - if (buf == NULL) - { - error("usbtmc_write: cannot allocate requested memory: %s\n", strerror(errno)); - return octave_value(-1); - } - - for (int i = 0; i < dtmp.length(); i++) - buf[i] = static_cast<uint8_t>(dtmp(i)); - - retval = usbtmc->write(buf, dtmp.length()); - - delete[] buf; - } - else - { - print_usage(); - return octave_value(-1); - } - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/vxi11/Makefile.in Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -VXI := vxi11_clnt.o vxi11_xdr.o -OCT := vxi11.oct vxi11_write.oct vxi11_close.oct vxi11_read.oct -OBJ := vxi11_class.o - -MKOCTFILE ?= mkoctfile -RPCGEN ?= rpcgen - -CFLAGS = @RPCINCLUDE@ @DEFS@ -LFLAGS = @RPCLIBS@ - -BUILD_VXI11 = @BUILD_VXI11@ - -ifneq ($(BUILD_VXI11),1) -VXI = -OBJ = -endif - -all: $(VXI) $(OBJ) $(OCT) - -ifeq ($(BUILD_VXI11),1) -vxi11.h vxi11_clnt.c vxi11_xdr.c : vxi11.x - $(RPCGEN) -M vxi11.x -endif - -%.o: %.c - $(MKOCTFILE) $(CFLAGS) $(RPCINCLUDE) -c $^ - -%.o: %.cc - $(MKOCTFILE) $(CFLAGS) $(RPCINCLUDE) -c $^ - -%.oct: %.o - $(MKOCTFILE) $^ $(OBJ) $(VXI) $(LFLAGS) -o ../$@ - -clean: - rm -f *.oct *.o - rm -f vxi11.h vxi11_clnt.c vxi11_xdr.c vxi11_svc.c - -distclean: clean - rm Makefile - -.PHONY: all clean
--- a/main/instrument-control/src/vxi11/vxi11.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_VXI11 -#include <errno.h> - -using std::string; - -#include "vxi11_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (vxi11, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{vxi11} = } vxi11 (@var{ip})\n \ -\n\ -Open vxi11 interface.\n \ -\n\ -@var{path} - the ip address of type String. If omitted defaults to '127.0.0.1'.\n \ -\n\ -The vxi11() shall return instance of @var{octave_vxi11} class as the result @var{vxi11}.\n \ -@end deftypefn") -{ -#ifndef BUILD_VXI11 - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_vxi11::register_type(); - type_loaded = true; - } - - // Do not open interface if return value is not assigned - if (nargout != 1) - { - print_usage(); - return octave_value(); - } - - // Default values - string path("127.0.0.1"); - - // Parse the function arguments - if (args.length() > 0) - { - if (args(0).is_string()) - { - path = args(0).string_value(); - } - else - { - print_usage(); - return octave_value(); - } - - } - - // Open the interface - octave_vxi11* retval = new octave_vxi11; - - if (retval->open(path) < 0) - { - error("vxi11: Error opening the interface: %s\n", strerror(errno)); - return octave_value(); - } - - return octave_value(retval); -#endif -}
--- a/main/instrument-control/src/vxi11/vxi11.x Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,183 +0,0 @@ -% -%/* VXI-11 RPCL definitions. Taken from appendix C of the VXI-11 specfication. -% * See http://www.vxi.org -% */ - -%#include <strings.h> -%#include <stdlib.h> -% -%/* VXI-11 flags */ -%#define VXI11_FLAG_WAITLOCK 0x01 -%#define VXI11_FLAG_ENDW 0x08 -%#define VXI11_FLAG_TERMCHRSET 0x80 -% -%/* VXI-11 device_docmd 'cmd' values */ -%#define VXI11_DOCMD_SEND_COMMAND 0x020000 -%#define VXI11_DOCMD_BUS_STATUS 0x020001 -%#define VXI11_DOCMD_ATN_CONTROL 0x020002 -%#define VXI11_DOCMD_REN_CONTROL 0x020003 -%#define VXI11_DOCMD_PASS_CONTROL 0x020004 -%#define VXI11_DOCMD_BUS_ADDRESS 0x02000A -%#define VXI11_DOCMD_IFC_CONTROL 0x020010 -% -%/* VXI-11 device_docmd Bus Status values */ -%#define VXI11_DOCMD_STAT_REMOTE 1 -%#define VXI11_DOCMD_STAT_SRQ 2 -%#define VXI11_DOCMD_STAT_NDAC 3 -%#define VXI11_DOCMD_STAT_SYS_CTRLR 4 -%#define VXI11_DOCMD_STAT_CTRLR_CHRG 5 -%#define VXI11_DOCMD_STAT_TALKER 6 -%#define VXI11_DOCMD_STAT_LISTENER 7 -%#define VXI11_DOCMD_STAT_BUSADDR 8 -% -%/* VXI-11 device_read 'reason' bits */ -%#define VXI11_REASON_REQCNT 1 /* requested number of bytes read */ -%#define VXI11_REASON_CHR 2 /* read terminated by eos character */ -%#define VXI11_REASON_END 4 /* read terminated by EOI */ -% -%/* VXI-11 errors */ -%#define VXI11_ERR_SUCCESS 0 -%#define VXI11_ERR_SYNTAX 1 -%#define VXI11_ERR_NODEVICE 3 -%#define VXI11_ERR_LINKINVAL 4 -%#define VXI11_ERR_PARAMETER 5 -%#define VXI11_ERR_NOCHAN 6 -%#define VXI11_ERR_NOTSUPP 8 -%#define VXI11_ERR_RESOURCES 9 -%#define VXI11_ERR_LOCKED 11 -%#define VXI11_ERR_NOLOCK 12 -%#define VXI11_ERR_IOTIMEOUT 15 -%#define VXI11_ERR_IOERROR 17 -%#define VXI11_ERR_ADDRINVAL 21 -%#define VXI11_ERR_ABORT 23 -%#define VXI11_ERR_CHANEST 29 - -/* Types */ -typedef long Device_Link; -enum Device_AddrFamily { /* used by interrupts */ - DEVICE_TCP, - DEVICE_UDP -}; -typedef long Device_Flags; - -/* Error types */ -typedef long Device_ErrorCode; -struct Device_Error { - Device_ErrorCode error; -}; - -struct Create_LinkParms { - long clientId; /* implementation specific value */ - bool lockDevice; /* attempt to lock the device */ - unsigned long lock_timeout; /* time to wait on a lock */ - string device<>; /* name of device */ -}; - -struct Create_LinkResp { - Device_ErrorCode error; - Device_Link lid; - unsigned short abortPort; /* for the abort RPC */ - unsigned long maxRecvSize; /* specifies max data size in bytes device will accept on a write */ -}; - -struct Device_WriteParms { - Device_Link lid; /* link id from create_link */ - unsigned long io_timeout; /* time to wait for I/O */ - unsigned long lock_timeout; /* time to wait for lock */ - Device_Flags flags; opaque data<>; /* the data length and the data itself */ -}; - -struct Device_WriteResp { - Device_ErrorCode error; - unsigned long size; /* Number of bytes written */ -}; - -struct Device_ReadParms { - Device_Link lid; /* link id from create_link */ - unsigned long requestSize; /* Bytes requested */ - unsigned long io_timeout; /* time to wait for I/O */ - unsigned long lock_timeout; /* time to wait for lock */ - Device_Flags flags; - char termChar; /* valid if flags & termchrset */ -}; - -struct Device_ReadResp { - Device_ErrorCode error; - long reason; /* Reason(s) read completed */ - opaque data<>; /* data.len and data.val */ -}; - -struct Device_ReadStbResp { - Device_ErrorCode error; /* error code */ - unsigned char stb; /* the returned status byte */ -}; - -struct Device_GenericParms { - Device_Link lid; /* Device_Link id from connect call */ - Device_Flags flags; /* flags with options */ - unsigned long lock_timeout; /* time to wait for lock */ - unsigned long io_timeout; /* time to wait for I/O */ -}; - -struct Device_RemoteFunc { - unsigned long hostAddr; /* Host servicing Interrupt */ - unsigned short hostPort; /* valid port # on client */ - unsigned long progNum; /* DEVICE_INTR */ - unsigned long progVers; /* DEVICE_INTR_VERSION */ - Device_AddrFamily progFamily; /* DEVICE_UDP | DEVICE_TCP */ -}; - -struct Device_EnableSrqParms { - Device_Link lid; - bool enable; /* Enable or disable interrupts */ - opaque handle<40>; /* Host specific data */ -}; - -struct Device_LockParms { - Device_Link lid; /* link id from create_link */ - Device_Flags flags; /* Contains the waitlock flag */ - unsigned long lock_timeout; /* time to wait to acquire lock */ -}; - -struct Device_DocmdParms { - Device_Link lid; /* link id from create_link */ - Device_Flags flags; /* flags specifying various options */ - unsigned long io_timeout; /* time to wait for I/O to complete */ - unsigned long lock_timeout; /* time to wait on a lock */ - long cmd; /* which command to execute */ - bool network_order; /* client's byte order */ - long datasize; /* size of individual data elements */ - opaque data_in<>; /* docmd data parameters */ -}; - -struct Device_DocmdResp { - Device_ErrorCode error; /* returned status */ - opaque data_out<>; /* returned data parameter */ -}; - -program DEVICE_ASYNC{ - version DEVICE_ASYNC_VERSION { - Device_Error device_abort (Device_Link) = 1; - } = 1; -} = 0x0607B0; - -program DEVICE_CORE { - version DEVICE_CORE_VERSION { - Create_LinkResp create_link (Create_LinkParms) = 10; - Device_WriteResp device_write (Device_WriteParms) = 11; - Device_ReadResp device_read (Device_ReadParms) = 12; - Device_ReadStbResp device_readstb (Device_GenericParms) = 13; - Device_Error device_trigger (Device_GenericParms) = 14; - Device_Error device_clear (Device_GenericParms) = 15; - Device_Error device_remote (Device_GenericParms) = 16; - Device_Error device_local (Device_GenericParms) = 17; - Device_Error device_lock (Device_LockParms) = 18; - Device_Error device_unlock (Device_Link) = 19; - Device_Error device_enable_srq (Device_EnableSrqParms) = 20; - Device_DocmdResp device_docmd (Device_DocmdParms) = 22; - Device_Error destroy_link (Device_Link) = 23; - Device_Error create_intr_chan (Device_RemoteFunc) = 25; - Device_Error destroy_intr_chan (void) = 26; - } = 1; -} = 0x0607AF; -
--- a/main/instrument-control/src/vxi11/vxi11_class.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,341 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -// -// VXI11 functions are copied from Steve D. Sharples VXI11 library -// see http://optics.eee.nottingham.ac.uk/vxi11/ -// - -#include <octave/oct.h> - -#include <string> - -// open or close vxi11 session only on call of vxi11 or vxi11_close -#define OPENONCE - -using std::string; - -#include "vxi11_class.h" - -DEFINE_OCTAVE_ALLOCATOR (octave_vxi11); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_vxi11, "octave_vxi11", "octave_vxi11"); - - -#define VXI11_DEFAULT_TIMEOUT 10000 /* in ms */ -#define VXI11_READ_TIMEOUT 2000 /* in ms */ -#define VXI11_MAX_CLIENTS 256 /* maximum no of unique IP addresses/clients */ -#define VXI11_NULL_READ_RESP 50 /* vxi11_receive() return value if a query - * times out ON THE INSTRUMENT (and so we have - * to resend the query again) */ -#define VXI11_NULL_WRITE_RESP 51 /* vxi11_send() return value if a sent command - * times out ON THE INSTURMENT. */ - - - -octave_vxi11::octave_vxi11() -{ - this->ip = ""; -} - -octave_vxi11::~octave_vxi11() -{ - this->close(); -} - -void octave_vxi11::print (std::ostream& os, bool pr_as_read_syntax ) const -{ - print_raw(os, pr_as_read_syntax); - newline(os); -} - -void octave_vxi11::print_raw (std::ostream& os, bool pr_as_read_syntax) const -{ - os << this->ip; -} - -int octave_vxi11::open(string ip) -{ - std::string inst="inst0"; - - this->ip=ip; - -#ifdef OPENONCE - if (this->openvxi(this->ip.c_str(),&this->client,&this->link,inst.c_str())) - { - error("vxi11: Cannot open VXI11..."); - return -1; - } -#endif - return 0; -} - -int octave_vxi11::read(char *buf, unsigned int len) -{ - CLIENT *client; - Create_LinkResp *link; - - unsigned long timeout = VXI11_READ_TIMEOUT; - - if (this->ip.empty()) - { - error("vxi11: setup ip first"); - return -1; - } - -#ifdef OPENONCE - client = this->client; - link = this->link; -#else - std::string inst="inst0"; - if (this->openvxi(this->ip.c_str(),&client,&link,inst.c_str())) - { - error("vxi11: Cannot open VXI11..."); - return -1; - } -#endif - - #define RCV_END_BIT 0x04 // An end indicator has been read - #define RCV_CHR_BIT 0x02 // A termchr is set in flags and a character which matches termChar is transferred - #define RCV_REQCNT_BIT 0x01 // requestSize bytes have been transferred. This includes a request size of zero. - - //long vxi11_receive(CLIENT *client, VXI11_LINK *link, char *buffer, unsigned long len, unsigned long timeout) { - Device_ReadParms read_parms; - Device_ReadResp read_resp; - unsigned int curr_pos = 0; - - read_parms.lid = link->lid; - read_parms.requestSize = len; - read_parms.io_timeout = timeout; /* in ms */ - read_parms.lock_timeout = timeout; /* in ms */ - read_parms.flags = 0; - read_parms.termChar = 0; - - do { - memset(&read_resp, 0, sizeof(read_resp)); - - read_resp.data.data_val = buf + curr_pos; - read_parms.requestSize = len - curr_pos; // Never request more total data than originally specified in len - - if(device_read_1(&read_parms, &read_resp, client) != RPC_SUCCESS) { - error("vxi11: cannot read"); - return -1; /* there is nothing to read. Usually occurs after sending a query - which times out on the instrument. If we don't check this first, - then the following line causes a seg fault */ - } - if (read_resp.error != 0) { - /* Read failed for reason specified in error code. - * (From published VXI-11 protocol, section B.5.2) - * 0 no error - * 1 syntax error - * 3 device not accessible - * 4 invalid link identifier - * 5 parameter error - * 6 channel not established - * 8 operation not supported - * 9 out of resources - * 11 device locked by another link - * 12 no lock held by this link - * 15 I/O timeout - * 17 I/O error - * 21 invalid address - * 23 abort - * 29 channel already established - */ - error("vxi11: cannot read: %d",(int)read_resp.error); - return -1; - } - - if((curr_pos + read_resp.data.data_len) <= len) { - curr_pos += read_resp.data.data_len; - } - if( (read_resp.reason & RCV_END_BIT) || (read_resp.reason & RCV_CHR_BIT) ) { - break; - } - else if( curr_pos == len ) - { - error("xvi11: read error: buffer too small. Read %d bytes without hitting terminator.", (int)curr_pos ); - return -1; - } - } while(1); - -#ifndef OPENONCE - // close VXI11 session - if (this->closevxi(this->ip.c_str(),client,link)) - { - error("vxi11:Cannot close VXI11..."); - return -1; - } -#endif - return curr_pos; -} - -int octave_vxi11::write(const char *buf, int len) -{ - - CLIENT *client; - Create_LinkResp *link; - - if (this->ip.empty()) - { - error("vxi11: setup ip first"); - return -1; - } - -#ifdef OPENONCE - client = this->client; - link = this->link; -#else - std::string inst="inst0"; - if (this->openvxi(this->ip.c_str(),&client,&link,inst.c_str())) - { - error("vxi11: Cannot open VXI11..."); - return -1; - } -#endif - - //int vxi11_send(CLIENT *client, VXI11_LINK *link, const char *cmd, unsigned long len) { - Device_WriteParms write_parms; - unsigned int bytes_left = len; - char *send_cmd; - - send_cmd = new char[len]; - memcpy(send_cmd, buf, len); - - write_parms.lid = link->lid; - write_parms.io_timeout = VXI11_DEFAULT_TIMEOUT; - write_parms.lock_timeout = VXI11_DEFAULT_TIMEOUT; - - /* We can only write (link->maxRecvSize) bytes at a time, so we sit in a loop, - * writing a chunk at a time, until we're done. */ - - do { - Device_WriteResp write_resp; - memset(&write_resp, 0, sizeof(write_resp)); - - if (bytes_left <= link->maxRecvSize) { - write_parms.flags = 8; - write_parms.data.data_len = bytes_left; - } - else - { - write_parms.flags = 0; - /* We need to check that maxRecvSize is a sane value (ie >0). Believe it - * or not, on some versions of Agilent Infiniium scope firmware the scope - * returned "0", which breaks Rule B.6.3 of the VXI-11 protocol. Nevertheless - * we need to catch this, otherwise the program just hangs. */ - if (link->maxRecvSize > 0) { - write_parms.data.data_len = link->maxRecvSize; - } - else - { - write_parms.data.data_len = 4096; /* pretty much anything should be able to cope with 4kB */ - } - } - write_parms.data.data_val = send_cmd + (len - bytes_left); - - if(device_write_1(&write_parms, &write_resp, client) != RPC_SUCCESS) { - delete[] send_cmd; - error("vxi11: cannot write"); - return -VXI11_NULL_WRITE_RESP; /* The instrument did not acknowledge the write, just completely - dropped it. There was no vxi11 comms error as such, the - instrument is just being rude. Usually occurs when the instrument - is busy. If we don't check this first, then the following - line causes a seg fault */ - } - if (write_resp.error != 0) { - error("vxi11_user: write error: %d", (int)write_resp.error); - delete[] send_cmd; - return -(write_resp.error); - } - bytes_left -= write_resp.size; - } while (bytes_left > 0); - - delete[] send_cmd; - -#ifndef OPENONCE - // close VXI11 session - if (this->closevxi(this->ip.c_str(),client,link)) - { - error("vxi11:Cannot close VXI11..."); - return -1; - } -#endif - - return 0; - -} - -int octave_vxi11::close() -{ - int retval = 0; - -#ifdef OPENONCE - // close VXI11 session - if (!this->ip.empty()) - if (this->closevxi(this->ip.c_str(),this->client,this->link)) - { - error("vxi11:Cannot close VXI11..."); - return -1; - } -#endif - this->ip = ""; - - return retval; -} - -int octave_vxi11::openvxi(const char *ip, CLIENT **client, Create_LinkResp **link, const char *device) -{ - *client = clnt_create(ip, DEVICE_CORE, DEVICE_CORE_VERSION, "tcp"); - if (*client == NULL) - { - clnt_pcreateerror(ip); - error("vxi11: Error creating client..."); - return -1; - } - - Create_LinkParms link_parms; - - /* Set link parameters */ - link_parms.clientId = (long) *client; - link_parms.lockDevice = 0; - link_parms.lock_timeout = VXI11_DEFAULT_TIMEOUT; - link_parms.device = (char *) device; - - *link = (Create_LinkResp *) calloc(1, sizeof(Create_LinkResp)); - - if (create_link_1(&link_parms, *link, *client) != RPC_SUCCESS) - { - clnt_perror(*client, ip); - error("vxi11: Error creating client..."); - return -2; - } - return 0; -} - -int octave_vxi11::closevxi(const char *ip, CLIENT *client, Create_LinkResp *link) -{ - Device_Error dev_error; - memset(&dev_error, 0, sizeof(dev_error)); - - if (destroy_link_1(&link->lid, &dev_error, client) != RPC_SUCCESS) - { - clnt_perror(client,ip); - return -1; - } - - clnt_destroy(client); - return 0; -}
--- a/main/instrument-control/src/vxi11/vxi11_class.h Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#ifndef VXI11_CLASS_H -#define VXI11_CLASS_H - -#include <octave/oct.h> - -#include <rpc/rpc.h> -#include "vxi11.h" - -#include <string> - -using std::string; - -class octave_vxi11 : public octave_base_value -{ -public: - octave_vxi11(); - ~octave_vxi11(); - - int open(string); - int close(); - - // Simple vxi11 commands - int write(const char*, int); - int read(char*, unsigned int); - - // Overloaded base functions - string vxi11_value() const - { - return (string)this->ip; - } - - virtual double scalar_value (bool frc_str_conv = false) const - { - return (double)0; - } - - 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: - CLIENT *client; - Create_LinkResp *link; - std::string ip; - std::string device; - - int openvxi(const char *, CLIENT **, Create_LinkResp **, const char *); - int closevxi(const char *, CLIENT *, Create_LinkResp *); - - DECLARE_OCTAVE_ALLOCATOR - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - - -#endif
--- a/main/instrument-control/src/vxi11/vxi11_close.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_VXI11 -#include "vxi11_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (vxi11_close, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} vxi11_close (@var{vxi11})\n \ -\n\ -Close the interface and release a file descriptor.\n \ -\n\ -@var{vxi11} - instance of @var{octave_vxi11} class.\n \ -@end deftypefn") -{ -#ifndef BUILD_VXI11 - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_vxi11::register_type(); - type_loaded = true; - } - - - if (args.length() != 1 || args(0).type_id() != octave_vxi11::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_vxi11* vxi11 = NULL; - - const octave_base_value& rep = args(0).get_rep(); - vxi11 = &((octave_vxi11 &)rep); - - vxi11->close(); - - return octave_value(); -#endif -}
--- a/main/instrument-control/src/vxi11/vxi11_read.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_VXI11 -#include <octave/uint8NDArray.h> - -#include "vxi11_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (vxi11_read, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {[@var{data}, @var{count}] = } vxi11_read (@var{vxi11}, @var{n})\n \ -\n\ -Read from vxi11 slave device.\n \ -\n\ -@var{vxi11} - instance of @var{octave_vxi11} class.@* \ -@var{n} - number of bytes to attempt to read of type Integer.\n \ -\n\ -The vxi11_read() shall return number of bytes successfully read in @var{count} as Integer and the bytes themselves in @var{data} as uint8 array.\n \ -@end deftypefn") -{ -#ifndef BUILD_VXI11 - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_vxi11::register_type(); - type_loaded = true; - } - - - if (args.length() < 1 || args.length() > 2 || args(0).type_id() != octave_vxi11::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - char *buffer = NULL; - unsigned int buffer_len = 1; - - if (args.length() > 1) - { - if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) - { - print_usage(); - return octave_value(-1); - } - - buffer_len = args(1).int_value(); - } - - buffer = new char [buffer_len + 1]; - - if (buffer == NULL) - { - error("vxi11_read: cannot allocate requested memory..."); - return octave_value(-1); - } - - octave_vxi11* vxi11 = NULL; - - const octave_base_value& rep = args(0).get_rep(); - vxi11 = &((octave_vxi11 &)rep); - - int retval; - - retval = vxi11->read(buffer, buffer_len); - - octave_value_list return_list; - - uint8NDArray data( dim_vector(1, (retval > 0) ? retval : 0) ); - - for (int i = 0; i < retval; i++) - data(i) = static_cast<uint8_t>(buffer[i]); - - return_list(0) = data; - return_list(1) = retval; - - - delete[] buffer; - - return return_list; -#endif -}
--- a/main/instrument-control/src/vxi11/vxi11_write.cc Tue Jul 23 19:35:06 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -// Copyright (C) 2013 Stefan Mahr <dac922@gmx.de> -// Copyright (C) 2012 Andrius Sutas <andrius.sutas@gmail.com> -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, see <http://www.gnu.org/licenses/>. - -#include <octave/oct.h> - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef BUILD_VXI11 -#include "vxi11_class.h" - -static bool type_loaded = false; -#endif - -DEFUN_DLD (vxi11_write, args, nargout, -"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{n} = } vxi11_write (@var{vxi11}, @var{data})\n \ -\n\ -Write data to a vxi11 slave device.\n \ -\n\ -@var{vxi11} - instance of @var{octave_vxi11} class.@* \ -@var{data} - data to be written to the slave device. Can be either of String or uint8 type.\n \ -\n\ -Upon successful completion, vxi11_write() shall return the number of bytes written as the result @var{n}.\n \ -@end deftypefn") -{ -#ifndef BUILD_VXI11 - error("usbtmc: Your system doesn't support the USBTMC interface"); - return octave_value(); -#else - if (!type_loaded) - { - octave_vxi11::register_type(); - type_loaded = true; - } - - - if (args.length() != 2 || args(0).type_id() != octave_vxi11::static_type_id()) - { - print_usage(); - return octave_value(-1); - } - - octave_vxi11* vxi11 = NULL; - - const octave_base_value& rep = args(0).get_rep(); - vxi11 = &((octave_vxi11 &)rep); - - const octave_base_value& data = args(1).get_rep(); - int retval; - - if (data.is_string()) - { - string buf = data.string_value(); - retval = vxi11->write(buf.c_str(), buf.length()); - } - else if (data.byte_size() == data.numel()) - { - NDArray dtmp = data.array_value(); - char* buf = new char [dtmp.length()]; - - for (int i = 0; i < dtmp.length(); i++) - buf[i] = (char)dtmp(i); - - retval = vxi11->write(buf, data.byte_size()); - - delete[] buf; - } - else - { - print_usage(); - return octave_value(-1); - } - - return octave_value(retval); -#endif -}