Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #
- #-------------------------------------------------------
- # Usage : python CreateHALfromXML.py > HalFile.hal
- #-------------------------------------------------------
- import xmlBiesse
- #from time import time, gmtime, strftime
- import time
- xBiesse = xmlBiesse.xmlBiesse() # the xml interface
- #----------------------------------------------
- # Get the Root, and from it all the Signals
- #----------------------------------------------
- xRoot = xBiesse.oXMLroot
- oXML = xRoot.find('Signals')
- #--------------------------
- # Start a few counters
- #--------------------------
- countSignals = 0
- countGoodSignals = 0
- countINSignals = 0
- countOUTSignals = 0
- countORSignals = -1
- print("#-----------------------------------------------")
- print("# HAL file for the tool changer")
- print("# Created on %s" % time.strftime("%b %d %Y %H:%M:%S", time.localtime()))
- print("# Created by XML to HAL converter in python: CreateHALfromXML.py")
- print("#-----------------------------------------------")
- #------------------------------------
- # Loop through the signals found
- #------------------------------------
- for x in oXML.iter("Signal"):
- #--------------------------
- # Fetch needed infos
- #--------------------------
- name = x.get("name")
- index = x.get("index")
- dir = x.get("dir")
- mesaOUT = x.get("mesaOUT")
- mesaIN = x.get("mesaIN")
- #--------------------------
- # Built the net command
- #--------------------------
- #net mag-open-A hm2_5i25.0.7i84.1.3.input-16 or2.0.in0
- #net mag-open-B motion.digital-out-00 or2.0.in1
- #net mag-open or2.0.out => hm2_5i25.0.7i71.1.2.output-38
- if mesaIN != "":
- countORSignals += 1
- halstr1 = "net %s-A %s or2.%s.in0 \n" % (name, mesaIN, countORSignals)
- halstr2 = "net %s-B motion.digital-out-%s or2.%s.in1 \n" % (name, index, countORSignals)
- halstr3 = "net %s or2.%s.out => %s" % (name, countORSignals, mesaOUT)
- halstr = "\n%s%s%s\n" % (halstr1, halstr2, halstr3)
- else:
- halstr = "net %s %s motion.digital-%s-%s" % (name, mesaOUT, dir.lower(), index)
- #-----------------------------
- # Count the number of signals
- # Good ones and all of them
- #-----------------------------
- countSignals += 1
- if dir.lower() == "in":
- countINSignals += 1
- if dir.lower() == "out":
- countOUTSignals += 1
- if index != "":
- countGoodSignals += 1
- #---------------------------------
- # Send the net command to screen
- #---------------------------------
- print(halstr)
- #----------------------------------------------------------------
- # We are done, send the stats to screen
- #----------------------------------------------------------------
- print("Signals:%s, Good:%s, IN:%s, OUT:%s" % (countSignals, countGoodSignals, countINSignals, countOUTSignals))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement