- Timestamp:
- 12/07/11 13:36:53 (9 years ago)
- Location:
- trunk/Puzzlebox/Synapse
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Puzzlebox/Synapse/Interface.py
r309 r313 10 10 11 11 __changelog__ = """\ 12 Last Update: 2011.12.0 412 Last Update: 2011.12.07 13 13 """ 14 14 … … 590 590 ################################################################## 591 591 592 def updateProfileSessionStatus(self ):592 def updateProfileSessionStatus(self, source=None, target=None): 593 593 594 594 session_time = self.calculateSessionTime() 595 595 596 if self.parent == None: 597 target = self 598 else: 599 target = self.parent 596 if source == None: 597 if self.parent == None: 598 source = self 599 else: 600 source = self.parent 601 602 if target == None: 603 if self.parent == None: 604 target = self 605 else: 606 target = self.parent 600 607 601 608 target.textLabelSessionTime.setText(session_time) 602 609 603 target.textLabelPacketsReceived.setText( "%i" % \ 604 target.thinkGearConnectServer.protocol.packet_count) 605 target.textLabelPacketsDropped.setText( "%i" % \ 606 target.thinkGearConnectServer.protocol.bad_packets) 610 try: 611 target.textLabelPacketsReceived.setText( "%i" % \ 612 source.thinkGearConnectServer.protocol.packet_count) 613 except: 614 pass 615 616 try: 617 target.textLabelPacketsDropped.setText( "%i" % \ 618 source.thinkGearConnectServer.protocol.bad_packets) 619 except: 620 pass 607 621 608 622 … … 927 941 ################################################################## 928 942 929 def collectData(self): 930 931 if self == None: 932 target = self 933 else: 934 target = self.parent 943 def collectData(self, source=None, target=None): 944 945 if source == None: 946 if self == None: 947 source = self 948 else: 949 source = self.parent 950 951 if target == None: 952 if self == None: 953 target = self 954 else: 955 target = self.parent 935 956 936 957 data = {} 937 958 938 data['rawEeg'] = target.packets['rawEeg']939 data['signals'] = target.packets['signals']959 data['rawEeg'] = source.packets['rawEeg'] 960 data['signals'] = source.packets['signals'] 940 961 941 962 data['sessionTime'] = self.calculateSessionTime() … … 979 1000 ################################################################## 980 1001 981 def saveData(self): 982 983 if self == None: 984 target = self 985 else: 986 target = self.parent 987 988 data = self.collectData() 1002 def saveData(self, source=None, target=None): 1003 1004 if source == None: 1005 if self == None: 1006 source = self 1007 else: 1008 source = self.parent 1009 1010 if target == None: 1011 if self == None: 1012 target = self 1013 else: 1014 target = self.parent 1015 1016 data = self.collectData(source=source, target=target) 989 1017 990 1018 (date, localtime) = self.parseTimeStamp(time.time()) … … 1015 1043 ################################################################## 1016 1044 1017 def exportData(self): 1018 1019 if self.parent == None: 1020 target = self 1021 else: 1022 target = self.parent 1045 def exportData(self, parent=None, source=None, target=None): 1046 1047 if parent == None: 1048 if self == None: 1049 parent = self 1050 else: 1051 parent = self.parent 1052 1053 if source == None: 1054 if self == None: 1055 source = self 1056 else: 1057 source = self.parent 1058 1059 if target == None: 1060 if self.parent == None: 1061 target = self 1062 else: 1063 target = self.parent 1023 1064 1024 1065 (date, localtime) = self.parseTimeStamp(time.time()) … … 1044 1085 if str(output_file).endswith('.csv'): 1045 1086 1046 outputData = self.exportDataToCSV( )1087 outputData = self.exportDataToCSV(parent=parent, source=source, target=target) 1047 1088 1048 1089 … … 1062 1103 ################################################################## 1063 1104 1064 def exportDataToCSV(self): 1065 1066 if self == None: 1067 target = self 1068 else: 1069 target = self.parent 1105 def exportDataToCSV(self, parent=None, source=None, target=None): 1106 1107 if parent == None: 1108 if self == None: 1109 parent = self 1110 else: 1111 parent = self.parent 1112 1113 if source == None: 1114 if self == None: 1115 source = self 1116 else: 1117 source = self.parent 1118 1119 if target == None: 1120 if self == None: 1121 target = self 1122 else: 1123 target = self.parent 1070 1124 1071 1125 try: … … 1083 1137 1084 1138 customDataHeaders = [] 1085 for header in target.customDataHeaders:1139 for header in parent.customDataHeaders: 1086 1140 customDataHeaders.append(header) 1087 for plugin in target.activePlugins:1141 for plugin in parent.activePlugins: 1088 1142 for header in plugin.customDataHeaders: 1089 1143 customDataHeaders.append(header) … … 1096 1150 csv = {} 1097 1151 1098 for packet in target.packets['signals']:1152 for packet in source.packets['signals']: 1099 1153 1100 1154 if 'rawEeg' in packet.keys(): … … 1311 1365 ################################################################## 1312 1366 1313 def resetData(self): 1314 1315 if self == None: 1316 target = self 1317 else: 1318 target = self.parent 1319 1320 target.packets['rawEeg'] = [] 1321 target.packets['signals'] = [] 1322 1323 target.thinkGearConnectServer.protocol.session_start_timestamp = \ 1367 def resetData(self, source=None): 1368 1369 if source == None: 1370 if self == None: 1371 source = self 1372 else: 1373 source = self.parent 1374 1375 #if target == None: 1376 #if self == None: 1377 #target = self 1378 #else: 1379 #target = self.parent 1380 1381 source.packets['rawEeg'] = [] 1382 source.packets['signals'] = [] 1383 1384 source.thinkGearConnectServer.protocol.session_start_timestamp = \ 1324 1385 time.time() 1325 1386 1326 target.thinkGearConnectServer.protocol.packet_count = 01327 target.thinkGearConnectServer.protocol.bad_packets = 01387 source.thinkGearConnectServer.protocol.packet_count = 0 1388 source.thinkGearConnectServer.protocol.bad_packets = 0 1328 1389 1329 1390 self.updateProfileSessionStatus() 1330 1391 1331 1392 try: 1332 target.textEditDebugConsole.setText("")1393 source.textEditDebugConsole.setText("") 1333 1394 except: 1334 1395 pass -
trunk/Puzzlebox/Synapse/Protocol.py
r307 r313 840 840 ################################################################## 841 841 842 def disconnectHardware(self): 843 844 if self.device != None and self.device.device != None: 845 if self.device_model == 'NeuroSky MindWave': 846 if self.DEBUG: 847 print "INFO: ThinkGear device model MindWave selected. Writing disconnect packet." 848 try: 849 self.device.device.write('\xc1') 850 except Exception, e: 851 if self.DEBUG: 852 print "ERROR: failed to write disconnect packet: ", 853 print e 854 855 856 ################################################################## 857 842 858 def run(self): 843 859 … … 864 880 def exitThread(self, callThreadQuit=True): 865 881 866 if self.device != None and self.device.device != None: 867 if self.device_model == 'NeuroSky MindWave': 868 if self.DEBUG: 869 print "INFO: ThinkGear device model MindWave selected. Writing disconnect packet." 870 try: 871 self.device.device.write('\xc1') 872 except Exception, e: 873 if self.DEBUG: 874 print "ERROR: failed to write disconnect packet: ", 875 print e 876 882 #if self.device != None and self.device.device != None: 883 #if self.device_model == 'NeuroSky MindWave': 884 #if self.DEBUG: 885 #print "INFO: ThinkGear device model MindWave selected. Writing disconnect packet." 886 #try: 887 #self.device.device.write('\xc1') 888 #except Exception, e: 889 #if self.DEBUG: 890 #print "ERROR: failed to write disconnect packet: ", 891 #print e 892 893 self.disconnectHardware() 877 894 878 895 try: -
trunk/Puzzlebox/Synapse/Server.py
r312 r313 670 670 print e 671 671 672 # Calling exitThread() on protocol first seems to occassionally 673 # create the following error: 674 # RuntimeError: Internal C++ object (PySide.QtNetwork.QTcpSocket) already deleted. 675 # Segmentation fault 676 # ...when program is closed without pressing "Stop" button for EEG 677 #if self.protocol != None: 678 #self.protocol.exitThread() 679 680 # Call disconnect block in protocol first due to above error 681 self.protocol.disconnectHardware() 682 683 if self.serial_device != None: 684 self.serial_device.exitThread() 685 672 686 if self.protocol != None: 673 687 self.protocol.exitThread() 674 688 689 self.socket.close() 690 691 if callThreadQuit: 692 QtCore.QThread.quit(self) 693 694 if self.parent == None: 695 sys.exit() 696 697 698 ################################################################## 699 700 def resetDevice(self): 701 675 702 if self.serial_device != None: 676 703 self.serial_device.exitThread() 677 704 678 #if self.protocol != None:679 #self.protocol.exitThread()680 681 self.socket.close()682 683 if callThreadQuit:684 QtCore.QThread.quit(self)685 686 if self.parent == None:687 sys.exit()688 689 690 ##################################################################691 692 def resetDevice(self):693 694 if self.serial_device != None:695 self.serial_device.exitThread()696 697 705 if self.protocol != None: 698 706 self.protocol.exitThread()
Note: See TracChangeset
for help on using the changeset viewer.