tool/CommandRescan.cpp
changeset 1961 48f536aefc18
child 1968 4f682084c643
equal deleted inserted replaced
1960:6c4269dca1c2 1961:48f536aefc18
       
     1 /*****************************************************************************
       
     2  *
       
     3  *  $Id$
       
     4  *
       
     5  *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
       
     6  *
       
     7  *  This file is part of the IgH EtherCAT Master.
       
     8  *
       
     9  *  The IgH EtherCAT Master is free software; you can redistribute it and/or
       
    10  *  modify it under the terms of the GNU General Public License version 2, as
       
    11  *  published by the Free Software Foundation.
       
    12  *
       
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
       
    14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
       
    16  *  Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License along
       
    19  *  with the IgH EtherCAT Master; if not, write to the Free Software
       
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    21  *
       
    22  *  ---
       
    23  *
       
    24  *  The license mentioned above concerns the source code only. Using the
       
    25  *  EtherCAT technology and brand is only permitted in compliance with the
       
    26  *  industrial property and similar rights of Beckhoff Automation GmbH.
       
    27  *
       
    28  *  vim: expandtab
       
    29  *
       
    30  ****************************************************************************/
       
    31 
       
    32 #include <sstream>
       
    33 #include <iomanip>
       
    34 using namespace std;
       
    35 
       
    36 #include "CommandRescan.h"
       
    37 #include "MasterDevice.h"
       
    38 
       
    39 /*****************************************************************************/
       
    40 
       
    41 CommandRescan::CommandRescan():
       
    42     Command("rescan", "Rescan the bus.")
       
    43 {
       
    44 }
       
    45 
       
    46 /*****************************************************************************/
       
    47 
       
    48 string CommandRescan::helpString() const
       
    49 {
       
    50     stringstream str;
       
    51 
       
    52     str << getName() << endl
       
    53         << endl
       
    54         << getBriefDescription() << endl
       
    55         << endl
       
    56         << "Command a bus rescan. Gathered slave information will be" << endl
       
    57         << "forgotten and slaves will be read in again." << endl
       
    58         << endl;
       
    59 
       
    60     return str.str();
       
    61 }
       
    62 
       
    63 /****************************************************************************/
       
    64 
       
    65 void CommandRescan::execute(const StringVector &args)
       
    66 {
       
    67 	MasterIndexList masterIndices;
       
    68     
       
    69     if (args.size() != 0) {
       
    70         stringstream err;
       
    71         err << "'" << getName() << "' takes no arguments!";
       
    72         throwInvalidUsageException(err);
       
    73     }
       
    74 
       
    75 	masterIndices = getMasterIndices();
       
    76     MasterIndexList::const_iterator mi;
       
    77     for (mi = masterIndices.begin();
       
    78             mi != masterIndices.end(); mi++) {
       
    79         MasterDevice m(*mi);
       
    80         m.open(MasterDevice::ReadWrite);
       
    81         m.rescan();
       
    82     }
       
    83 }
       
    84 
       
    85 /*****************************************************************************/