Using serial port to control ETG4000

2 min read

To synchronize NIRS recording and your stimuli (visual, auditory, button press etc), your presentation program needs to talk to the NIRS machine. Hitachi ETG4000 allows serial communication between the NIRS machine and an external computer. You can use either MatLab or Eprime to achieve this communication.

MatLab

If you use Matlab to deliver the stimuli, then controlling NIRS machine is very simple. Here is a minimum example.

In Matlab, you use the following commands to control the NIRS machine:

% Script SerialOT
% Serial control function for OTsystem using MATLAB
%
% Written by S.Kawasaki
% First completed 2006/04/30
%

clear all;

%/////////// Open MATLAB Serial Port ////////////// 
com1 = serial('COM1','BaudRate',9600,'DataBits',8,'Parity','none','StopBits',1);
fopen(com1);

%//////////////// Command List //////////////////
st   = sprintf('ST\r\n');%Start
mark1 = sprintf('A \r\n');%Mark A
mark2 = sprintf('B \r\n');%Mark B
mark3 = sprintf('C \r\n');%Mark C
mark4 = sprintf('D \r\n');%Mark D
ed   = sprintf('ED\r\n');%End

%/////////// Send to Commands for OT /////////////
fwrite(com1,st);disp('Send ST');    %Start
pause(10);                          %10s Prescan
pause(5);                          %5s Rest

for time=1:5
    fwrite(com1,mark1);disp('Send A ');  %Mark A Start
    pause(5);                          %5s Task
    fwrite(com1,mark1);disp('Send A ');  %Mark A End
    pause(5);                          %5s Rest
end

fwrite(com1,ed);disp('Send ED');    %End

%//////////// Close Serial Port ///////////////// 
fclose(com1);
%delete(com1);
clear com1;clear st;clear mark;clear ed;

EPrime

To allow your EPrime script to control ETG-4000, you may follow the instructions below:

First, make sure “Port” and “SRBOX” are not checked under tab “Devices” in window “Properties: Experiment Object Properties”.

Then,
1. Insert an “InLine” object into the beginning of your experiment procedure and copy the ST.txt script into the object; Rename the object to ‘StartETG’
2. Insert a “Wait” object right after “StartETG” and change the duration to 20 seconds. This step is necessary!
3. Insert an “InLine” object into the end of your experiment procedure and copy the ED.txt script into the object; Rename the object to ‘EndETG’

Hitachi also allows EPrime to send the marker information (i.e., event timing information) to ETG4000. To achieve that, you
1. Insert an “InLine” object into the place where you want to put a marker. This is usually when a trial starts and ends. Copy F1.txt into that object. You may need to change the marker String (here “F1”). If you are measuring in stim mode, then change the marker string to “A ” (note, ‘A’ and space), or “B “, or “C “, …; If you measure in event mode, change to “F1”, “F2”, “F3”, … Different string corresponds different types of event.
2. Reopen the StartETG object and comment out the line “dim myPort as SerialDevice”
3. Copy “dim myPort as SerialDevice” to the User window in Script window.

Then run your script.

If you encourter errors such as “constant” or “variable” error, you can move (not copy) the variable declaration lines (below) to User Window.
const header2 as string = “A ” ‘ can be B, F1 etc; can be header3 etc
Dim header2Bytes(1) As Integer

For each type of event, use a different variable name such as header2, header3, header2Bytes etc.

Here are sample EPrime scripts to control NIRS machine.

START

' E-prime inLine code for Sending ST
'
' written by Shingo Kawasaki

'''''''''''''''Begin Code

const header as string = "ST"
Dim headerBytes(1) As Integer
headerBytes(0) = 2  ' This specifies the type of string (2=Marker)
headerBytes(1) = 1  ' This specifies the number of bytes

' initialize the serial port by creating a serialdevice object and setting its properties
dim myPort as SerialDevice
Set myPort = New SerialDevice
dim myPortInfo as SerialDeviceInfo
myPortInfo.CommPort = 1
myPortInfo.BaudRate = 9600
myPortInfo.DataBits = 8
myPortInfo.Parity = ebParityNo
myPortInfo.StopBits = ebStopBits1_0

'Open the port and flush the buffer
myPort.open myPortInfo
myPort.FlushOutBuffer

' End section...Port is now ready to send the packet

' Write the packet  itself
myPort.WriteString header  'Header string
myPort.FlushOutBuffer

' close the port and clear the object when you are finished
' (when the last packet has been sent)
'myPort.close
'Set myPort = Nothing

END

' E-prime inLine code for Sending ED
'
' written by Shingo Kawasaki

const header4 as string = "ED" 
Dim header4Bytes(1) As Integer
header4Bytes(0) = 2  ' This specifies the type of string (2=Marker)
header4Bytes(1) = 1  ' This specifies the number of bytes


' Write the packet  itself
myPort.WriteString header4  'Header string
myPort.FlushOutBuffer

' close the port and clear the object when you are finished
' (when the last packet has been sent)
myPort.close
Set myPort = Nothing

F1

' E-prime inLine code for Sending F1
'
' written by Shingo Kawasaki


const header2 as string = "F1" 
Dim header2Bytes(1) As Integer
header2Bytes(0) = 2  ' This specifies the type of string (2=Marker)
header2Bytes(1) = 1  ' This specifies the number of bytes

' Write the packet  itself
myPort.WriteString header2  'Header string
myPort.FlushOutBuffer

' close the port and clear the object when you are finished
' (when the last packet has been sent)
'myPort.close
'Set myPort = Nothing

第十九期 fNIRS Journal Club 通知 2021/05/29,9:30am

美国普渡大学童云杰助理教授,将为大家讲解他们组最近被接受的一篇使用近红外相位信息研究脑血流变化的文章。热烈欢迎大家参与讨论。 时间: 北京时间2021年5月29日上午9:30地点: https://zoom.com房间号: 846 8391 7517密码: 805190 童云杰教授简介:普渡大学 生物医学工程助理教授、博士生导师。主攻方向是多模态脑成像, 包括核磁,fNIRS, EEG。关注脑功能及生理信号的提取与研究。发表论文九十余篇,引用上千次(H-index = 20)。 童教授要讲解的文章如下: Liang Z, Tian H, Yang HC, Arimitsu T, Takahashi...
Xu Cui
12 sec read

第十八期 fNIRS Journal Club 视频

北京时间2021年4月25日10点,北京师范大学的朱朝喆教授为大家讲解了他们最近几年在经颅脑图谱(Transcranial brain Atlas) 方面做的工作。视频如下: Youtube: https://youtu.be/EhYPuBPQ5uI Youku: 该视频在优酷上传后被优酷屏蔽,不清楚什么原因。申诉无效。
Xu Cui
3 sec read

第七届全国近红外光谱脑功能成像学术会议

会议日期:2021年5月22日-24日会议地点:天津师范大学 一、 会议简介       近红外光谱脑功能成像(fNIRS)具有设备购买与使用成本低、可在自然环境条件下使用、具有较高的时间分辨率和空间定位能力等特点,受到了脑科学研究的高度重视。“近红外光谱脑功能成像学术会议”是由北京师范大学认知神经科学与学习国家重点实验室朱朝喆教授发起并组织的全国性学术会议。已连续成功举办六届,共吸引全国近百家高校、科研院所及医院的六百余名学者参加。该会议已成为国内规模和影响力最大的fNIRS脑成像学术活动。       本届会议由北京师范大学与天津师范大学联合主办。会议将延用往届会议将学术报告与研究方法工作坊相结合的模式。学术报告模块(5月22日周六)将邀请心理学与认知神经科学领域、基础与临床医学领域以及工程技术领域知名学者汇报其fNIRS最新研究成果;工作坊模块(5月23-24日)由fNIRS领域一线研究者系统讲授fNIRS成像原理、fNIRS实验设计、fNIRS数据分析与统计、fNIRS论文写作以及fNIRS前沿技术等。除理论讲授外,还设置了fNIRS空间定位与数据分析操作(NIRS-KIT软件)环节,此外还安排充足的研讨答疑时间以便与会人员交流互动。       具体日程与详细内容等最新消息请关注后续通知,可通过天津师范大学心理部网站http://psych.tjnu.edu.cn/或北京师范大学国家重点实验室网站http://brain.bnu.edu.cn/,或者扫描下方二维码关注微信公众号-“fNIRS脑成像实验室”查阅更新信息,期盼在天津师范大学与您相聚! 二、会议组织机构 主办单位:教育部人文社会科学重点研究基地天津师范大学心理与行为研究院、天津师范大学心理学部、北京师范大学认知神经科学与学习国家重点实验室会议主席:白学军、朱朝喆组织委员会:赵春健、杨邵峰、侯鑫、曹正操 三、说明1.        学术报告模块注册费:人民币500元/人;工作坊模块注册费:人民币2500元/人。发票为电子发票,内容均为:“会议费”。两个模块各自独立收费,参会者可根据自己需要进行选择。2.        注册费包括各自模块的资料费、午餐费;其他费用自理。3.        会议报告人免除会议模块注册费,其他费用请自理。4.       ...
Xu Cui
18 sec read

9 Replies to “Using serial port to control ETG4000”

  1. Thank you for your great website. Do you by chance happen to have a code for using the serial port to control the Hitachi ETG 4000 by the presentation software? Thank you very much!

  2. I mean the “Presentation” Software, that was perhaps a bit ambiguos in my above comment :-)) Sorry.

  3. Do you happen to have the ETG-4000 software manual? I have a lot of questions about triggering, but can’t find anybody with the manual.

    My most pressing question: are triggers necessarily strings “A” etc for blocks and “F1” etc for events? Can integers be used?

  4. @anon
    In my experience, only “A” etc and “F1” etc be used for markers for ETG4000. I never used integers.

    As to the 1st question, if you have ETG4000, the company should give you the manual.

  5. Hi, Mr. Cui,
    I am writing a matlab script which needs to send marks to the ETG 4000 device. And I wonder if I can customize the string assigned to the mark(e.g.mark1 = sprintf(‘Response\r\n’)). Should the string contain just 2 characters?
    Thanks for your attenion~

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading