示例#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_stop_streaming(PicoDeviceHandle device);
 internal static extern UInt32 device_start_streaming(PicoDeviceHandle device, UInt32 samples_per_second);
 internal static extern bool device_set_callback(PicoDeviceHandle device, StreamingCallbackInternal callback);
 internal static extern bool device_disable_channel(PicoDeviceHandle device, string channel);
 internal static extern bool device_enable_channel(PicoDeviceHandle device, string channel, string range, string coupling);
 internal static extern StringHandle device_get_channel_ranges(PicoDeviceHandle device, string channel);
 internal static extern StringHandle device_get_variant(PicoDeviceHandle device);
 internal static extern StringHandle device_get_serial(PicoDeviceHandle device);