大家好,我是陈锐。

今天分享内容来源官网教程参考已测试,内容仅供参考学习分享。

第一步:安装 EGI NetStation Python 库

使用PsychoPy版本2022.1.3 或最新版本,则软件自带有该egi-netstation库,可直接使用。如无,则需要使用 终端命令安装 egi-NetStation 库。

第二步:将代码组件添加到Builder 实验

与NetStation EEG脑电进行通信,将一些 Python 代码组件添加到实验中,即可完成。
首先,在Instructions中添加一个代码组件,如下图:
在Begin Experiment选项卡中,复制并粘贴以下代码,该代码将导入egi-netstation库并匹配IP地址进行通信,按照所连接的放大器型号,修改其ip地址:
#导入库egi-netstation
fromegi_pynetstation.NetStationimportNetStation

#设置苹果主机IP
IP_ns='10.10.10.42'

#如果是NA300放大器,则设置为42;NA400/410放大器,则设置为51
IP_amp='10.10.10.51'

#配置ECI端口,默认为55513,具体可参考采集软件上的port
port_ns=55513

#开始记录和发送开始标记STRT
eci_client=NetStation(IP_ns, port_ns)
eci_client.connect(ntp_ip=IP_amp)
eci_client.begin_rec()
eci_client.send_event(event_type='STRT', start=0.0)
然后,将以下代码输入带trial层中Begin Routine中,表示在试次开始前还没有触发值。
triggerSent = False
接着在同一代码组件的Each Frame中,添加以下代码以在呈现刺激时发送不超过四个字符的触发器。这里的.status属性是检查我们的刺激是否已经开始,如果已经开始,PsychoPy 会将触发器发送到 EGI NetStation。请注意,PsychoPy 中的大多数组件都具有该.status属性,因此您可以轻松地调整此代码,例如,在按下响应键时发送触发器:
#发送标记到netstation,需要四字符编码,如"code"
#如需条件分类,则可以设置为文件调用即可

iftext_stim.status==STARTEDandnottriggerSent: #表示text_stim(根据自己的实验名称修改)的.status状态已经开始并且不是False的,那么就发送下面的标记
win.callOnFlip(eci_client.send_event, event_type='code') #发送标记,同步每屏的刷新
triggerSent=True#写上这句,表示已发送trigger。
  • 最后,在实验结束时,添加代码以下内容:
    #停止记录,断开连接
    eci_client.end_rec()
    eci_client.disconnect()
除此之外呢,如使用的Psychopy code,则直接使用以下代码即可
fromegi_pynetstationimportNetStation
# Set an IP address for the computer running NetStation as an IPv4 string
IP_ns='10.10.10.42'
# Set a port that NetStation will be listening to as an integer
port_ns=55513
ns=NetStation(IP_ns, port_ns)
# Set an NTP clock server (the amplifier) address as an IPv4 string
IP_amp='10.10.10.51'
ns.connect(ntp_ip=IP_amp)
# Do whatever setup for your experiment here...
# Begin recording
ns.begin_rec()
# You can now send events; this one just says "HIYA" and automatically
# marks the time for you
ns.send_event(event_type="HIYA")
# You can include a data dictionary; perhaps you have a dog stimulus
my_data= {"dogs": "fido"}
# Send this data with the event type of "STIM"
ns.send_event(event_type="STIM", data=my_data)
# With the experiment concluded, you can end the recording
ns.end_rec()
# You'll want to disconnect the amplifier when your program is done
ns.disconnect()
参考网址:
https://github.com/nimh-sfim/egi-pynetstation
https://egi-pynetstation.readthedocs.io/en/latest/
https://psychopy.org/hardware/egiNetStation.html#egi

谢谢大家观看,如有帮助,来个喜欢或者关注吧!


本文作者:陈锐
本文仅供学习参考,有任何疑问及建议,扫描以下公众号二维码添加交流:
更多学习内容,仅在知识星球发布:

继续阅读
阅读原文