Unable to receive data from BCI2000 using App Connector

Forum for software developers to discuss BCI2000 software development
Locked
svaronamoya
Posts: 4
Joined: 15 May 2013, 06:58

Unable to receive data from BCI2000 using App Connector

Post by svaronamoya » 14 Apr 2014, 12:12

Hi,

I have run out of ideas about why I cannot read anything from a BCI2000 P300 speller example application through a simple socket. It will most likely be a silly error on my part, but I just can´t figure it out.

I have followed the steps detailed in the documentation and also in some posts of this forum (like this response to Yuliy). After setting the ConnectorOutput parameter to "localhost:5000" in the configuration parameter file, launching the .bat file that starts the different modules and loads the parameter file, clicking "Set Config" and then "Start", I monitor the ports that are being used in my PC through TCPView and there is no data transmission regarding the 5000 port.

I have also tried to read data from Python using an UDP socket bound to that port with the same result: no data received.

I have read the available documentation and the posts in the forum, so any help would be most appreciated.

Thanks!
Last edited by boulay on 15 Apr 2014, 10:04, edited 1 time in total.
Reason: Cleaned up URL.

boulay
Posts: 382
Joined: 25 Dec 2011, 21:14

Re: Unable to receive data from BCI2000 using App Connector

Post by boulay » 15 Apr 2014, 10:02

Please post the contents of your .bat file and the .prm file(s) that the batch file loads?
Be sure to wrap each in

Code: Select all

code blocks
for readability.

svaronamoya
Posts: 4
Joined: 15 May 2013, 06:58

Re: Unable to receive data from BCI2000 using App Connector

Post by svaronamoya » 17 Apr 2014, 11:23

Thanks! These are the pieces of code.

.bat file

Code: Select all

#! ../prog/BCI2000Shell
@cls & ..\prog\BCI2000Shell %0 %* #! && exit /b 0 || exit /b 1\n
#######################################################################################
## $Id: P3Speller_SignalGenerator.bat 4126 2012-06-15 17:42:57Z mellinger $
## Description: BCI2000 startup Operator module script. For an Operator scripting
##   reference, see
##   http_nospam_doc.bci2000.org/index/User_Reference:Operator_Module_Scripting
##
## $BEGIN_BCI2000_LICENSE$
##
## This file is part of BCI2000, a platform for real-time bio-signal research.
## [ Copyright (C) 2000-2012: BCI2000 team and many external contributors ]
##
## BCI2000 is free software: you can redistribute it and/or modify it under the
## terms of the GNU General Public License as published by the Free Software
## Foundation, either version 3 of the License, or (at your option) any later
## version.
##
## BCI2000 is distributed in the hope that it will be useful, but
##                         WITHOUT ANY WARRANTY
## - without even the implied warranty of MERCHANTABILITY or FITNESS FOR
## A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along with
## this program.  If not, see <http_nospam_www.gnu.org/licenses/>.
##
## $END_BCI2000_LICENSE$
#######################################################################################
Change directory $BCI2000LAUNCHDIR
Show window; Set title ${Extract file base $0}
Reset system
Startup system localhost
Start executable SignalGenerator --local
Start executable P3SignalProcessing --local
Start executable P3Speller --local
Wait for Connected
Load parameterfile "../parms/examples/P3Speller_CopySpellingFromPython.prm"
.prm file

Code: Select all

Source:Signal%20Properties int SourceCh= 16 16 1 % // number of digitized and stored channels
Source:Signal%20Properties int SampleBlockSize= 8 32 1 % // number of samples transmitted at a time
Source:Signal%20Properties int SamplingRate= 256 256Hz 1 % // sample rate
Source:Signal%20Properties list ChannelNames= 0 // list of channel names
Source:Signal%20Properties floatlist SourceChOffset= 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 % % // Offset for channels in A/D units
Source:Signal%20Properties floatlist SourceChGain= 16 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.033 0.003 % % // gain for each channel (A/D units -> muV)
Storage:Data%20Location string DataDirectory= ../data ../data % % // path to top level data directory (directory)
Storage:Session string SubjectName= test Name % % // subject alias
Storage:Session string SubjectSession= 001 001 % % // three-digit session number
Storage:Session string SubjectRun= 00 00 % % // two-digit run number
Storage:Documentation string ID_System= % // BCI2000 System Code
Storage:Documentation string ID_Amp= % // BCI2000 Amp Code
Storage:Documentation string ID_Montage= % // BCI2000 Cap Montage Code
Visualize:Timing int VisualizeTiming= 1 1 0 1 // visualize system timing (0=no, 1=yes) (boolean)
Visualize:Source%20Signal int VisualizeSource= 1 1 0 1 // visualize raw brain signal (0=no, 1=yes) (boolean)
Visualize:Source%20Signal int VisualizeSourceDecimation= 1 1 0 % // decimation factor for raw brain signal
Visualize:Source%20Signal int VisualizeSourceTime= 2s 2 0 % // how much time in Source visualization
Visualize:Source%20Signal int SourceMin= -100muV -100muV % % // raw signal vis Min Value
Visualize:Source%20Signal int SourceMax= 100muV 100muV % % // raw signal vis Max Value
Source:SignalGeneratorADC int ModulateAmplitude= 1 0 0 1 // Modulate the amplitude with the mouse (0=no, 1=yes) (boolean)
Source:SignalGeneratorADC int SineChannelX= 0 0 0 % // Channel number of sinewave controlled by mouse x position
Source:SignalGeneratorADC int SineChannelY= 0 0 0 % // Channel number of sinewave controlled by mouse y position (0 for all)
Source:SignalGeneratorADC int SineChannelZ= 0 0 0 % // Channel number of sinewave controlled by mouse key state
Source:SignalGeneratorADC float SineFrequency= 0 10Hz % % // Frequency of sine wave
Source:SignalGeneratorADC int SineAmplitude= 0 100muV % % // Amplitude of sine wave
Source:SignalGeneratorADC int NoiseAmplitude= 30muV 30muV % % // Amplitude of white noise (common to all channels)
Source:SignalGeneratorADC int DCOffset= 60muV 0muV % % // DC offset (common to all channels)
Source:SignalGeneratorADC string OffsetMultiplier= StimulusType StimulusType % % // Expression to multiply offset by
Source:SignalGeneratorADC int RandomSeed= 0 0 0 1 // Initialization value for random number generator (initialize from time if 0)
Source:SignalGeneratorADC int SignalType= 0 0 0 2 // numeric type of output signal:  0: int16, 1: float32, 2: int32 (enumeration)
Storage:BCI2000FileWriter int SavePrmFile= 0 1 0 1 // save additional parameter file (0=no, 1=yes) (boolean)
Storage:BCI2000FileWriter string StorageTime= % // time of beginning of data storage
Source:Alignment int AlignChannels= 1 0 0 1 // align channels in time (0=no, 1=yes)
Source:Alignment floatlist SourceChTimeOffset= 0 0 % % // time offsets for all source channels (may be empty)
Source:Online%20Processing list TransmitChList= 4 1 2 3 4 1 1 128 // list of transmitted channels
Visualize:Processing%20Stages int VisualizeAlignmentFilter= 0 0 0 1 // Visualize AlignmentFilter output (boolean)
Visualize:Processing%20Stages int VisualizeTransmissionFilter= 0 0 0 1 // Visualize TransmissionFilter output (boolean)
Filtering:SpatialFilter matrix SpatialFilter= 4 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 % % // columns represent input channels, rows represent output channels
Filtering:P3TemporalFilter int EpochLength= 400ms 500ms 0 % // Length of data epoch from stimulus onset
Filtering:P3TemporalFilter int EpochsToAverage= 2 1 0 % // Number of epochs to average
Visualize:P3TemporalFilter int VisualizeP3TemporalFiltering= 1 0 0 1 // visualize Temporal filtered signals (0=no 1=yes) (boolean)
Visualize:P3TemporalFilter int TargetERPChannel= 1 1 0 128 // input channel for which to display ERP data
Filtering:LinearClassifier matrix Classifier= 2 { input%20channel input%20element%20(bin) output%20channel weight } 1 4 1 1 1 6 2 1 // Linear classification matrix in sparse representation
Filtering:Normalizer floatlist NormalizerOffsets= 2 0 0 0 % % // normalizer offsets
Filtering:Normalizer floatlist NormalizerGains= 2 1 1 0 % % // normalizer gain values
Filtering:Normalizer intlist Adaptation= 2 0 0 0 0 2 // 0: no adaptation, 1: zero mean, 2: zero mean, unit variance (enumeration)
Filtering:Normalizer matrix BufferConditions= 2 1 (Feedback)&&(TargetCode==1) (Feedback)&&(TargetCode==2) // expressions corresponding to data buffers (columns correspond to output channels, multiple rows correspond to multiple buffers)
Filtering:Normalizer float BufferLength= 9s 9s % % // time window of past data per buffer that enters into statistic
Filtering:Normalizer string UpdateTrigger= (Feedback==0) // expression to trigger offset/gain update when changing from 0 (use empty string for continuous update)
Visualize:Processing%20Stages int VisualizeSpatialFilter= 0 0 0 1 // Visualize SpatialFilter output (boolean)
Visualize:Processing%20Stages int VisualizeLinearClassifier= 0 0 0 1 // Visualize LinearClassifier output (boolean)
Visualize:Processing%20Stages int VisualizeNormalizer= 0 0 0 1 // Visualize Normalizer output (boolean)
Connector:ConnectorInput list ConnectorInputFilter= 0 // list of state names or signal elements to allow, "*" for any, signal elements as in "Signal(1,0)"
Connector:ConnectorInput string ConnectorInputAddress= % localhost:20320 % % // IP address/port to read from, e.g. localhost:20320
Application:Window int WindowWidth= 640 640 0 % // width of application window
Application:Window int WindowHeight= 480 480 0 % // height of application window
Application:Window int WindowLeft= 0 0 % % // screen coordinate of application window's left edge
Application:Window int WindowTop= 0 0 % % // screen coordinate of application window's top edge
Application:Window string WindowBackgroundColor= 0x000000 0x505050 % % // background color (color)
Application:Sequencing float PreRunDuration= 2s 0 0 % // pause preceding first sequence
Application:Sequencing float PostRunDuration= 2s 0 0 % // pause following last sequence
Application:Sequencing float PreSequenceDuration= 1/2s 2s 0 % // pause preceding sequences/sets of intensifications
Application:Sequencing float PostSequenceDuration= 3/4s 2s 0 % // pause following sequences/sets of intensifications
Application:Sequencing float StimulusDuration= 31.25ms 40ms 0 % // stimulus duration
Application:Sequencing float ISIMinDuration= 62.5ms 80ms 0 % // minimum duration of inter-stimulus interval
Application:Sequencing float ISIMaxDuration= 62.5ms 80ms 0 % // maximum duration of inter-stimulus interval
Application:Result%20Processing int InterpretMode= 2 0 0 2 // interpretation of results: 0 none, 1 online free mode, 2 copy mode (enumeration)
Application:Result%20Processing int DisplayResults= 1 1 0 1 // display results of copy/free spelling (boolean)
Application:Sequencing int NumberOfSequences= 2 15 1 % // number of sequences in a set of intensifications
Application:Speller%20Targets matrix TargetDefinitions= 36 { Display Enter Display%20Size Icon%20File Sound%20File } A A 1 % % B B 1 % % C C 1 % % D D 1 % % E E 1 % % F F 1 % % G G 1 % % H H 1 % % I I 1 % % J J 1 % % K K 1 % % L L 1 % % M M 1 % % N N 1 % % O O 1 % % P P 1 % % Q Q 1 % % R R 1 % % S S 1 % % T T 1 % % U U 1 % % V V 1 % % W W 1 % % X X 1 % % Y Y 1 % % Z Z 1 % % 1 1 1 % % 2 2 1 % % 3 3 1 % % 4 4 1 % % 5 5 1 % % 6 6 1 % % 7 7 1 % % 8 8 1 % % 9 9 1 % % _ %20 1 % % // speller target properties
Application:Speller%20Targets intlist NumMatrixColumns= 1 6 6 1 % // display matrices' column number(s)
Application:Speller%20Targets intlist NumMatrixRows= 1 6 6 0 % // display matrices' row number(s)
Application:Audio%20Stimuli int AudioStimuliOn= 0 0 0 1 // Audio Stimuli Mode (0=no, 1=yes) (boolean)
Application:Audio%20Stimuli matrix AudioStimuliRowsFiles= 6 { filename } sounds/1.wav sounds/2.wav sounds/3.wav sounds/4.wav sounds/5.wav sounds/6.wav // audio stimuli rows files 
Application:Audio%20Stimuli matrix AudioStimuliColsFiles= 6 { filename } sounds/a.wav sounds/b.wav sounds/c.wav sounds/d.wav sounds/e.wav sounds/f.wav // audio stimuli column files 
Application:Speller%20Targets floatlist TargetWidth= 1 16 0 0 100 // target width in percent of screen width
Application:Speller%20Targets floatlist TargetHeight= 1 14 0 0 100 // target height in percent of screen height
Application:Speller%20Targets floatlist TargetTextHeight= 1 12 0 0 100 // height of target labels in percent of screen height
Application:Speller%20Targets stringlist BackgroundColor= 1 0x00000000 0x505050 % % // target background color (color)
Application:Speller%20Targets stringlist TextColor= 1 0x00555555 0x505050 % % // text color (color)
Application:Speller%20Targets stringlist TextColorIntensified= 1 0x00FFFFFF 0x505050 % % // intensified text color (color)
Application:Speller%20Targets intlist IconHighlightMode= 1 1 1 0 2 // icon highlight method 0: Show/Hide, 1: Intensify, 2: Grayscale, 3: Invert, 4: Dim    (enumeration)
Application:Speller%20Targets floatlist IconHighlightFactor= 1 0.5 0.5 0 % // scale factor for highlighted icon pixel values
Application:Speller int FirstActiveMenu= 1 1 1 % // Index of first active menu
Application:Speller float StatusBarSize= 10 0 0 100 // size of status bar in percent of screen height
Application:Speller float StatusBarTextHeight= 4 0 0 100 // size of status bar text in percent of screen height
Application:Speller string TextToSpell= SPELLING%20IN%20THE%20RAIN // character or string to spell in offline copy mode
Application:Speller string TextResult= % // user spelling result
Application:Speller int TestMode= 1 0 0 1 // select targets by clicking on their associated stimuli (0=no, 1=yes) (boolean)
Application:Speller string DestinationAddress= % // network address for speller output in IP:port format
Application:Text%20Window int TextWindowEnabled= 0 0 0 1 // Show Text Window (0=no, 1=yes) (boolean)
Application:Text%20Window int TextWindowLeft= 600 0 0 % // Text Window X location
Application:Text%20Window int TextWindowTop= 5 0 0 % // Text Window Y location
Application:Text%20Window int TextWindowWidth= 512 512 0 % // Text Window Width
Application:Text%20Window int TextWindowHeight= 512 512 0 % // Text Window Height
Application:Text%20Window string TextWindowFontName= Courier // Text Window Font Name
Application:Text%20Window int TextWindowFontSize= 10 4 1 % // Text Window Font Size
Application:Text%20Window string TextWindowFilePath= % // Path for Saved Text File (directory)
Connector:ConnectorInput string ConnectorInputAddress= localhost:5001 // IP address/port to write to, e.g. localhost:20320
Connector:ConnectorOutput string ConnectorOutputAddress= localhost:5000 // IP address/port to write to, e.g. localhost:20320
Application:Localization string Language= Default Default % % // Language for user messages
Application:Localization matrix LocalizedStrings= { German } { TIME%20OUT%20!!! Waiting%20to%20start%20... } Zeit%20abgelaufen! Warte%20... // Localized user messages
Python script (although it is trivial)

Code: Select all

# -*- coding: utf-8 -*-
"""
Created on Tue Apr 08 12:33:53 2014

@author: BCI
"""

import socket
import sys

host = "localhost" # "127.0.0.1"
port = 5000
buf = 1024
addr = (host,port)
# Connect to UDP socket.
UDPSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
UDPSock.bind(addr)

while True:
    data, addr = UDPSock.recvfrom(1024) # buffer size is 1024 bytes
    print "Received message: " + data

sys.exit()
It must surely be some stupid mistake from my part anyway.

boulay
Posts: 382
Joined: 25 Dec 2011, 21:14

Re: Unable to receive data from BCI2000 using App Connector

Post by boulay » 17 Apr 2014, 13:34

I created a parameter file matching exactly what you have, I modified P3Speller_SignalGenerator.bat to load that parameter file, and I ran that exact Python code. It worked.

I am using the latest source code (as of a week ago). There may be slight differences there, but I doubt it.
I'm on Windows 8.1, but that shouldn't matter.

Are you running this from an administrator account? Is there any chance the firewall is preventing the application(s) from opening the port? Did you try different ports?

svaronamoya
Posts: 4
Joined: 15 May 2013, 06:58

Re: Unable to receive data from BCI2000 using App Connector

Post by svaronamoya » 22 Apr 2014, 06:55

Thank you very much! It's good to know that that code should work.

I did try with other ports but the result was the same. The machine I am using is working under Windows XP and I should have administrator rights.

It seems it has something to do with the firewall. I'll check it out.

Thanks again!

Locked

Who is online

Users browsing this forum: No registered users and 1 guest