<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>MEGSynch</title><revhistory><revision><revnumber>3</revnumber><date>2017-08-08 15:48:21</date><authorinitials>JohanCarlin</authorinitials><revremark>typos</revremark></revision><revision><revnumber>2</revnumber><date>2017-08-08 15:47:51</date><authorinitials>JohanCarlin</authorinitials><revremark>replace attachment with github link</revremark></revision><revision><revnumber>1</revnumber><date>2016-04-06 15:41:26</date><authorinitials>TiborAuer</authorinitials></revision></revhistory></articleinfo><section><title>MEGSynch</title><para>MEGSynch provides an interface for National Instruments PCI 6503 card used to capture all pulses (scanner synch pulse and button pulses alike) when using MATLAB. </para><para>For more information, type in MATLAB </para><programlisting format="linespecific" language="highlight" linenumbering="unnumbered" startinglinenumber="1"><methodname><![CDATA[help]]></methodname><![CDATA[ ]]><methodname><![CDATA[MEGSynchClass]]></methodname>
</programlisting><caution><para>N.B.: National Instruments PCI 6503 card does not monitor pulses in the background, so you have to make sure that you wait for any pulse before it comes! </para></caution><para>Any problems, report them to <ulink url="http://imaging.mrc-cbu.cam.ac.uk/imaging/JohanCarlin">Johan Carlin</ulink>. </para><section><title>Obtain MEGSynch</title><itemizedlist><listitem override="none"><para>MEGSynch is already available on MEG stimulus PC. You can check out a personal copy for testing from <ulink url="https://github.com/MRC-CBU/megsync">our github repo</ulink>. </para></listitem></itemizedlist></section><section><title>Using MEGSynch</title><section><title>Initialise</title><itemizedlist><listitem><para>Default. Use only in MEG lab! </para></listitem><listitem override="none"><programlisting format="linespecific" language="highlight" linenumbering="unnumbered" startinglinenumber="1"><methodname><![CDATA[MEG]]></methodname><![CDATA[ = ]]><methodname><![CDATA[MEGSynchClass]]></methodname><![CDATA[;]]>
</programlisting><para>Default button mapping: </para><informaltable><tgroup cols="5"><colspec colname="col_0"/><colspec colname="col_1"/><colspec colname="col_2"/><colspec colname="col_3"/><colspec colname="col_4"/><tbody><row rowsep="1"><entry colsep="1" rowsep="1"><para><emphasis role="strong">Button</emphasis> </para></entry><entry align="center" colsep="1" nameend="col_2" namest="col_1" rowsep="1"><para><emphasis role="strong">Button name in MATLAB</emphasis> </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"><para><emphasis role="strong">Channel</emphasis> </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>'Left Yellow' </para></entry><entry align="center" colsep="1" nameend="col_2" namest="col_1" rowsep="1"><para>'LY' </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"><para>'S3' </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>'Right Blue' </para></entry><entry align="center" colsep="1" nameend="col_2" namest="col_1" rowsep="1"><para>'RB' </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"><para>'S4' </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>'Right Yellow' </para></entry><entry align="center" colsep="1" nameend="col_2" namest="col_1" rowsep="1"><para>'RY' </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"><para>'S5' </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>'Right Green' </para></entry><entry align="center" colsep="1" nameend="col_2" namest="col_1" rowsep="1"><para>'RG' </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"><para>'S6' </para></entry></row><row rowsep="1"><entry colsep="1" rowsep="1"><para>'Right Red' </para></entry><entry align="center" colsep="1" nameend="col_2" namest="col_1" rowsep="1"><para>'RR' </para></entry><entry align="center" colsep="1" nameend="col_4" namest="col_3" rowsep="1"><para>'S7' </para></entry></row></tbody></tgroup></informaltable></listitem><listitem override="none"><para>To change button mapping: </para></listitem><listitem override="none"><programlisting format="linespecific" language="highlight" linenumbering="unnumbered" startinglinenumber="1"><methodname><![CDATA[MEG]]></methodname><![CDATA[ = ]]><methodname><![CDATA[MEGSynchClass]]></methodname><![CDATA[({]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[B1']]></phrase><![CDATA[,]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[S4']]></phrase><![CDATA[;]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[B2']]></phrase><![CDATA[,]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[S5']]></phrase><![CDATA[}); ]]><lineannotation><![CDATA[% specify button names "B1" and "B2" and maps them to S4 and S5]]></lineannotation>
</programlisting></listitem><listitem><para>Emulation: </para></listitem><listitem override="none"><programlisting format="linespecific" language="highlight" linenumbering="unnumbered" startinglinenumber="1"><methodname><![CDATA[MEG]]></methodname><![CDATA[ = ]]><methodname><![CDATA[MEGSynchClass]]></methodname><![CDATA[(1);   ]]><lineannotation><![CDATA[% full emulation]]></lineannotation>
</programlisting></listitem></itemizedlist></section><section><title>Close</title><para>MEGSynchClass has a destructor, which is automatically triggered if the object is deleted (e.g. clear, returning function). If you use a script, however, it does not perform any auto-clear, so you have to destroy the object manually: </para><itemizedlist><listitem override="none"><programlisting format="linespecific" language="highlight" linenumbering="unnumbered" startinglinenumber="1"><methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[delete]]></methodname><![CDATA[;]]>
</programlisting></listitem></itemizedlist></section><section><title>Send trigger</title><itemizedlist><listitem override="none"><programlisting format="linespecific" language="highlight" linenumbering="unnumbered" startinglinenumber="1"><token><![CDATA[for]]></token><![CDATA[ ]]><methodname><![CDATA[v]]></methodname><![CDATA[ = 0:255  ]]><lineannotation><![CDATA[% send triggers 0 to 255 ...]]></lineannotation>
<![CDATA[    ]]><methodname><![CDATA[pause]]></methodname><![CDATA[(0.1) ]]><lineannotation><![CDATA[% ... in every 100ms]]></lineannotation>
<![CDATA[    ]]><methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[SendTrigger]]></methodname><![CDATA[(]]><methodname><![CDATA[v]]></methodname><![CDATA[)]]>
<token><![CDATA[end]]></token>
</programlisting></listitem></itemizedlist></section><section><title>Capture button presses</title><itemizedlist><listitem override="none"><programlisting format="linespecific" language="highlight" linenumbering="unnumbered" startinglinenumber="1"><methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[SetButtonReadoutTime]]></methodname><![CDATA[(0.5);      ]]><lineannotation><![CDATA[% block individual buttons for 0.5s after button press so we will not detect the same button press twice]]></lineannotation>
<lineannotation><![CDATA[% MEG.SetButtonBoxReadoutTime(0.5); % block the whole buttonbox for 0.5s after button press]]></lineannotation>
<lineannotation><![CDATA[% MEG.Keys = {'f1','f2','f3','f4'}; % emulation Buttons #1-#4 with F1-F4]]></lineannotation>
<methodname><![CDATA[n]]></methodname><![CDATA[ = 0;]]>
<lineannotation><![CDATA[% MEG.BBoxTimeout = 1.5;            % Wait for button press for 1.5s]]></lineannotation>
<lineannotation><![CDATA[% MEG.BBoxTimeout = -1.5;           % Wait for button press for 1.5s even in case of response]]></lineannotation>
<methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[ResetClock]]></methodname><![CDATA[;]]>
<token><![CDATA[while]]></token><![CDATA[ ]]><methodname><![CDATA[n]]></methodname><![CDATA[ ~= 10 ]]><methodname><![CDATA[rButtonRelease]]></methodname><![CDATA[;     ]]><lineannotation><![CDATA[% Wait for any button to be   released]]></lineannotation>
<![CDATA[    ]]><lineannotation><![CDATA[% MEG.WaitFo                      % polls 10 button presses]]></lineannotation>
<![CDATA[    ]]><methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[WaitForButtonPress]]></methodname><![CDATA[;         ]]><lineannotation><![CDATA[% Wait for any button to be pressed]]></lineannotation>
<![CDATA[    ]]><lineannotation><![CDATA[% MEG.WaitForButtonPress([],2); % Wait for Button #2]]></lineannotation>
<![CDATA[    ]]><lineannotation><![CDATA[% MEG.WaitForButtonPress(2);    % Wait for any button for 2s (overrides MEG.BBoxTimeout only for this event)]]></lineannotation>
<![CDATA[    ]]><lineannotation><![CDATA[% MEG.WaitForButtonPress(-2);   % Wait for any button for 2s even in case of response (overrides MEG.BBoxTimeout only for this event)]]></lineannotation>
<![CDATA[    ]]><lineannotation><![CDATA[% MEG.WaitForButtonPress(2,2);  % Wait for Button #2 for 2s (overrides MEG.BBoxTimeout only for this event)]]></lineannotation>
<![CDATA[    ]]><lineannotation><![CDATA[% MEG.WaitForButtonPress(-2,2); % Wait for Button #2 for 2s even in case of response (overrides MEG.BBoxTimeout only for this event)]]></lineannotation>
<![CDATA[    ]]><methodname><![CDATA[n]]></methodname><![CDATA[ = ]]><methodname><![CDATA[n]]></methodname><![CDATA[ + 1;]]>
<![CDATA[    ]]><methodname><![CDATA[fprintf]]></methodname><![CDATA[(]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[At %2.3fs, ']]></phrase><![CDATA[,]]><methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[Clock]]></methodname><![CDATA[);]]>
<![CDATA[    ]]><methodname><![CDATA[fprintf]]></methodname><![CDATA[(]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[Button %d ']]></phrase><![CDATA[,]]><methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[LastButtonPress]]></methodname><![CDATA[);]]>
<![CDATA[    ]]><methodname><![CDATA[fprintf]]></methodname><![CDATA[(]]><phrase><![CDATA[']]></phrase><phrase><![CDATA[pressed: %2.3fs\n']]></phrase><![CDATA[,]]><methodname><![CDATA[MEG]]></methodname><![CDATA[.]]><methodname><![CDATA[TimeOfLastButtonPress]]></methodname><![CDATA[);]]>
<token><![CDATA[end]]></token>
</programlisting></listitem></itemizedlist></section></section></section></article>