[etherlab-dev] Xml output of ethercat (tool)
Erwin Burgstaller
ethercat.berknapp at spamgourmet.com
Mon Apr 27 13:59:29 CEST 2009
* Fri, Apr 24, 2009 - 14:27:33 +0200, Florian Pose - fp at igh-essen.com:
> On Fri, Apr 24, 2009 at 12:26:35PM +0200, Erwin Burgstaller wrote:
> > The name could be EtherCATInfoList for example, any better names?
> >
> > And attached there's a little patch for the file
> > ''tool/CommandXml.cpp'', which would solve that. The patch works from
> > Version 1.4 up to devel-r1713.
> >
> > What do you think about?
>
> The generated XML documents shall conform to the XML device description
> schema. Generally adding a new top-level element will break this.
>
> I think there are two solutions:
>
> - Retrieving the XMLs one-by-one with the --alias and --position
> options, or
>
> - Adding a --list option that adds the <EtherCATInfoList> tag
> optionally.
>
OK, there's a third one.
The output from 'ethercat xml' is not that very useful as you'll have to
use an editor to split it up into files easily. So it's anyway better to
call it just for a certain slave to get a valid XML-document.
An bash script example of building different XML-Files (one for each
attached device type) would be this:
for pos in `ethercat slaves|cut -f1 -d' '`; \
do ethercat xml -p $pos >/tmp/`ethercat slave -p $pos|cut -f9 -d' '`.xml; \
done
Or one for each slave:
for pos in `ethercat slaves|cut -f1 -d' '`; \
do ethercat xml -p $pos >/tmp/`ethercat slave -p $pos|cut -f9 -d' '`-$pos.xml; \
done
So it makes more sense to distinguish between calls with parameter -p and
ones which were called for all slaves, which could simply be done like
this:
cout << "<?xml version=\"1.0\" ?>" << endl;
if (slaves.size() > 1) {
cout << "<EtherCATInfoList>" << endl;
}
for (si = slaves.begin(); si != slaves.end(); si++) {
generateSlaveXml(m, *si);
}
if (slaves.size() > 1) {
cout << "</EtherCATInfoList>" << endl;
}
So both variants (ethercat xml and ethercat xml -p <x>) would produce
valid XML-documents. :-)
Of course, above if-statements could validate an command line option
instead, would work for me too. ;-)
Patch attached,
Erwin
--
Erwin Burgstaller
-------------- next part --------------
--- /tmp/ethercat-devel-r1718/tool/CommandXml.cpp 2009-03-19 09:43:05.000000000 +0100
+++ CommandXml.cpp 2009-04-27 12:34:32.954471517 +0200
@@ -82,9 +82,18 @@
m.open(MasterDevice::Read);
slaves = selectedSlaves(m);
+ cout << "<?xml version=\"1.0\" ?>" << endl;
+ if (slaves.size() > 1) {
+ cout << "<EtherCATInfoList>" << endl;
+ }
+
for (si = slaves.begin(); si != slaves.end(); si++) {
generateSlaveXml(m, *si);
}
+
+ if (slaves.size() > 1) {
+ cout << "</EtherCATInfoList>" << endl;
+ }
}
/****************************************************************************/
@@ -101,7 +110,6 @@
unsigned int i, j, k;
cout
- << "<?xml version=\"1.0\" ?>" << endl
<< " <EtherCATInfo>" << endl
<< " <!-- Slave " << slave.position << " -->" << endl
<< " <Vendor>" << endl
@@ -202,8 +210,8 @@
cout
<< " </Device>" << endl
- << " </Devices>" << endl
- << " </Descriptions>" << endl
- << "</EtherCATInfo>" << endl;
+ << " </Devices>" << endl
+ << " </Descriptions>" << endl
+ << " </EtherCATInfo>" << endl;
}
/*****************************************************************************/
More information about the Etherlab-dev
mailing list