psychopy与EGInetstation连接

Posted by 陈锐CR on June 2, 2022 | 阅读

Psychopy刺激软件与EGI脑电设备连接

第一步:安装 EGI NetStation Python 库

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

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

与NetStation EEG脑电进行通信,将一些 Python 代码组件添加到实验中,即可完成。

首先,在Instructions中添加一个代码组件,如下图:

image-20220708102114130

在Begin Experiment选项卡中,复制并粘贴以下代码,该代码将导入egi-netstation库并匹配IP地址进行通信,按照所连接的放大器型号,修改其ip地址:

#导入库egi-netstation
from egi_pynetstation.NetStation import NetStation

#设置苹果主机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

image-20220708110607809

接着在同一代码组件的Each Frame中,添加以下代码以在呈现刺激时发送不超过四个字符的触发器。这里的.status属性是检查我们的刺激是否已经开始,如果已经开始,PsychoPy 会将触发器发送到 EGI NetStation。请注意,PsychoPy 中的大多数组件都具有该.status属性,因此您可以轻松地调整此代码,例如,在按下响应键时发送触发器:

#发送标记到netstation,需要四字符编码,如"code"
#如需条件分类,则可以设置为文件调用即可

if text_stim.status == STARTED and not triggerSent: #表示text_stim(根据自己的实验名称修改)的.status状态已经开始并且不是False的,那么就发送下面的标记
    win.callOnFlip(eci_client.send_event, event_type = 'code') #发送标记,同步每屏的刷新
    triggerSent = True #写上这句,表示已发送trigger。

image-20220708113709682

  • 最后,在实验结束时,添加代码以下内容:

    #停止记录,断开连接
    eci_client.end_rec()
    eci_client.disconnect()
    

image-20220708115734212

除此之外呢,如使用的Psychopy code,则直接使用以下代码即可

from egi_pynetstation import NetStation
# 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

image-20211111220310776

微信 公众号 B站 知乎 CSDN


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


本文作者:陈锐

博客地址 : Chen Rui Blog
知乎地址 : 知乎专栏
书店地址 : 书店主页
知识星球 : 星球主页


版权声明:本文由 陈锐CR 在 2022年06月02日发表。本博客文章作者为陈锐CR时均采用属于个人原创撰写,未经许可,禁止在任何媒介以任何形式复制、发行本文章,如需转载,请查看About联系方式,非商业转载请注明出处,不得用于商业目的。
文章题目及链接:《psychopy与EGInetstation连接》



☛您的打赏是我创作的动力☚


  相关文章:

「游客及非Github用户留言」:

%
UP
博客已运行