File: instrhwinfo.m

package info (click to toggle)
octave-instrument-control 0.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 860 kB
  • sloc: cpp: 5,846; makefile: 436; ansic: 18; sh: 4
file content (101 lines) | stat: -rw-r--r-- 3,074 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
## Copyright (C) 2018 John Donoghue <john.donoghue@ieee.org>
## Copyright (C) 2016 Andreas Weber <andy.weber.aw@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/>.

## -*- texinfo -*-
## @deftypefn {Function File} {[@var{list}] =} instrhwinfo ()
## @deftypefnx {Function File} {@var{list} =} instrhwinfo (@var{interface})
## Query available hardware for instrument-control
##
## When run without any input parameters, instrhwinfo will provide the toolbox
## information and a list of supported interfaces.
##
## If an output variable is provided, the function will store the information
## to the variable, otherwise it will be displayed to the screeen.
##
## @example
## instrhwinfo
## scalar structure containing the fields:
##
##    ToolboxVersion = 0.3.0
##    ToolboxName = octave instrument control package
##    SupportedInterfaces =
##    @{
##      [1,1] = i2c
##      [1,2] = parallel
##      [1,3] = serial
##      [1,4] = tcp
##      [1,5] = udp
##      [1,6] = usbtmc
##      [1,7] = vxi11
##    @}
##
## @end example
##
## @var{interface} is the instrument interface to query. When provided, instrhwinfo
## will provide information on the specified interface.
##
## Currently only interface "serial" is supported, which will provide a list of
## available serial ports.
## @end deftypefn

function out = instrhwinfo (interface)

  if (nargin == 0)
    a = __instr_hwinfo__();
    if (nargout == 0)
      disp(a);
    else
      out = a;
    endif
  elseif (nargin != 1)
    print_usage ();
  elseif (strcmpi (interface, "serial"))

    if (ispc ()) # windoze

      Skey = 'HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM';
      ## Find connected serial devices and clean up the output
      [~, list] = dos(['REG QUERY ' Skey]);
      [~, ~, ~, out]=regexp (list, "COM[0-9]+");

    elseif (isunix ()) # GNU/Linux, BSD...

      ## only devices with device/driver
      tmp = glob ("/sys/class/tty/*/device/driver");
      tmp = strrep (tmp, "/sys/class/tty/", "");
      out = strrep (tmp, "/device/driver", "");

    endif
   else
    error ("Interface '%s' not yet implemented...", interface);
  endif

endfunction

%!test
%! a = instrhwinfo();
%! assert(! isempty (a))

%!xtest
%! # could fail if no serial ports?
%! assert(!isempty(instrhwinfo("serial")))

%!error <Invalid call to instrhwinfo> instrhwinfo("serial", "2ndarg")

%!xtest
%! p = pkg('list', 'instrument-control');
%! hw = instrhwinfo ();
%! assert (hw.ToolboxVersion, p{1}.version)