tool/CommandSoeRead.cpp
author Florian Pose <fp@igh-essen.com>
Fri, 03 Mar 2017 17:08:39 +0100
changeset 2678 f5ffd1875da1
parent 1968 4f682084c643
permissions -rw-r--r--
Clear unused ports; use arrows for next slaves.
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 ****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <iostream>
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    31
#include <iomanip>
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
using namespace std;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include "CommandSoeRead.h"
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include "MasterDevice.h"
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
/*****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
CommandSoeRead::CommandSoeRead():
1966
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1953
diff changeset
    40
    Command("soe_read", "Read an SoE IDN from a slave.")
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
{
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
/*****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    46
string CommandSoeRead::helpString(const string &binaryBaseName) const
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
{
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    stringstream str;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    50
    str << binaryBaseName << " " << getName()
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    51
        << " [OPTIONS] <IDN>" << endl
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    52
        << binaryBaseName << " " << getName()
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    53
        << " [OPTIONS] <DRIVE> <IDN>" << endl
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << getBriefDescription() << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        << "This command requires a single slave to be selected." << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
        << "Arguments:" << endl
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    60
        << "  DRIVE    is the drive number (0 - 7). If omitted, 0 is assumed."
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    61
        << endl
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    62
        << "  IDN      is the IDN and must be either an unsigned" << endl
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    63
        << "           16 bit number acc. to IEC 61800-7-204:" << endl
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    64
        << "             Bit 15: (0) Standard data, (1) Product data" << endl
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    65
        << "             Bit 14 - 12: Parameter set (0 - 7)" << endl
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    66
        << "             Bit 11 - 0: Data block number" << endl
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    67
        << "           or a string like 'P-0-150'." << endl
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    68
        << endl
1872
23d4e121faaf Improved SoE command help.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
    69
        << "Data of the given IDN are read and displayed according to" << endl
23d4e121faaf Improved SoE command help.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
    70
        << "the given datatype, or as raw hex bytes." << endl
23d4e121faaf Improved SoE command help.
Florian Pose <fp@igh-essen.com>
parents: 1870
diff changeset
    71
        << endl
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    72
        << typeInfo()
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
        << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
        << "Command-specific options:" << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
        << "  --alias    -a <alias>" << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        << "  --position -p <pos>    Slave selection. See the help of" << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        << "                         the 'slaves' command." << endl
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    78
        << "  --type     -t <type>   Data type (see above)." << endl
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        << endl
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        << numericInfo();
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    return str.str();
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
/****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
void CommandSoeRead::execute(const StringVector &args)
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
{
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    SlaveList slaves;
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
    90
    stringstream err;
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
    91
    const DataType *dataType = NULL;
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
    92
    ec_ioctl_slave_soe_read_t ioctl;
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    93
    int driveArgIndex = -1, idnArgIndex = -1;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    95
    if (args.size() == 1) {
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    96
        idnArgIndex = 0;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    97
    } else if (args.size() == 2) {
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    98
        driveArgIndex = 0;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
    99
        idnArgIndex = 1;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   100
    } else {
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   101
        err << "'" << getName() << "' takes eiter 1 or 2 arguments!";
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
        throwInvalidUsageException(err);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   105
    if (driveArgIndex >= 0) {
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   106
        stringstream str;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   107
        unsigned int number;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   108
        str << args[driveArgIndex];
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   109
        str
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   110
            >> resetiosflags(ios::basefield) // guess base from prefix
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   111
            >> number;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   112
        if (str.fail() || number > 7) {
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   113
            err << "Invalid drive number '" << args[driveArgIndex] << "'!";
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   114
            throwInvalidUsageException(err);
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   115
        }
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   116
        ioctl.drive_no = number;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   117
    } else {
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   118
        ioctl.drive_no = 0;
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   119
    }
1953
968a531e5a89 Always set drive_no to zero in ethercat tool (TBC).
Florian Pose <fp@igh-essen.com>
parents: 1877
diff changeset
   120
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   121
    try {
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   122
        ioctl.idn = parseIdn(args[idnArgIndex]);
1868
489ea0becd74 Implemented SoE IDN parser for strings like 'P-0-0150'; moved data type
Florian Pose <fp@igh-essen.com>
parents: 1837
diff changeset
   123
    } catch (runtime_error &e) {
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
   124
        err << "Invalid IDN '" << args[idnArgIndex] << "': " << e.what();
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
        throwInvalidUsageException(err);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
1870
0cee1fb7f0fd Added getSingleMasterIndex() for command-line tool.
Florian Pose <fp@igh-essen.com>
parents: 1869
diff changeset
   128
    MasterDevice m(getSingleMasterIndex());
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    m.open(MasterDevice::Read);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
    slaves = selectedSlaves(m);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    if (slaves.size() != 1) {
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        throwSingleSlaveRequired(slaves.size());
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
    }
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   134
    ioctl.slave_position = slaves.front().position;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   136
    if (getDataType().empty()) {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   137
        dataType = findDataType("raw"); // FIXME
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   138
    } else { // no data type specified
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   139
        if (!(dataType = findDataType(getDataType()))) {
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   140
            err << "Invalid data type '" << getDataType() << "'!";
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   141
            throwInvalidUsageException(err);
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   142
        }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   143
    }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   144
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   145
    if (dataType->byteSize) {
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   146
        ioctl.mem_size = dataType->byteSize;
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   147
    } else {
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   148
        ioctl.mem_size = 1024;
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   149
    }
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   150
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   151
    ioctl.data = new uint8_t[ioctl.mem_size + 1];
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
    try {
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   154
        m.readSoe(&ioctl);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    } catch (MasterDeviceSoeException &e) {
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   156
        delete [] ioctl.data;
1877
7b77000f9764 Included list of common SoE error messages.
Florian Pose <fp@igh-essen.com>
parents: 1872
diff changeset
   157
        err << "SoE read command failed with code " << errorMsg(e.errorCode);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
        throwCommandException(err);
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
    } catch (MasterDeviceException &e) {
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   160
        delete [] ioctl.data;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        throw e;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    m.close();
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   166
    try {
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   167
        outputData(cout, dataType, ioctl.data, ioctl.data_size);
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   168
    } catch (SizeException &e) {
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   169
        delete [] ioctl.data;
1835
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   170
        throwCommandException(e.what());
20748e9d2238 Sourced out data type handling into an own class.
Florian Pose <fp@igh-essen.com>
parents: 1832
diff changeset
   171
    }
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1835
diff changeset
   173
    delete [] ioctl.data;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
/*****************************************************************************/