예제 #1
0
        public async ValueTask DisposeAsync()
        {
            var stopCts = Interlocked.Exchange(ref StopCts, null !);

            if (stopCts != null)
            {
                return;
            }

            try {
                StopCts.Cancel();
            }
            catch {
                // Dispose shouldn't throw exceptions
            }
            await ReaderTask.SuppressExceptions().ConfigureAwait(false);

            await WriterTask.SuppressExceptions().ConfigureAwait(false);

            try {
            }
            catch {
                // Dispose shouldn't throw exceptions
            }
            finally {
                if (OwnsWebSocket)
                {
                    WebSocket.Dispose();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Sets the position of the galvo.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public virtual void SetPosition(double x, double y, bool async = false)
        {
            ConfigureTask(1);

            IsWriting = true;
            if (WriterTask.IsDone)
            {
                WriterTask.Start();
            }
            MCWriter.WriteSingleSample(false, new double[] { x, y });
            System.Threading.Thread.Sleep(10);
            IsWriting = false;
        }
예제 #3
0
        public virtual void WriteScan(double[,] positions, bool async = true,
                                      string triggerSource            = null, DigitalEdgeStartTriggerEdge edge = DigitalEdgeStartTriggerEdge.Rising)
        {
            // Go to initial position. (before the scan starts);
            SetPosition(positions[0, 0], positions[0, 1]);

            // Confugyre the task and force recration of the task.
            ConfigureTask(positions.GetLength(1) * positions.GetLength(0), true);

            // If there is a trigger source then we are currently waiting to writer trigger.
            if (triggerSource != null)
            {
                WriterTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(triggerSource, edge);
                IsWaitingForWriteStartEvent = false;
                IsWriting = true;
            }
            else
            {
                IsWaitingForWriteStartEvent = true;
                IsWriting = false;
            }

            // define the start action.
            TotalScanTicks = positions.GetLength(1);

            MCWriter.WriteMultiSample(false, positions);
            //MCWriter.BeginWriteMultiSample(false, positions, (IAsyncResult rslt) =>
            //{
            //    //CallWriteScanEnd();
            //}, null);

            if (WriterTask.IsDone)
            {
                WriterTask.Start();
            }

            CallStartScanEvent();

            if (triggerSource != null)
            {
                CallStartScanEvent();
            }

            if (!async)
            {
                while (IsWriting || IsWaitingForWriteStartEvent)
                {
                    System.Threading.Thread.Sleep(10);
                }
            }
        }