/// <summary> /// Adds a guardless permitted transition to the state configuration. /// </summary> /// <param name="trigger">The trigger that this state should accept.</param> /// <returns></returns> public TriggerConfiguration On(TTrigger trigger) { var existingConfig = GetConfigurationByTrigger(trigger); if (existingConfig != null) { // Does the existing configuration have a guard clause? if (existingConfig.GuardClause != null) { throw new SolidStateException( string.Format( "State {0} has at least one guarded transition configured on trigger {1} already. A state cannot have both guardless and guarded transitions at the same time!", _stateType.Name, trigger)); } else { throw new SolidStateException(string.Format( "Trigger {0} has already been configured for state {1}!", trigger, _stateType.Name)); } } var newConfiguration = new TriggerConfiguration(trigger, null, this); _triggerConfigurations.Add(newConfiguration); return(newConfiguration); }
public static void Main() { string DigitalPath = Path.GetFullPath(@"Digital Project"); string pinMapPath = Path.Combine(DigitalPath, "PinMap.pinmap"); string specPath = Path.Combine(DigitalPath, "Specifications.specs"); string levelsPath = Path.Combine(DigitalPath, "PinLevels.digilevels"); string timingPath = Path.Combine(DigitalPath, "Timing.digitiming"); string[] patternPaths = Directory.GetFiles(Path.Combine(DigitalPath, "RFFE Command Patterns"), "*.digipat"); ProjectFiles projectFiles = new ProjectFiles { PinMapFile = pinMapPath, SpecificationsFiles = new string[1] { specPath }, PinLevelsFiles = new string[1] { levelsPath }, TimingFiles = new string[1] { timingPath }, DigitalPatternFiles = patternPaths }; //Initialize hardware and load pinmap plus sheets into //digital pattern instrument. Most of the fucntions below are //a lightweight wrapper around NI - Digital functions. //If you change the insturment name below, you must also change the instrument name //in the PinMap file NIDigital digital = new NIDigital("PXIe-6570", false, false, ""); LoadProjectFiles(digital, projectFiles); //Turn RFFE bus power on digital.PinAndChannelMap.GetPinSet("RFFEVIO").WriteStatic(PinState._1); //Setup new register data to send to register 0 RegisterData regData = new RegisterData { SlaveAddress = 0xF, //15 WriteRegisterData = new byte[1] { 0x8 }, ByteCount = 1 }; //Trgger type is set to none so burst will start immediately TriggerConfiguration triggerConfig = new TriggerConfiguration { BurstTriggerType = TriggerType.None, }; //Burst a Reg0Write command using the data specified in regData BurstRFFE(digital, regData, "RFFEDATA", RFFECommand.Reg0Write, triggerConfig); Console.ReadKey(); DisconnectAndClose(digital); }
public TriggerConfiguration On(TTrigger trigger, Func <bool> guardClause) { if (guardClause == null) { throw new ArgumentNullException("guardClause"); } var existingConfig = GetConfigurationByTrigger(trigger); if (existingConfig != null) { // It's OK that there are multiple configurations of the same trigger, as long as they all have guard clauses if (existingConfig.GuardClause == null) { throw new SolidStateException( string.Format( "State {0} has an unguarded transition for trigger {1}, you cannot add guarded transitions to this state as well!", _stateType.Name, trigger)); } } var newConfiguration = new TriggerConfiguration(trigger, guardClause, this); _triggerConfigurations.Add(newConfiguration); return(newConfiguration); }
/// <summary> /// Handles the processing of a trigger, calculating if it is valid and which target state we should go to. /// </summary> /// <param name="trigger"></param> private void DoTrigger(TTrigger trigger) { // Find all trigger configurations with a matching trigger var triggers = _currentState.TriggerConfigurations.Where(x => x.Trigger.Equals(trigger)).ToList(); // No trigger configs found? if (triggers.Count == 0) { // Do we have a handler for the situation? if (_invalidTriggerHandler == null) { throw new SolidStateException(string.Format("Trigger {0} is not valid for state {1}!", trigger, _currentState.StateType.Name)); } // Let the handler decide what to do _invalidTriggerHandler(_currentState.StateType, trigger); } else { // Is it a single, unguarded trigger? if (triggers[0].GuardClause == null) { var previousStateType = ExitCurrentState(addToHistory: true); EnterNewState(previousStateType, triggers[0].TargetState); } else { // First exit the current state, it may affect the evaluation of the guard clauses var previousStateType = ExitCurrentState(addToHistory: true); TriggerConfiguration matchingTrigger = null; foreach (var tr in triggers) { if (tr.GuardClause()) { if (matchingTrigger != null) { throw new SolidStateException(string.Format( "State {0}, trigger {1} has multiple guard clauses that simultaneously evaulate to True!", previousStateType.Name, trigger)); } matchingTrigger = tr; } } // Did we find a matching trigger? if (matchingTrigger == null) { throw new SolidStateException(string.Format( "State {0}, trigger {1} has no guard clause that evaulate to True!", previousStateType.Name, trigger)); } // Queue up the transition EnterNewState(previousStateType, matchingTrigger.TargetState); } } }
static void Main() { NIDigital digital = new NIDigital("PXIe-6570", false, false, ""); string pinMapPath = Path.GetFullPath(@"Support Files\PinMap.pinmap"); string specPath = Path.GetFullPath(@"Support Files\Specifications.specs"); string levelsPath = Path.GetFullPath(@"Support Files\PinLevels.digilevels"); string timingPath = Path.GetFullPath(@"Support Files\Timing.digitiming"); string patternPath = Path.GetFullPath(@"Support Files\Pattern.digipat"); ProjectFiles projectFiles = new ProjectFiles { PinMapFile = pinMapPath, SpecificationsFiles = new string[1] { specPath }, PinLevelsFiles = new string[1] { levelsPath }, TimingFiles = new string[1] { timingPath }, DigitalPatternFiles = new string[1] { patternPath } }; // Alternatively, you could use the following command to search for all matching NI-Digital project files // projectFiles = Digital.Utilities.SearchForProjectFiles(Path.GetFullPath(@"Support Files\"), true) LoadProjectFiles(digital, projectFiles); SourcePinConfiguration sourcePin = SourcePinConfiguration.GetDefault(); sourcePin.PinName = "DUTPin1"; ConfigureAndSourcePin(digital, sourcePin); TriggerConfiguration triggerConfig = new TriggerConfiguration { BurstTriggerType = TriggerType.None }; InitiatePatternGeneration(digital, "new_pattern", triggerConfig); Console.WriteLine("Pattern generation has begun. Press any key to abort, disconnect pins, and close the program."); Console.ReadKey(); digital.PatternControl.Abort(); DisconnectAndClose(digital); }
static void Main() { NIDigital digital = new NIDigital("PXI1Slot2", false, false, ""); string pinMapPath = Path.GetFullPath(@"Support Files\PinMap.pinmap"); string specPath = Path.GetFullPath(@"Support Files\Specifications.specs"); string levelsPath = Path.GetFullPath(@"Support Files\PinLevels.digilevels"); string timingPath = Path.GetFullPath(@"Support Files\Timing.digitiming"); string patternPath = Path.GetFullPath(@"Support Files\Pattern.digipat"); ProjectFiles projectFiles = new ProjectFiles { PinMapFile = pinMapPath, SpecificationsFiles = new string[1] { specPath }, PinLevelsFiles = new string[1] { levelsPath }, TimingFiles = new string[1] { timingPath }, DigitalPatternFiles = new string[1] { patternPath } }; LoadProjectFiles(digital, projectFiles); SourcePinConfiguration sourcePin = GetDefaultSourcePinConfiguration(); sourcePin.PinName = "DUTPin1"; ConfigureAndSourcePin(digital, sourcePin); TriggerConfiguration triggerConfig = new TriggerConfiguration { BurstTriggerType = TriggerType.None }; InitiatePatternGeneration(digital, "new_pattern", triggerConfig); digital.PatternControl.Abort(); DisconnectAndClose(digital); }
public static ReadData BurstRFFE(NIDigital niDigital, RegisterData regData, string pinName, RFFECommand rffeCommand, TriggerConfiguration triggerConfig) { //Check data is valid rffeCommand.ValidateLogic(regData); //Create source and capture waveforms in driver CreateRFFEWaveforms(niDigital, pinName, rffeCommand); //Create dynamic source waveform data for selected command rffeCommand.CreateSourceData(regData, out uint[] sourceData, out int byteCount); niDigital.SourceWaveforms.WriteBroadcast(rffeCommand.SourceName, sourceData); //reg0 set based on amount of bytes used niDigital.PatternControl.WriteSequencerRegister("reg0", byteCount); //Burst pattern based on the input trigger settings Digital.InitiatePatternGeneration(niDigital, rffeCommand.SourceName, triggerConfig); //On read calls only, return capture data return(new ReadData()); }
public static void InitiatePatternGeneration(NIDigital nIDigital, string patternStartLabel, TriggerConfiguration triggerConfig) { switch (triggerConfig.BurstTriggerType) { case TriggerType.Software: nIDigital.Trigger.StartTrigger.Software.Configure(); // This call to BurstPattern returns immediately because waitUntilDone is 'false.' nIDigital.PatternControl.BurstPattern(string.Empty, patternStartLabel, true, false, TimeSpan.FromSeconds(10)); break; case TriggerType.DigitalEdge: nIDigital.Trigger.StartTrigger.DigitalEdge.Configure(triggerConfig.DigitalEdgeSource, triggerConfig.DigitalEdgeType); // This call to BurstPattern returns immediately because waitUntilDone is 'false.' nIDigital.PatternControl.BurstPattern("", patternStartLabel, true, false, TimeSpan.FromSeconds(10)); break; case TriggerType.None: nIDigital.PatternControl.BurstPattern(string.Empty, patternStartLabel, true, TimeSpan.FromSeconds(10)); break; } }
public ITriggerConfiguration ConfigureTrigger() { TriggerConfiguration = new TriggerConfiguration(this); return(TriggerConfiguration); }
public void activateThumbTriggerConfiguration() { logger.Log($"activateThumbTriggerConfiguration"); triggerConfiguration = TriggerConfiguration.Thumb; }
public void activatePointerTriggerConfiguration() { logger.Log($"activatePointerTriggerConfiguration"); triggerConfiguration = TriggerConfiguration.Pointer; }
/// <summary> /// TODO The crete json trigger configuration template. /// </summary> /// <param name="triggerObject"> /// TODO The bubbling event. /// </param> /// <returns> /// The <see cref="string" />. /// </returns> public static string CreteJsonTriggerConfigurationTemplate(ITriggerAssembly triggerObject) { var eventCorrelationTemplate = new Event( "{Event component ID to execute if Correlation = true}", "{Configuration ID to execute if Correlation = true}", "Event Name Sample", "Event Description Sample"); try { var triggerConfiguration = new TriggerConfiguration(); triggerConfiguration.Trigger = new Trigger( triggerObject.Id, Guid.NewGuid().ToString(), triggerObject.Name, triggerObject.Description); triggerConfiguration.Trigger.TriggerProperties = new List <TriggerProperty>(); foreach (var Property in triggerObject.Properties) { if (Property.Value.Name != "DataContext") { var triggerProperty = new TriggerProperty(Property.Value.Name, "Value to set"); triggerConfiguration.Trigger.TriggerProperties.Add(triggerProperty); } } triggerConfiguration.Events = new List <Event>(); // 1* var eventTriggerTemplate = new Event( "{Event component ID Sample to execute}", "{Configuration ID Sample to execute}", "Event Name Sample", "Event Description Sample"); eventTriggerTemplate.Channels = new List <Channel>(); var points = new List <Point>(); points.Add(new Point("Point ID Sample", "Point Name Sample", "Point Description Sample")); eventTriggerTemplate.Channels.Add( new Channel("Channel ID Sample", "Channel Name Sample", "Channel Description Sample", points)); eventCorrelationTemplate.Channels = new List <Channel>(); eventCorrelationTemplate.Channels.Add( new Channel("Channel ID Sample", "Channel Name Sample", "Channel Description Sample", points)); triggerConfiguration.Events.Add(eventTriggerTemplate); var events = new List <Event>(); events.Add(eventCorrelationTemplate); eventTriggerTemplate.Correlation = new Correlation("Correlation Name Sample", "C# script", events); var serializedMessage = JsonConvert.SerializeObject( triggerConfiguration, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); // string serializedMessage = JsonConvert.SerializeObject(triggerConfiguration); return(serializedMessage); // return "<![CDATA[" + serializedMessage + "]]>"; } catch (Exception ex) { return(ex.Message); } }