You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIModell.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from subprocess import *
  2. import os
  3. class Modell():
  4. PATH_OV = 'meta/dist/designer-Release/openvibe-designer.sh'
  5. PATH_FILES = 'Projekte/OpenViBE_visual_BCI-master/openvibe_visual_bci/'
  6. def __init__(self):
  7. pass
  8. def startCopySpelling(self):
  9. print("start copySpelling")
  10. path = self.PATH_FILES + 'p300-visual-1-acquisition.xml'
  11. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  12. stdout=PIPE,
  13. universal_newlines=True)
  14. while True:
  15. output = process.stdout.readline()
  16. print(output.strip())
  17. x = output.find("schlagwort?")
  18. if(x != -1):
  19. print("Training finished")
  20. process.terminate()
  21. break
  22. self.killProzess()
  23. def trainXDawn(self):
  24. print("start training Xdawn")
  25. path = self.PATH_FILES + 'p300-visual-2-train-xDAWN.xml'
  26. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  27. stdout=PIPE,
  28. universal_newlines=True)
  29. while True:
  30. output = process.stdout.readline()
  31. print(output.strip())
  32. x = output.find("Training finished and saved")
  33. if(x != -1):
  34. print("Training finished")
  35. process.terminate()
  36. break
  37. self.killProzess()
  38. def trainClassifier(self):
  39. print("start training Classifier")
  40. path = self.PATH_FILES + 'p300-visual-3-train-classifier.xml'
  41. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  42. stdout=PIPE,
  43. universal_newlines=True)
  44. while True:
  45. output = process.stdout.readline()
  46. print(output.strip())
  47. x = output.find("schlagwort?")
  48. if(x != -1):
  49. print("Training finished")
  50. process.terminate()
  51. break
  52. self.killProzess()
  53. def freeSpelling(self):
  54. print("start freeSpelling")
  55. path = self.PATH_FILES + 'p300-visual-4-online.xml'
  56. process = Popen(['bash', self.PATH_OV, '--play', path, '--no-gui'],
  57. stdout=PIPE,
  58. universal_newlines=True)
  59. while True:
  60. output = process.stdout.readline()
  61. print(output.strip())
  62. x = output.find("schlagwort?")
  63. if(x != -1):
  64. print("End Spelling")
  65. process.terminate()
  66. break
  67. self.killProzess()
  68. def killProzess(self):
  69. print('start killing')
  70. pidOV = 0
  71. pidP = 0
  72. items = []
  73. prozesse = Popen(["ps", "-e"], stdout=PIPE).communicate()[0].strip()
  74. zeilen = prozesse.split('\n')
  75. for z in zeilen:
  76. if(z.find("openvibe-design") != -1):
  77. z = z.strip()
  78. items = z.split(' ')
  79. pidOV = items[0]
  80. #kill -TERM veranlasst dem Prozess sich selbst zu beenden (nicht erzwungen)
  81. Popen(["kill", "-TERM", pidOV], stdout=PIPE).communicate()
  82. print("killed openvibe-designer")