public IInputData ReadStreamAsyncIO(HekaDAQInputStream stream)
        {
            lock (this)
            {
                var channelData = new ITCMM.ITCChannelDataEx[]
                {
                    new ITCMM.ITCChannelDataEx
                    {
                        ChannelNumber = stream.ChannelNumber,
                        ChannelType   = (ushort)stream.ChannelType
                    }
                };

                uint err = ItcmmCall(() => ITCMM.ITC_AsyncIO(DevicePtr, 1, channelData));
                if (err != ITCMM.ACQ_SUCCESS)
                {
                    throw new HekaDAQException("Unable to read AsyncIO", err);
                }

                var inData =
                    new InputData(
                        new List <IMeasurement> {
                    new Measurement(channelData[0].Value, HekaDAQInputStream.DAQCountUnits)
                },
                        new Measurement(0, "Hz"),
                        DateTimeOffset.Now)
                    .DataWithStreamConfiguration(stream, stream.Configuration);

                return(inData.DataWithUnits(stream.MeasurementConversionTarget));
            }
        }
        private void WriteAsyncIO(HekaDAQOutputStream stream, IMeasurement streamValue)
        {
            lock (this)
            {
                var channelData = new[]
                {
                    new ITCMM.ITCChannelDataEx
                    {
                        ChannelNumber = stream.ChannelNumber,
                        ChannelType   = (ushort)stream.ChannelType,
                        Value         =
                            (short)
                            Converters.Convert(streamValue, HekaDAQOutputStream.DAQCountUnits)
                            .QuantityInBaseUnit
                    }
                };

                uint err = ItcmmCall(() => ITCMM.ITC_AsyncIO(DevicePtr, 1, channelData));
                if (err != ITCMM.ACQ_SUCCESS)
                {
                    throw new HekaDAQException("Unable to write AsyncIO", err);
                }
            }
        }
        public void AsyncIORoundTrip()
        {
            HekkaDevice device = HekkaDevice.Zero;

            uint err = ITCMM.ITC_OpenDevice(ITCMM.USB18_ID, 0, ITCMM.SMART_MODE, out device);

            Assert.AreEqual(ITCMM.ACQ_SUCCESS,
                            err,
                            ErrorDescription.ErrorString(err)
                            );

            try
            {
                err = ITCMM.ITC_InitDevice(device, IntPtr.Zero); //ref sHWFunction);
                Assert.AreEqual(ITCMM.ACQ_SUCCESS,
                                err,
                                ErrorDescription.ErrorString(err)
                                );


                uint expectedValue = 8000;

                var channelData = new ITCMM.ITCChannelDataEx[] {
                    new ITCMM.ITCChannelDataEx {
                        ChannelNumber = 0,
                        ChannelType   = ITCMM.OUTPUT_GROUP,
                        Value         = (short)expectedValue
                    }
                };

                err = ITCMM.ITC_AsyncIO(device, 1, channelData);
                if (err != ITCMM.ACQ_SUCCESS)
                {
                    throw new HekaDAQException("Unable to write AsyncIO", err);
                }

                channelData = new ITCMM.ITCChannelDataEx[] {
                    new ITCMM.ITCChannelDataEx {
                        ChannelNumber = 0,
                        ChannelType   = ITCMM.INPUT_GROUP,
                        Value         = (short)expectedValue
                    }
                };

                err = ITCMM.ITC_AsyncIO(device, 1, channelData);
                if (err != ITCMM.ACQ_SUCCESS)
                {
                    throw new HekaDAQException("Unable to write AsyncIO", err);
                }

                var actualValue = channelData[0].Value;

                Assert.That(actualValue, Is.InRange(expectedValue - 50, expectedValue + 50));
            }
            finally
            {
                err = ITCMM.ITC_CloseDevice(device);
                Assert.AreEqual(ITCMM.ACQ_SUCCESS,
                                err,
                                ErrorDescription.ErrorString(err)
                                );
            }
        }