-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (42 loc) · 1.46 KB
/
main.py
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
import msvcrt
import configparser
import argparse
import uuid
import pylsl
import mpdev
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--cfg', default='config.ini')
args = parser.parse_args()
config = configparser.ConfigParser()
config.read(args.cfg)
sampletime = config["biopac"].getint("sampletime", fallback=1)
channels = [int(x) for x in config["biopac"]["channels"].split(',')]
digital_channels = [int(x) for x in config["biopac"]["digital_channels"].split(',')]
params = dict(
dll_dir=config["biopac"].get("dll_dir", fallback=None),
sampletime=sampletime,
connected=False,
channels=channels,
digital_channels=digital_channels,
)
biopac = mpdev.setup_biopac(params)
channel_count = len(channels) + len(digital_channels)
info = pylsl.StreamInfo(
name=config["lsl"].get("stream_name", fallback='biopac'),
type=config["lsl"].get("stream_type", fallback='float'),
channel_format='double64',
channel_count=channel_count,
source_id=str(uuid.uuid4())
)
outlet = pylsl.StreamOutlet(info)
print("Acquisition running, press Q to stop")
running = True
while running:
sample = mpdev.receive_data(biopac, channels, digital_channels)
outlet.push_sample(sample)
if msvcrt.kbhit():
running = msvcrt.getch() != b'q'
mpdev.shutdown_biopac(biopac)
if __name__ == '__main__':
main()