Esempio n. 1
0
def main():
    if len(sys.argv) != 2:
        print "usage: %s chain.xml" % (sys.argv[0])
        sys.exit(1)
    chainfile = sys.argv[1]

    import libxml2
    doc = libxml2.parseFile(chainfile)

    chain = ethercat.EthercatChain()
    chainPorts = {}  # dictionary of chainElements by port name
    sdoDict = {}  # sdos indexed by sdo name

    for d in doc.xpathEval("//device") + doc.xpathEval(
            "//ethercat.EthercatSlave"):
        type_names = d.xpathEval("@type_name")
        if type_names:
            name = type_names[0].content
            revision = ethercat.parseInt(d.xpathEval("@revision")[0].content)
            type_rev = "%s rev 0x%08x" % (name, revision)
        else:
            type_rev = d.xpathEval("@type_rev")[0].content
        position = d.xpathEval("@position")[0].content
        if not position.startswith("DCS"):
            position = ethercat.parseInt(position)
        portname = d.xpathEval("@name")[0].content
        oversample = 0
        oversample_xml = d.xpathEval("@oversample")
        if len(oversample_xml):
            oversample = ethercat.parseInt(
                d.xpathEval("@oversample")[0].content)
        chainElem = ethercat.EthercatChainElem(type_rev, position, portname,
                                               oversample)
        chainPorts[portname] = chainElem
        chain.setDevice(chainElem)
    for d in doc.xpathEval("//ethercat.PdoAssignment"):
        slave = d.xpathEval("@slave")[0].content
        pdo_index = ethercat.parseInt(d.xpathEval("@pdo_index")[0].content)
        smnumber = ethercat.parseInt(d.xpathEval("@smnumber")[0].content)
        # name= d.xpathEval("@name")[0].content
        chainPorts[slave].assignPdo(smnumber, pdo_index)
    for d in doc.xpathEval("//ethercat.SdoControl"):
        name = d.xpathEval("@name")[0].content
        slave_name = d.xpathEval("@slave")[0].content
        index = ethercat.parseInt(d.xpathEval("@index")[0].content)
        sdo = ethercat.Sdo(name, slave_name, index)
        chainPorts[slave_name].assignSdo(sdo)
        sdoDict[name] = sdo
    for d in doc.xpathEval("//ethercat.SdoEntryControl"):
        asynparameter = d.xpathEval("@asynparameter")[0].content
        bit_length = ethercat.parseInt(d.xpathEval("@bit_length")[0].content)
        description = d.xpathEval("@description")[0].content
        name = d.xpathEval("@name")[0].content
        parentsdo = sdoDict[d.xpathEval("@parentsdo")[0].content]
        subindex = ethercat.parseInt(d.xpathEval("@subindex")[0].content)
        sdoentry = ethercat.SdoEntry(parentsdo, name, asynparameter,
                                     description, subindex, bit_length)
    ethercat.initialise()
    chain.getDeviceDescriptions()
    print chain.generateMasterXml()
def main():
    if len(sys.argv) != 2:
        print "usage: %s chain.xml" % (sys.argv[0])
        sys.exit(1)
    chainfile = sys.argv[1]

    import libxml2
    doc = libxml2.parseFile(chainfile)

    chain = ethercat.EthercatChain()

    for d in doc.xpathEval("//device") + doc.xpathEval("//ethercat.EthercatSlave"):
        type_names = d.xpathEval("@type_name")
        if type_names:
            name = type_names[0].content
            revision = ethercat.parseInt(d.xpathEval("@revision")[0].content)
            type_rev = "%s rev 0x%08x" % (name, revision)
        else:
            type_rev = d.xpathEval("@type_rev")[0].content
        position = d.xpathEval("@position")[0].content
        if not position.startswith("DCS"):
            position = ethercat.parseInt(position)
        portname = d.xpathEval("@name")[0].content
        oversample = 0
        oversample_xml = d.xpathEval("@oversample")
        if len(oversample_xml):
           oversample = ethercat.parseInt(d.xpathEval("@oversample")[0].content)
        chainElem = ethercat.EthercatChainElem(type_rev, position, portname, oversample)
        chain.setDevice(chainElem)
        
    ethercat.initialise()
    chain.getDeviceDescriptions()
    print chain.generateMasterXml()
Esempio n. 3
0
def main():
    if len(sys.argv) != 2:
        print "usage: %s chain.xml" % (sys.argv[0])
        sys.exit(1)
    chainfile = sys.argv[1]

    import libxml2
    doc = libxml2.parseFile(chainfile)

    chain = ethercat.EthercatChain()
    chainPorts = {} # dictionary of chainElements by port name
    sdoDict = {} # sdos indexed by sdo name

    for d in doc.xpathEval("//device") + doc.xpathEval("//ethercat.EthercatSlave"):
        type_names = d.xpathEval("@type_name")
        if type_names:
            name = type_names[0].content
            revision = ethercat.parseInt(d.xpathEval("@revision")[0].content)
            type_rev = "%s rev 0x%08x" % (name, revision)
        else:
            type_rev = d.xpathEval("@type_rev")[0].content
        position = d.xpathEval("@position")[0].content
        if not position.startswith("DCS"):
            position = ethercat.parseInt(position)
        portname = d.xpathEval("@name")[0].content
        oversample = 0
        oversample_xml = d.xpathEval("@oversample")
        if len(oversample_xml):
           oversample = ethercat.parseInt(d.xpathEval("@oversample")[0].content)
        chainElem = ethercat.EthercatChainElem(type_rev, position, portname, oversample)
        chainPorts[portname] = chainElem
        chain.setDevice(chainElem)
    for d in doc.xpathEval("//ethercat.PdoAssignment"):
        slave = d.xpathEval("@slave")[0].content
        pdo_index = ethercat.parseInt(d.xpathEval("@pdo_index")[0].content)
        smnumber= ethercat.parseInt(d.xpathEval("@smnumber")[0].content)
        # name= d.xpathEval("@name")[0].content
        chainPorts[slave].assignPdo(smnumber, pdo_index)
    for d in doc.xpathEval("//ethercat.SdoControl"):
        name = d.xpathEval("@name")[0].content
        slave_name = d.xpathEval("@slave")[0].content
        index = ethercat.parseInt(d.xpathEval("@index")[0].content)
        sdo = ethercat.Sdo(name, slave_name, index)
        chainPorts[slave_name].assignSdo(sdo)
        sdoDict[name] = sdo
    for d in doc.xpathEval("//ethercat.SdoEntryControl"):
        asynparameter = d.xpathEval("@asynparameter")[0].content
        bit_length = ethercat.parseInt(d.xpathEval("@bit_length")[0].content)
        description = d.xpathEval("@description")[0].content
        name = d.xpathEval("@name")[0].content
        parentsdo = sdoDict[d.xpathEval("@parentsdo")[0].content]
        subindex = ethercat.parseInt(d.xpathEval("@subindex")[0].content)
        sdoentry = ethercat.SdoEntry(parentsdo, name,
                                     asynparameter, description,
                                     subindex, bit_length)
    ethercat.initialise()
    chain.getDeviceDescriptions()
    print chain.generateMasterXml()
Esempio n. 4
0
def keyRepr(key):
    (typename, revision) = key
    return "%s %d" % (typename, revision)


if __name__ == "__main__":
    if len(sys.argv) >= 2:
        if sys.argv[1] == "-a":
            sys.argv.pop(1)
            doFilter = False
        if sys.argv[1] == "-h":
            usage()
    else:
        usage()
    ethercat.initialise()
    while len(sys.argv) > 1:
        print("processing %s" % sys.argv[1])
        dev_set = ethercat.getDescriptions(sys.argv[1])
        # filtered set
        fset = dev_set
        if dev_set and doFilter:
            fset = ethercat.filteredDescriptions(dev_set)
        if fset:
            print """File: %(name)s
Number of entries: %(count)d (Filter: %(filtered)s)
""" % dict(name=sys.argv[1], count=len(fset), filtered=doFilter)
            for k in sorted(fset.keys(), key=keyRepr):
                print "%s rev 0x%08x" % k
        else:
            print("File: %(name)s has no descriptions" %
         %s [-a]

Names returned are filtered to reflect only devices supported at DLS
Options:
    -a  Shows all devices, does not filter for DLS supported devices""" % __file__
    sys.exit(1)

doFilter = True

def getDiamondDeviceSet():
    '''return list of devices filtered according to diamondFilter'''
    if doFilter:
        return ethercat.filteredDescriptions(ethercat.getAllDevices())
    else:
        return ethercat.getAllDevices()

def keyRepr(key):
    ( typename, revision ) = key
    return "%s %d" % (typename, revision)

if __name__ == "__main__":
    if len(sys.argv) > 1:
        if sys.argv[1] == "-a":
            doFilter = False
        if sys.argv[1] == "-h":
            usage()
    ethercat.initialise()
    dev_set = getDiamondDeviceSet()
    for k in sorted(dev_set.keys(), key=keyRepr):
        print "%s rev 0x%08x" % k
Esempio n. 6
0
 def setUp(self):
     ethercat.initialise()