// Return a float matrix array of the latest data in the FieldTrip buffer public float[,] GetData() { if (!C.isConnected()) { return(null); } // Poll for the new data SamplesEventsCount sampevents = C.poll(); // Remember the Num samples in buffer so far if (nSamples == 0) { nSamples = sampevents.nSamples; } if (sampevents.nSamples == nSamples) { return(null); } if (sampevents.nSamples < nSamples) { nSamples = sampevents.nSamples - 1; return(null); } // Get just the newest data float[,] data = C.getFloatData(nSamples, sampevents.nSamples - 1); // Update the Num samples in buffer so far nSamples = sampevents.nSamples - 1; return(data); }
public float[] GetEventArray(string commandType) { if (!C.isConnected()) { return(null); } // Poll for the new events SamplesEventsCount sampevents = C.poll(); // Remember the num events in buffer so far if (nEvents == 0) { nEvents = sampevents.nEvents - 2; } if (sampevents.nEvents - 1 == nEvents) { return(null); } if (sampevents.nEvents < nEvents) { nEvents = sampevents.nEvents; return(null); } // Get just the newest events BufferEvent[] events = C.getEvents(nEvents, sampevents.nEvents - 1); // Update the Num events in buffer so far nEvents = sampevents.nEvents - 1; // Parse the event array and find the specified commandType event type // Return the array of values link to that event foreach (BufferEvent evt in events) { // check if the type is one we care about //ATTENTION: for buffer events use toString() lowercase NOT ToString() if (evt.getType().toString().Equals(commandType)) // check if this event type matches //Convert.ToSingle(evt.getValue().array); //return Convert.ToSingle(evt.getValue().array); //return double.Parse(evt.getValue().toString()); { return((float[])evt.getValue().array); //if (evt.getValue().toString().Equals(valueType)) { // check if the event value matches // processEvent(evt); //} } } return(null); }
virtual public SamplesEventsCount wait(int nSamples, int nEvents, int timeout) { ByteBuffer buf; SamplesEventsCount secount = null; buf = ByteBuffer.allocate(20); buf.order(myOrder); buf.putShort(VERSION).putShort(WAIT_DAT).putInt(12); buf.putInt(nSamples).putInt(nEvents).putInt(timeout).rewind(); writeAll(buf); buf = readResponse(WAIT_OK); secount = new SamplesEventsCount(buf.getInt(), buf.getInt()); return(secount); }
// use the returned sample info to update the clock sync override public SamplesEventsCount wait(int nSamples, int nEvents, int timeout) { //Console.WriteLine("clock update"); SamplesEventsCount secount = base.wait(nSamples, nEvents, timeout); double deltaSamples = clockSync.getSamp() - secount.nSamples; // delta between true and estimated //Console.WriteLine("sampErr="+getSampErr() + " d(samp) " + deltaSamples + " sampThresh= " + clockSync.m*1000.0*.5); if (getSampErr() < maxSampError) { if (deltaSamples > clockSync.m * 1000.0 * .5) // lost samples { Console.WriteLine(deltaSamples + " Lost samples detected"); clockSync.reset(); //clockSync.b = clockSync.b - deltaSamples; } else if (deltaSamples < -clockSync.m * 1000.0 * .5) // extra samples { Console.WriteLine(-deltaSamples + " Extra samples detected"); clockSync.reset(); } } clockSync.updateClock(secount.nSamples); // update the rt->sample mapping return(secount); }