Skip to content

Commit 83071b3

Browse files
Merge pull request #312 from JohnGriffiths/add_pyxid2_device
Add pyxid2 device for nirx fnirs recording triggers
2 parents 0c928e6 + 865238b commit 83071b3

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

eegnb/devices/eeg.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
from serial import Serial, EIGHTBITS, PARITY_NONE, STOPBITS_ONE
2222

23+
import pyxid2
24+
2325
from eegnb.devices.utils import (
2426
get_openbci_usb,
2527
create_stim_array,
@@ -57,7 +59,9 @@
5759
"muse2016_bfb",
5860
]
5961

60-
62+
xid_devices = [
63+
"nirsport2"
64+
]
6165

6266
class EEG:
6367
device_name: str
@@ -68,6 +72,7 @@ def __init__(
6872
device=None,
6973
serial_port=None,
7074
serial_num=None,
75+
xid_num=None,
7176
mac_addr=None,
7277
other=None,
7378
ip_addr=None,
@@ -88,6 +93,7 @@ def __init__(
8893
self.serial_num = serial_num
8994
self.serial_port = serial_port
9095
self.mac_address = mac_addr
96+
self.xid_num = xid_num
9197
self.ip_addr = ip_addr
9298
self.other = other
9399
self.config = config
@@ -112,7 +118,8 @@ def initialize_backend(self):
112118
self._init_kf()
113119
elif self.backend == "serialport":
114120
self._init_serial()
115-
121+
elif self.backend == "xidport":
122+
self._init_xid()
116123

117124
def _get_backend(self, device_name):
118125
if device_name in brainflow_devices:
@@ -123,6 +130,8 @@ def _get_backend(self, device_name):
123130
return "kernelflow"
124131
elif device_name in ["biosemi"]:
125132
return "serialport"
133+
elif device_name in ["nirsport2"]:
134+
return "xidport"
126135

127136

128137
#####################
@@ -606,6 +615,33 @@ def _serial_open_port(self,PORT_ID="COM4", BAUD=115200):
606615

607616

608617

618+
################################
619+
# Cedrus XID port functions #
620+
################################
621+
622+
623+
def _init_xid(self):
624+
if self.xid_num is not None: # if an xis device number is supplied, open and init that device
625+
xids_list = pyxid2.get_xid_devices()
626+
xid = xids_list[self.xid_num]
627+
xid.init_device()
628+
# (otherwise, don't open; assuming an xid attribute will be
629+
# manually added later)
630+
631+
xid.set_pulse_duration(1000) # [ is this needed / optimal in all cases ? ]
632+
633+
print("\nOpened XID Device #%s:\n%s" %(self.xid_num, xid))
634+
635+
self.xid = xid
636+
637+
638+
def _xid_push_sample(self, marker):
639+
640+
if not (0 <= marker <= 255): raise ValueError("marker code must be 045255")
641+
self.xid.activate_line(lines=[marker])
642+
643+
644+
609645

610646
#################################
611647
# Highlevel device functions #
@@ -628,7 +664,10 @@ def start(self, fn, duration=None):
628664
elif self.backend == "kernelflow":
629665
self._start_kf()
630666
elif self.backend == "serialport":
631-
pass
667+
pass
668+
elif self.backend == "xidport":
669+
pass
670+
632671

633672

634673
def push_sample(self, marker, timestamp, marker_name=None):
@@ -647,7 +686,8 @@ def push_sample(self, marker, timestamp, marker_name=None):
647686
self._kf_push_sample(marker=marker,timestamp=timestamp, marker_name=marker_name)
648687
elif self.backend == "serialport":
649688
self._serial_push_sample(marker=marker)
650-
689+
elif self.backend == "xidport":
690+
self._xid_push_sample(marker=marker)
651691

652692
def stop(self):
653693
if self.backend == "brainflow":

eegnb/devices/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"freeeeg32": [f"eeg_{i}" for i in range(0, 32)],
3030
"kernelflow": [],
3131
"biosemi": [],
32+
"nirsport2": [],
3233
}
3334

3435
BRAINFLOW_CHANNELS = {
@@ -60,6 +61,7 @@
6061
"freeeeg32": BoardShim.get_eeg_channels(BoardIds.FREEEEG32_BOARD.value),
6162
"kernelflow": [],
6263
"biosemi": [],
64+
"nirsport2": [],
6365
}
6466

6567
SAMPLE_FREQS = {
@@ -84,6 +86,7 @@
8486
"freeeeg32": BoardShim.get_sampling_rate(BoardIds.FREEEEG32_BOARD.value),
8587
"kernelflow": [],
8688
"biosemi": [],
89+
"nirsport2": [],
8790
}
8891

8992

0 commit comments

Comments
 (0)