Beispiel #1
0
        private PicoDevice(PicoDeviceHandle handle)
        {
            this.handle       = handle;
            this.dataCallback = (string channelNames, IntPtr samplesPtr, UInt32 samplesPerChannel) =>
            {
                // Don't split the data out if we haven't got any listeners
                if (this.StreamingData.GetInvocationList().Length == 0)
                {
                    return;
                }

                var  channels      = channelNames.Split(',').Select(p => p.Trim(' ')).ToArray();
                uint srcStartIndex = 0;

                var outDict = new Dictionary <string, float[]>();

                foreach (var channel in channels)
                {
                    var channelData = new float[samplesPerChannel];
                    var srcStartPtr = new IntPtr(samplesPtr.ToInt64() + srcStartIndex);
                    Marshal.Copy(srcStartPtr, channelData, 0, (int)samplesPerChannel);

                    outDict.Add(channel, channelData);
                    srcStartIndex += samplesPerChannel;
                }

                this.StreamingData?.Invoke(this, new StreamingDataArgs(outDict));
            };

            if (Native.device_set_callback(this.handle, this.dataCallback) == false)
            {
                ThrowException();
            }
        }
 internal static extern bool device_set_callback(PicoDeviceHandle device, StreamingCallbackInternal callback);