Exemple #1
0
 public bool TryStopTask()
 {
     //如果是主卡,判断是否有任何从卡没有完成,否则不能出来
     if (_staticConfig.TriggerConfig.MasterOrSlave == AITriggerMasterOrSlave.Master)
     {
         bool canOut = false;
         while (!canOut)
         {
             canOut = true;
             lock (TClockDevice.Lock)
             {
                 foreach (var s in TClockDevice.SlaveOver)
                 {
                     if (s.Value == false)
                     {
                         canOut = false;
                     }
                 }
             }
         }
     }
     //如果是从卡,设置让主卡可以出来
     else if (_staticConfig.TriggerConfig.MasterOrSlave == AITriggerMasterOrSlave.Slave)
     {
         lock (TClockDevice.Lock)
         {
             TClockDevice.SlaveOver[_staticConfig.ResourceName] = true;
         }
     }
     lock (TClockDevice.Lock)
     {
         if (TClockDevice.SyncDevices != null && TClockDevice.SyncDevices.Contains(scopeSession))
         {
             TClockDevice.SyncDevices.Remove(scopeSession);
         }
     }
     try
     {
         if (tClockSession != null)
         {
             tClockSession = null;
         }
         if (scopeSession != null)
         {
             scopeSession.Close();
             scopeSession.Dispose();
             scopeSession = null;
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.ToString());
     }
     AIState = Status.Idle;
     return(true);
 }
Exemple #2
0
        /// <summary>Synchronizes the RF and envelope signal generators, and initiates generation.</summary>
        /// <param name="rfVsg">The open RFSG session corresponding to the RF signal generator.</param>
        /// <param name="envVsg">The open RFSG session corresponding to the envelope signal generator.</param>
        /// <param name="syncConfig">Specifies common settings used for synchronizing the RF and envelope signal generators.</param>
        public static void InitiateSynchronousGeneration(NIRfsg rfVsg, NIRfsg envVsg, SynchronizationConfiguration syncConfig)
        {
            TClock tclk = new TClock(new ITClockSynchronizableDevice[] { rfVsg, envVsg });

            // The PXIe-5840 can only apply positive delays so we have to establish an inital delay of -RFDelayRange/2 for TCLK to handle negative shifts as well
            tclk.DevicesToSynchronize[0].SampleClockDelay = -syncConfig.RFDelayRange_s / 2.0;
            rfVsg.Arb.RelativeDelay = syncConfig.RFDelayRange_s / 2.0 + syncConfig.RFDelay_s;
            tclk.ConfigureForHomogeneousTriggers();
            tclk.Synchronize();
            tclk.Initiate();
        }
Exemple #3
0
        public static void Main()
        {
            Console.CursorVisible = false;
            Console.WriteLine("Ждем события!");
            Console.WindowWidth = 80;
            var t_time = new TClock(500, "Таймер 1: ");

            t_time.Ring += T_time_Ring;
            var t = new TClock(800, "Таймер 2: ");

            t.Ring += T_Ring;
            t.Start();
            Console.ReadLine();
            t.Dispose();
        }
Exemple #4
0
        private static void MapAndConfigTrigger(NIScope scopeSession, AITriggerConfiguration triggerConfiguration, ref TClock tClockSession)
        {
            //配置触发沿
            ScopeTriggerSlope triggerSlope;

            switch (triggerConfiguration.TriggerEdge)
            {
            case Edge.Rising:
                triggerSlope = ScopeTriggerSlope.Positive;
                break;

            case Edge.Falling:
                triggerSlope = ScopeTriggerSlope.Negative;
                break;

            default:
                throw new Exception("触发沿 TriggerEdge 设置错误!");
            }

            //设置触发源
            ScopeTriggerSource triggerSource = triggerConfiguration.TriggerSource.ToString();

            //设置触发模式
            switch (triggerConfiguration.TriggerType)
            {
            case AITriggerType.Immediate:
                scopeSession.Trigger.Type = ScopeTriggerType.Immediate;
                scopeSession.Trigger.ConfigureTriggerImmediate();
                break;

            case AITriggerType.DigitalTrigger:
                scopeSession.Trigger.Type = ScopeTriggerType.DigitalEdge;
                scopeSession.Trigger.ConfigureTriggerDigital(triggerSource, triggerSlope, PrecisionTimeSpan.Zero, new PrecisionTimeSpan(triggerConfiguration.Delay));
                break;

            case AITriggerType.AnalogTrigger:
                scopeSession.Trigger.Type = ScopeTriggerType.Edge;
                scopeSession.Trigger.EdgeTrigger.Configure(triggerSource, 2.5, triggerSlope, ScopeTriggerCoupling.DC, PrecisionTimeSpan.Zero, new PrecisionTimeSpan(triggerConfiguration.Delay));
                break;

            default:
                throw new Exception("触发模式 TriggerType 设置错误!");
            }

            //如果不是非同步
            //加入到TClock中
            if (triggerConfiguration.MasterOrSlave != AITriggerMasterOrSlave.NonSync)
            {
                lock (TClockDevice.Lock)
                {
                    if (TClockDevice.SyncDevices == null)
                    {
                        TClockDevice.SyncDevices = new List <NIScope>();
                    }
                    TClockDevice.SyncDevices.Add(scopeSession);
                }
            }

            //如果是主卡,则将所有的 SynchronizableDevices 实例化出来,这样写也就决定了只能有一个 Master( NI 机箱可级联支持双 Master)
            //这一行必须是在所有需要同步的卡 scopeSession 设置完毕之后
            if (triggerConfiguration.MasterOrSlave == AITriggerMasterOrSlave.Master)
            {
                TClockDevice.IsMasterReady            = false;
                TClockDevice.IsSlaveCanAddIntoTDevice = true;

                //因为主卡可能会和从卡同时被 Arm,因此先等待所有从卡设备加入 TClockDevice
                Thread.Sleep(1000);

                TClockDevice.IsSlaveCanAddIntoTDevice = false;

                ITClockSynchronizableDevice[] scopeSynchronizableDevices = new ITClockSynchronizableDevice[TClockDevice.SyncDevices.Count];
                for (int i = 0; i < TClockDevice.SyncDevices.Count; i++)
                {
                    scopeSynchronizableDevices[i] = TClockDevice.SyncDevices[i];
                }
                tClockSession = new TClock(scopeSynchronizableDevices);
                tClockSession.ConfigureForHomogeneousTriggers();
                tClockSession.Synchronize();
            }
        }
Exemple #5
0
        /// <summary>
        /// 配置已经实例化的 scopeSession,包括通道设置、时钟设置以及触发设置
        /// </summary>
        /// <param name="niTask"></param>
        /// <param name="channelConfiguration"></param>
        public static void MapAndConfigAll(NIScope scopeSession, NIScopeAIStaticConfig basicAIConifg, ref TClock tClockSession)
        {
            if (basicAIConifg.MoreRecordsThanMemoryAllowed == true)
            {
                throw new Exception("暂时不支持超内存采样!");
            }
            scopeSession.Timing.MoreRecordsThanMemoryAllowed = basicAIConifg.MoreRecordsThanMemoryAllowed;

            MapAndConfigTrigger(scopeSession, basicAIConifg.TriggerConfig, ref tClockSession);
            MapAndConfigClock(scopeSession, basicAIConifg.ClockConfig);
            MapAndConfigChannel(scopeSession, basicAIConifg.ChannelConfig);
        }