示例#1
0
 /// <summary>
 /// Closes the device.
 /// </summary>
 /// <returns></returns>
 public async Task CloseAsync()
 {
     if (m_cts != null)
     {
         if (m_cts != null)
         {
             m_cts.Cancel();
         }
         m_cts = null;
     }
     if (m_ParserTask != null)
     {
         await m_ParserTask;
     }
     if (m_stream != null)
     {
         await CloseStreamAsync(m_stream);
     }
     MultiPartMessageCache.Clear();
     m_stream = null;
     lock (m_lockObject)
     {
         m_isOpening = false;
         IsOpen      = false;
     }
 }
示例#2
0
        /// <summary>
        /// Opens the device connection.
        /// </summary>
        /// <returns></returns>
        public async Task OpenAsync()
        {
            lock (m_lockObject)
            {
                if (IsOpen)
                {
                    return;
                }
                IsOpen = true;
            }
            m_cts    = new System.Threading.CancellationTokenSource();
            m_stream = await OpenStreamAsync();

            StartParser();
            MultiPartMessageCache.Clear();
        }
示例#3
0
        /// <summary>
        /// Closes the device.
        /// </summary>
        /// <returns></returns>
        public async Task CloseAsync()
        {
            if (m_cts != null)
            {
                closeTask = new TaskCompletionSource <bool>();
                if (m_cts != null)
                {
                    m_cts.Cancel();
                }
                m_cts = null;
            }
            await closeTask.Task;

            await CloseStreamAsync(m_stream);

            MultiPartMessageCache.Clear();
            m_stream = null;
            lock (m_lockObject)
                IsOpen = false;
        }
示例#4
0
        /// <summary>
        /// Opens the device connection.
        /// </summary>
        /// <returns></returns>
        public async Task OpenAsync()
        {
            lock (m_lockObject)
            {
                if (IsOpen || m_isOpening)
                {
                    return;
                }
                m_isOpening = true;
            }
            m_cts    = new CancellationTokenSource();
            m_stream = await OpenStreamAsync();

            StartParser(m_cts.Token);
            MultiPartMessageCache.Clear();
            lock (m_lockObject)
            {
                IsOpen      = true;
                m_isOpening = false;
            }
        }