Example #1
0
        public async Task <bool> WriteAsync(byte[] data, int timeout = 0)
        {
            var writeDelegate = new WriteDelegate(Write);

#if NET20 || NET35
            return(await Task <bool> .Factory.StartNew(() => writeDelegate.Invoke(data, timeout)));
#else
            return(await Task <bool> .Factory.FromAsync(writeDelegate.BeginInvoke, writeDelegate.EndInvoke, data, timeout, null));
#endif
        }
Example #2
0
        /// <summary>
        /// Подпрограмма выдачи данных
        /// </summary>
        /// <param name="channel">Номер канала для выдачи (допустимые значения от 1 до 16)</param>
        /// <param name="data">Массив выдаваемых данных</param>
        /// <param name="length">Количество выдаваемых слов (допустимые значения от 1 до 512)</param>
        /// <returns></returns>
        public int Write(ushort channel, uint[] data, uint length)
        {
            // Synchronously wait to enter the Semaphore.
            SemaphoreSlim.Wait();
            var gch   = GCHandle.Alloc(data, GCHandleType.Pinned);
            var error = _write?.Invoke(ref _device, channel, gch.AddrOfPinnedObject(), length) ?? int.MaxValue;

            gch.Free();
            // Release the Semaphore.
            SemaphoreSlim.Release();
            return(error);
        }