Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #!/usr/bin/python
  2. #
  3. #-------------------------------------------------------
  4. # Usage : python CreateHALfromXML.py > HalFile.hal
  5. #-------------------------------------------------------
  6. import xmlBiesse
  7. #from time import time, gmtime, strftime
  8. import time
  9. xBiesse = xmlBiesse.xmlBiesse() # the xml interface
  10. #----------------------------------------------
  11. # Get the Root, and from it all the Signals
  12. #----------------------------------------------
  13. xRoot = xBiesse.oXMLroot
  14. oXML = xRoot.find('Signals')
  15. #--------------------------
  16. # Start a few counters
  17. #--------------------------
  18. countSignals = 0
  19. countGoodSignals = 0
  20. countINSignals = 0
  21. countOUTSignals = 0
  22. countORSignals = -1
  23. print("#-----------------------------------------------")
  24. print("# HAL file for the tool changer")
  25. print("# Created on %s" % time.strftime("%b %d %Y %H:%M:%S", time.localtime()))
  26. print("# Created by XML to HAL converter in python: CreateHALfromXML.py")
  27. print("#-----------------------------------------------")
  28. #------------------------------------
  29. # Loop through the signals found
  30. #------------------------------------
  31. for x in oXML.iter("Signal"):
  32. #--------------------------
  33. # Fetch needed infos
  34. #--------------------------
  35. name = x.get("name")
  36. index = x.get("index")
  37. dir = x.get("dir")
  38. mesaOUT = x.get("mesaOUT")
  39. mesaIN = x.get("mesaIN")
  40. #--------------------------
  41. # Built the net command
  42. #--------------------------
  43. #net mag-open-A hm2_5i25.0.7i84.1.3.input-16 or2.0.in0
  44. #net mag-open-B motion.digital-out-00 or2.0.in1
  45. #net mag-open or2.0.out => hm2_5i25.0.7i71.1.2.output-38
  46. if mesaIN != "":
  47. countORSignals += 1
  48. halstr1 = "net %s-A %s or2.%s.in0 \n" % (name, mesaIN, countORSignals)
  49. halstr2 = "net %s-B motion.digital-out-%s or2.%s.in1 \n" % (name, index, countORSignals)
  50. halstr3 = "net %s or2.%s.out => %s" % (name, countORSignals, mesaOUT)
  51. halstr = "\n%s%s%s\n" % (halstr1, halstr2, halstr3)
  52. else:
  53. halstr = "net %s %s motion.digital-%s-%s" % (name, mesaOUT, dir.lower(), index)
  54. #-----------------------------
  55. # Count the number of signals
  56. # Good ones and all of them
  57. #-----------------------------
  58. countSignals += 1
  59. if dir.lower() == "in":
  60. countINSignals += 1
  61. if dir.lower() == "out":
  62. countOUTSignals += 1
  63. if index != "":
  64. countGoodSignals += 1
  65. #---------------------------------
  66. # Send the net command to screen
  67. #---------------------------------
  68. print(halstr)
  69. #----------------------------------------------------------------
  70. # We are done, send the stats to screen
  71. #----------------------------------------------------------------
  72. print("Signals:%s, Good:%s, IN:%s, OUT:%s" % (countSignals, countGoodSignals, countINSignals, countOUTSignals))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement