2020
2121from serial import Serial , EIGHTBITS , PARITY_NONE , STOPBITS_ONE
2222
23+ import pyxid2
24+
2325from eegnb .devices .utils import (
2426 get_openbci_usb ,
2527 create_stim_array ,
5759 "muse2016_bfb" ,
5860]
5961
60-
62+ xid_devices = [
63+ "nirsport2"
64+ ]
6165
6266class 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 ("\n Opened 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" :
0 commit comments