-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocument.rtf
More file actions
114 lines (114 loc) · 4.59 KB
/
Document.rtf
File metadata and controls
114 lines (114 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{\rtf1\ansi\ansicpg950\deff0\nouicompat\deflang1033\deflangfe1028{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 10.0.14393}\viewkind4\uc1
\pard\sa200\sl276\slmult1\f0\fs28\lang9 Within the code of your feedback/visualization, you can use the objects\par
of BCI.py as follows (examples):\par
\par
To receive TOBI ID messages in the feedback:\par
\par
1) Define a function like the following:\par
\par
def handle_tobiid_input(self):\par
data = None\par
try:\par
data = self.bci.iDsock_dev.recv(512)\par
self.bci.idStreamer_dev.Append(data)\par
except:\par
self.nS = False\par
self.dec = 0\par
pass\par
\par
# deserialize ID message\par
if data:\par
if self.bci.idStreamer_dev.Has("<tobiid","/>"):\par
msg = self.bci.idStreamer_dev.Extract("<tobiid","/>")\par
self.bci.id_serializer_dev.Deserialize(msg)\par
self.bci.idStreamer_dev.Clear()\par
self.MyIDMessage = int(self.bci.id_msg_dev.GetEvent()) # Here\par
is the value of the received message!\par
elif self.bci.idStreamer_dev.Has("<tcstatus","/>"):\par
MsgNum = self.bci.idStreamer_dev.Count("<tcstatus")\par
for i in range(1,MsgNum-1):\par
# Extract most of these messages and trash them\par
msg_useless = self.bci.idStreamer_dev.Extract("<tcstatus","/>")\par
\par
2) Call this function from within your code, whenever you want to check\par
for ID messages, e.g.:\par
# Do something\par
handle_tobiid_input()\par
# Do more\par
\par
Note that you have to options: This function can either RETURN the ID\par
message value (in this case add in the end a line: return MyIDMessage,\par
or save it in an internal variable of your feedback class, as in the\par
example: self.MyIDMessage)\par
\par
3) Note also: self.bci is the object created based on the BciInterface\par
class, defined inside BCI.py, aka in the initialization of your feedback\par
you should have a line : self.bci = BciInterface() which will start the\par
BCI and make the connections\par
\par
\par
To SEND ID Messages FROM the feedback TO the loop, you simply write:\par
\par
self.bci.id_msg_bus.SetEvent(YOUREVENTCODE)\par
\par
self.bci.iDsock_bus.sendall(self.bci.id_serializer_bus.Serialize());\par
\par
wherever you need to send an ID message.\par
\par
*** In these exanples I use two TiD interfaces BUS (to send from the\par
feedback to the loop) and DEV (from matlab to the feedback). That's why\par
both are defined in BciInterface class in BCI.py. There is no real need\par
for that, you can use a single TiD (on BUS usually) to both send and receive\par
\par
\par
Now, similarly for TiC interface:\par
\par
\par
1) Define a function to read TiC:\par
\par
def handle_tobiic_input(self):\par
data = None\par
self.bci.IsProb = False\par
try:\par
data = self.bci.conn.recv(512)\par
self.bci.icStreamer.Append(data)\par
except:\par
self.bci.IsProb = False\par
pass # no data available\par
\par
# deserialize IC message\par
if data:\par
try:\par
while self.bci.icStreamer.Has("<tobiic","</tobiic>"):\par
msg = self.bci.icStreamer.Extract("<tobiic","</tobiic>")\par
self.bci.ic_serializer.Deserialize(msg)\par
# Clear streamer buffer, better loose some messages than\par
# observe the...past in the feedback\par
# self.bci.icStreamer.Dump() # Check what's left, see how\par
much I loose\par
self.bci.icStreamer.Clear()\par
\par
except:\par
print self.bci.ic_serializer.Deserialize(data)\par
print '[TOBI-IC] Warning, received data not in iC format!'\par
return\par
\par
# take the first classifier and the first set of data from\par
that classifier, ignore anything else\par
\par
#print "Left prob:", self.bci.ic_msg.GetValue("mi", "2")\par
#print "Right prob:", self.bci.ic_msg.GetValue("mi", "1")\par
self.probRight = self.bci.ic_msg.GetValue("mi", "1")\par
self.probLeft = self.bci.ic_msg.GetValue("mi", "2")\par
self.bci.IsProb = True\par
self.bci.CurICindex = int(self.bci.ic_msg.GetFidx())\par
\par
You can change of course the self.probLeft and self.probRight to your\par
case (e.g. self.SpermPosition) etc.\par
\par
2) Call it when you need to read TiC data\par
\par
handle_tobiic_input()\par
}