private void saveRuntimeApplication(NodeRuntimeApplication runtimeApplicationToSave) { try { if (!Directory.Exists(COMMON_APPLICATION_DATA_FOLDER)) { Directory.CreateDirectory(COMMON_APPLICATION_DATA_FOLDER); } string fileName = Path.Combine(COMMON_APPLICATION_DATA_FOLDER, RUNTIME_APPLICATION_FILENAME); string signalFileName = Path.Combine(COMMON_APPLICATION_DATA_FOLDER, SIGNAL_STATE_FILENAME); if (runtimeApplicationToSave != null) { byte[] byteArray = Encoding.Unicode.GetBytes(runtimeApplicationToSave.ToXml()); File.WriteAllBytes(fileName, byteArray); byte[] signalByteArray = Encoding.Unicode.GetBytes(signalStateToBlob(runtimeApplicationToSave)); File.WriteAllBytes(signalFileName, signalByteArray); } else { if (File.Exists(fileName)) { File.Delete(fileName); } if (File.Exists(signalFileName)) { File.Delete(signalFileName); } } } catch { //FIXME - tie into error reporting feature, to be written } }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { bool set = context.RungCondition; bool reset = false; var signalIn = instruction.NodeSignalInChildren[0]; // reset var value = signalIn.GetValue(rta); if (value != null) { reset = Convert.ToBoolean(value.Value); } bool oldRungOutCondition = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value); bool newRungOutCondition; if (reset) { newRungOutCondition = false; } else if (set) { newRungOutCondition = true; } else { newRungOutCondition = oldRungOutCondition; } instruction.NodeSignalChildren[0].Value = newRungOutCondition; return(new InstructionGroupExecutorContextLD(newRungOutCondition)); }
private void ScanPage(NodeRuntimeApplication rta, NodePage page) { foreach (var instructionGroup in page.NodeInstructionGroupChildren) { ScanInstructionGroup(rta, instructionGroup); } }
private void ScanInstructionGroup(NodeRuntimeApplication rta, NodeInstructionGroup instructionGroup) { string language = instructionGroup.Language.ToString(); IGroupExecutor executor = null; if (m_groupExecutors.ContainsKey(language)) { executor = m_groupExecutors[language]; } else { // this only instantiates new language modules if we're actually using that language foreach (var executorSearch in groupExecutorsImported) { if (executorSearch.Metadata.Language == language) { executor = executorSearch.Value; m_groupExecutors.Add(language, executor); break; } } } if (executor != null) { executor.ScanInstructionGroup(rta, instructionGroup); } else { // FIXME - should report the error - we can't execute it } }
public void RuntimeApplicationGoOnline(NodeRuntimeApplication runtimeApplication) { if (runtimeApplication == null) { throw new ArgumentNullException("runtimeApplication"); } }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { // inputs: 0 = input1, 1 = input2 bool newRungOut = false; if (context.RungCondition) { Decimal input1 = 0; var signalIn = instruction.NodeSignalInChildren[0]; // input1 var value = signalIn.GetValue(rta); if (value != null) { input1 = Convert.ToDecimal(value.Value); } Decimal input2 = 0; signalIn = instruction.NodeSignalInChildren[1]; // input2 value = signalIn.GetValue(rta); if (value != null) { input2 = Convert.ToDecimal(value.Value); } newRungOut = Compare(input1, input2); } return(new InstructionGroupExecutorContextLD(newRungOut)); }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { instruction.NodeSignalChildren[0].Value = context.RungCondition; return(context); }
/// <summary> /// Restores the state of all signals from a blob string created by signalStateToBlob /// </summary> /// <param name="rta">Runtime application to restore to</param> /// <param name="blob">blob</param> private static void restoreSignalStateFromBlob(NodeRuntimeApplication rta, string blob) { if (rta == null) { throw new ArgumentNullException("rta"); } if (blob == null) { return; } var signalValues = EncodedSignalValue.ParseEncodedSignals(blob, rta.Signals); foreach (var signalTuple in signalValues) { NodeSignal signal = signalTuple.Item1; object value = signalTuple.Item2; try { signal.Value = value; } catch { // FIXME - tie into error reporting feature, to be developed } } }
public IRuntime OpenRuntime(NodeRuntimeApplication rta) { var comPort = rta.Address.ToString().ToUpper(); foreach (var rt in Runtimes) { var arduinoRuntimeProxy = rt as ArduinoRuntimeProxy; if (arduinoRuntimeProxy != null && arduinoRuntimeProxy.ComPort.ToUpper() == comPort.ToUpper()) { return(arduinoRuntimeProxy); } } ArduinoRuntimeProxy retVal = null; try { retVal = new ArduinoRuntimeProxy( this, comPort, this.m_runtimeService, this.messagingService); this.m_Runtimes.Add(retVal); } catch (ProtocolException ex) { this.messagingService.ShowMessage( ex.Message, "Error connecting to Runtime"); } return(retVal); }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { // inputs: 0 = input1, 1 = input2 // outputs: 0 = result Decimal input1 = 0; var signalIn = instruction.NodeSignalInChildren[0]; // input1 var value = signalIn.GetValue(rta); if (value != null) { input1 = Convert.ToDecimal(value.Value); } Decimal input2 = 0; signalIn = instruction.NodeSignalInChildren[1]; // input2 value = signalIn.GetValue(rta); if (value != null) { input2 = Convert.ToDecimal(value.Value); } Decimal oldResult = Convert.ToDecimal(instruction.NodeSignalChildren[0].Value); Decimal result = ComputeResult(context.RungCondition, input1, input2, oldResult); instruction.NodeSignalChildren[0].Value = result; return(context); }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { // inputs: 0 = setpoint, 1 = reset // outputs: 0 = counter done, 1 = count, 2 = oneshot state bool newRungOutCondition; Decimal newCount; Decimal setPoint = Decimal.MaxValue; // default to not turning on (for a long time) var signalIn = instruction.NodeSignalInChildren[0]; // setpoint var value = signalIn.GetValue(rta); if (value != null) { setPoint = Convert.ToDecimal(value.Value); } bool reset = false; signalIn = instruction.NodeSignalInChildren[1]; // reset value = signalIn.GetValue(rta); if (value != null) { reset = Convert.ToBoolean(value.Value); } bool oldRungOutCondition = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value); Decimal oldCount = Convert.ToDecimal(instruction.NodeSignalChildren[1].Value); bool oldOneshotState = Convert.ToBoolean(instruction.NodeSignalChildren[2].Value); if (reset) { newCount = 0; newRungOutCondition = false; } else if (oldRungOutCondition) // set - so latch until reset { // do nothing newCount = oldCount; newRungOutCondition = oldRungOutCondition; } else if (context.RungCondition && !oldOneshotState) // rising edge { newCount = Math.Min(setPoint, oldCount + 1); newRungOutCondition = newCount >= setPoint; } else { newCount = oldCount; newRungOutCondition = newCount >= setPoint; } instruction.NodeSignalChildren[0].Value = newRungOutCondition; instruction.NodeSignalChildren[1].Value = newCount; instruction.NodeSignalChildren[2].Value = context.RungCondition; // save state for next time return(new InstructionGroupExecutorContextLD(newRungOutCondition)); }
private NodeRuntimeApplication loadRuntimeApplication() { NodeRuntimeApplication readApplication = null; try { string fileName = Path.Combine(COMMON_APPLICATION_DATA_FOLDER, RUNTIME_APPLICATION_FILENAME); string xml = readFile(fileName); if (xml != null) { readApplication = NodeBase.NodeFromXML(xml, null) as NodeRuntimeApplication; if (readApplication != null) { string signalFileName = Path.Combine(COMMON_APPLICATION_DATA_FOLDER, SIGNAL_STATE_FILENAME); string blob = readFile(signalFileName); restoreSignalStateFromBlob(readApplication, blob); } } } catch { //FIXME - tie into future error reporting mechanism } return(readApplication); }
public void ScanOutputs(NodeDriver driver, NodeRuntimeApplication runtimeApplication) { // No outputs yet //foreach (var device in driver.NodeDeviceChildren.Items) //{ //} }
public SignalTreeClass(SignalChooserDialog dlg) { var tpl = dlg.runtimeService.FindParentPageAndRuntimeApp(dlg.NodeItem); NodePage pg = tpl.Item1; NodeRuntimeApplication rta = tpl.Item2; Items = BuildSignalTree(dlg, rta, pg, dlg.SignalId, dlg.m_dataTypefilter); }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { // inputs: 0 = count-down, 1 = reset // outputs: 0 = counter value is zero, 1 = count, 2 = previous count-up state, 3 = previous count-down state bool newRungOutCondition; Decimal newCount; bool countDown = false; var signalIn = instruction.NodeSignalInChildren[0]; // count-down var value = signalIn.GetValue(rta); if (value != null) { countDown = Convert.ToBoolean(value.Value); } bool reset = false; signalIn = instruction.NodeSignalInChildren[1]; // reset value = signalIn.GetValue(rta); if (value != null) { reset = Convert.ToBoolean(value.Value); } bool oldRungOutCondition = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value); Decimal oldCount = Convert.ToDecimal(instruction.NodeSignalChildren[1].Value); bool oldCountUpState = Convert.ToBoolean(instruction.NodeSignalChildren[2].Value); bool oldCountDownState = Convert.ToBoolean(instruction.NodeSignalChildren[3].Value); if (reset) { newCount = 0M; } else { newCount = oldCount; if (context.RungCondition && !oldCountUpState) // rising edge count up { newCount = newCount + 1; } if (countDown && !oldCountDownState) // rising edge count up { newCount = newCount - 1; } } newRungOutCondition = newCount == 0M; instruction.NodeSignalChildren[0].Value = newRungOutCondition; instruction.NodeSignalChildren[1].Value = newCount; instruction.NodeSignalChildren[2].Value = context.RungCondition; // save state for next time instruction.NodeSignalChildren[3].Value = countDown; // save state for next time return(new InstructionGroupExecutorContextLD(newRungOutCondition)); }
public RuntimeApplicationItem(ISolutionItem parent, NodeRuntimeApplication runtimeApplication) : base(parent, runtimeApplication.Code.ToString()) { ContextMenu = extensionService.Sort(contextMenu); RuntimeApplication = runtimeApplication; SetItems(); SetIconFromBitmap(Resources.Images.Disconnected); }
public bool RuntimeApplicationDownload(NodeRuntimeApplication runtimeApplication, bool onlineChange) { if (runtimeApplication == null) { throw new ArgumentNullException("runtimeApplication"); } m_communicationService.Value.SendDeltaToPeer(this, Peer, runtimeApplication, null); return(true); }
/// <summary> /// Stores the state of all signals into a string that can be saved to a file. /// </summary> /// <param name="rta">Runtime application to store the state of</param> /// <returns>blob</returns> private static string signalStateToBlob(NodeRuntimeApplication rta) { if (rta == null) { throw new ArgumentNullException("rta"); } var encodedSignals = from signal in rta.Signals select EncodedSignalValue.EncodeSignalValue(signal); return(string.Join(string.Empty, encodedSignals)); }
public void ScanInstructionGroup(NodeRuntimeApplication rta, NodeInstructionGroup instructionGroup) { var contextIterator = new InstructionGroupExecutorContextLD(true); // rung condition at the beginning of a rung is always true // A rung only ever has one series instruction as a child, so the foreach is kind of overkill, but should work foreach (var instruction in instructionGroup.NodeInstructionChildren) { contextIterator = ScanInstruction(rta, instruction, contextIterator); } }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { bool enable = context.RungCondition; string stringToSearch = string.Empty; var stringToSearchSignalIn = instruction.NodeSignalInChildren[0]; // stringToSearch var stringToSearchValue = stringToSearchSignalIn.GetValue(rta); if (stringToSearchValue != null) { stringToSearch = Convert.ToString(stringToSearchValue.Value); } string stringToFind = string.Empty; var stringToFindSignalIn = instruction.NodeSignalInChildren[1]; // stringToFind var stringToFindValue = stringToFindSignalIn.GetValue(rta); if (stringToFindValue != null) { stringToFind = Convert.ToString(stringToFindValue.Value); } bool caseSensitive = false; var caseSensitiveSignalIn = instruction.NodeSignalInChildren[2]; // caseSensitive var caseSensitiveValue = caseSensitiveSignalIn.GetValue(rta); if (caseSensitiveValue != null) { caseSensitive = Convert.ToBoolean(caseSensitiveValue.Value); } bool oldRungOutCondition = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value); bool newRungOutCondition; if (!enable) { newRungOutCondition = false; } else { if (caseSensitive) { newRungOutCondition = stringToSearch.Contains(stringToFind); } else { newRungOutCondition = stringToSearch.ToLower().Contains(stringToFind.ToLower()); } } instruction.NodeSignalChildren[0].Value = newRungOutCondition; return(new InstructionGroupExecutorContextLD(newRungOutCondition)); }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { var contextIterator = context; foreach (var childInstruction in instruction.NodeInstructionChildren) { contextIterator = groupExecutorLD.ScanInstruction(rta, childInstruction, contextIterator); } return contextIterator; }
public IRuntime OpenRuntime(NodeRuntimeApplication rta) { IRuntime retVal = null; foreach (var rt in Runtimes) { retVal = rt; break; } return(retVal); }
private void ScanPageCollection(NodeRuntimeApplication rta, NodePageCollection pageCollection) { foreach (var childPageCollection in pageCollection.NodePageCollectionChildren) { ScanPageCollection(rta, childPageCollection); } foreach (var childPage in pageCollection.NodePageChildren) { ScanPage(rta, childPage); } }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { bool oldRungOutCondition = Convert.ToBoolean(instruction.NodeSignalChildren[0].Value); bool newRungOutCondition; newRungOutCondition = oldRungOutCondition && !context.RungCondition; instruction.NodeSignalChildren[0].Value = context.RungCondition; return(new InstructionGroupExecutorContextLD(newRungOutCondition)); }
public InstructionGroupExecutorContextLD ScanInstruction(NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { var retVal = new InstructionGroupExecutorContextLD(false); if (m_instructionExecutors.ContainsKey(instruction.InstructionType)) { var executor = m_instructionExecutors[instruction.InstructionType]; retVal = executor.ScanInstruction(rta, instruction, context); } else { // FIXME - throw some kind of exception? } return(retVal); }
private void ScanIO(NodeRuntimeApplication rta, Action <IRuntimeDriver, NodeDriver> action) { foreach (var nDriver in rta.DeviceConfiguration.NodeDriverChildren) { if (nDriver.Running.BoolValue) { var nDriverGuid = new Guid(nDriver.TypeId.ToString()); foreach (IRuntimeDriver driver in drivers) // NOT threadsafe: won't support recomposition { if (driver.TypeId == nDriverGuid) { action(driver, nDriver); } } } } }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { var signalIn = instruction.NodeSignalInChildren[0]; var value = signalIn.GetValue(rta); if (value != null) { return(new InstructionGroupExecutorContextLD( context.RungCondition && (bool)(value.Value))); } else { return(new InstructionGroupExecutorContextLD(false)); } }
public InstructionGroupExecutorContextLD ScanInstruction( NodeRuntimeApplication rta, NodeInstruction instruction, InstructionGroupExecutorContextLD context) { bool mutableRungCondition = false; // OR's together the results foreach (var childInstruction in instruction.NodeInstructionChildren) { var contextResult = groupExecutorLD.ScanInstruction(rta, childInstruction, context); mutableRungCondition = contextResult.RungCondition || mutableRungCondition; } // Removed this because in some cases the rung-in condition doesn't have to be true for the output // of a branch to be true. Seems odd, but the best example of this is a FallingEdge instruction, // which is true on the scan that the rung-in condition goes false. //mutableRungCondition = context.RungCondition && mutableRungCondition; return(new InstructionGroupExecutorContextLD(mutableRungCondition)); }
/// <summary> /// Assumes the memento is the RuntimeId (FieldGuid) /// </summary> /// <param name="memento"></param> /// <returns></returns> public override IDocument CreateDocument(string memento) { if (memento == null) { // They want to create a new runtime application (not saved yet) var rtp = new RuntimeApplicationProperties(); rtp.Title = Resources.Strings.RuntimeApplication_NewTitle; rtp.m_editRuntimeApplication = NodeRuntimeApplication.BuildWith( new FieldIdentifier(Resources.Strings.RuntimeApplication_Code_Default), // Code new FieldGuid(firstRuntimeId()), // TypeId new FieldGuid(), // RuntimeId new FieldString(), // Address new FieldBase64(), // Configuration new FieldBool(false)); // ExecuteOnStartup return(rtp); } if (!m_docs.ContainsKey(memento)) { RuntimeApplicationItem item = null; foreach (var solutionItem in rootSolutionItem.Items) { RuntimeApplicationItem itemTest = solutionItem as RuntimeApplicationItem; if (itemTest != null) { if (itemTest.RuntimeApplication.RuntimeId.ToString() == memento) { item = itemTest; break; } } } if (item != null) { RuntimeApplicationProperties rtp = new RuntimeApplicationProperties(item); m_docs.Add(rtp.Memento, rtp); } else { return(null); } } return(m_docs[memento]); }
/// <summary> /// Returns a dictionary of signal names, and those signals, in a depth /// first search of the runtime application. For those signals within /// the same page, it has no prefix, but for those in other pages or /// in the device configuration, it adds a directory-like prefix. /// </summary> public Dictionary <string, NodeSignal> SignalList(INodeWrapper requester, FieldDataType.DataTypeEnum dataTypeFilter) { var dict = new Dictionary <string, NodeSignal>(); var tpl = FindParentPageAndRuntimeApp(requester); NodePage pg = tpl.Item1; NodeRuntimeApplication rta = tpl.Item2; if (rta != null) { if (pg != null) { // Search the local page first SignalsDepthFirst(pg, string.Empty, dict, pg, dataTypeFilter); } SignalsDepthFirst(rta, string.Empty, dict, pg, dataTypeFilter); } return(dict); }