UDP output

Forum for software developers to discuss BCI2000 software development
Locked
ageronimo
Posts: 29
Joined: 04 Dec 2012, 14:00

UDP output

Post by ageronimo » 17 Apr 2013, 17:45

Hi,

I recently upgraded from 3.0.1 to 3.0.5 and can no longer connect to an external application through UDP (Dasher). I think I have tracked down the problem but am not sure how to solve it. Running the 3.0.1 version of the CursorTask_gUSBamp batch file, I get the following UDP input in the Dasher socket debugger.

Code: Select all

...
Reading from socket...
 received string: 'ResultCode 0
'.
Reading from socket...
 received string: 'Feedback 0
'.
Reading from socket...
 received string: 'CursorPosX 0
'.
Matched label 'CursorPosX'...
...parsed value as 0.000000.
Socket input: clipped CursorPosX value of 0to configured minimum of 205
Socket input: new value for coordinate 0 rescales to 4096 in Dasher's internal c
oordinates (range 0-4096).
Matched label 'CursorPosX'...
...parsed value as 0.000000.
Socket input: clipped CursorPosX value of 0to configured minimum of 205
Socket input: new value for coordinate 1 rescales to 0 in Dasher's internal coor
dinates (range 0-4096).
Reading from socket...
 received string: 'CursorPosY 0
'.
Reading from socket...
 received string: 'CursorPosZ 0
'.
Reading from socket...
 received string: 'Running 1
'.
Reading from socket...
 received string: 'Recording 1
'.
Reading from socket...
 received string: 'SourceTime 60013
'.
Reading from socket...
 received string: 'StimulusTime 60019
'.
Reading from socket...
 received string: 'Signal(0,0) -0.0953556
'.
...
As opposed to the 3.0.5 version where i get:

Code: Select all

...
Reading from socket...
 received string: 'PauseApplication 0'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'CursorPosX 0'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'CursorPosY 0'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'CursorPosZ 0'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'StimulusTime 7163'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'Signal(0,0) -8.00468'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'Running 1'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'Recording 1'.
Reading from socket...
 received string: '
'.
Reading from socket...
 received string: 'SourceTime 7218'.
...
Both outputs have each state/signal separated by a return, but Dasher interprets them differently. How can I go about modifying this in the 3.0.5 version to be compatible with what Dasher expects to read?

Thanks in advance,
Andrew

ageronimo
Posts: 29
Joined: 04 Dec 2012, 14:00

Re: UDP output

Post by ageronimo » 17 Apr 2013, 20:26

Ok so I figured out a solution-- made the following changes to ConnectorFilters.cpp

Code: Select all

int
ConnectorOutput::Connection::OnExecute()
{
  const int cReactionTimeMs = 100;
  while( !IsTerminating() )
  {
    if( Wait( cReactionTimeMs ) )
    {
      Reset();
      bool result = true;
      while( result && !IsTerminating() )
      {
        string message;
        {
          ::Lock<Connection> lock( *this );
          result = std::getline( *this, message );
        }
        if( result && !IsTerminating() )
        { 
          //Used to Be
          //mSocket.write( message.c_str(), message.length() );
          //mSocket.write( "\n", 1 );

          // Changed for Dasher compatibility. AG 4/17/13
          message += "\n";
          mSocket.write( message.c_str(), message.length() );
         
        }
      }
    }
  }
  return 0;
}
It works now, but is this the best way to do it? Is there another way to do this that doesn't have me modify the core BCI2000 code?

Thanks,
Andrew

gschalk
Posts: 615
Joined: 28 Jan 2003, 12:37

Re: UDP output

Post by gschalk » 18 Apr 2013, 12:25

Hi,

You are saying it worked in 3.0.1 and now does not work in 3.0.5 (before you made that change)?

Gerv

ageronimo
Posts: 29
Joined: 04 Dec 2012, 14:00

Re: UDP output

Post by ageronimo » 20 Apr 2013, 11:42

Correct -- Dasher (version 4.1.1) was able to read the CursorPosX state over UDP when I was using BCI2000 3.0.1. When I upgraded to 3.0.5, Dasher was able to read the BCI2000 States, but my guess is that it the State outputs were formatted slightly differently and wasnt able to recognize that the CursorPosX variable had been sent. The change I made to ConnectorFilters.cpp was my attempt to put the UDP output in the exact format I was getting with 3.0.1. This seems to work now.

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: UDP output

Post by mellinger » 29 Apr 2013, 09:27

Hi,

thanks for reporting this problem. I was not aware there would be software out there that treated BCI2000's UDP output in form of individual packets, rather than a continuous stream of characters.

I fixed that issue in the current SVN version of BCI2000.

Regards,
Juergen

Locked

Who is online

Users browsing this forum: No registered users and 0 guests