private void ProcessStream1D(NodeSystemLib2.FormatData1D.InputPortData1D port) { var _buffer = port.Read(); WriterObject writer = null; Stream1DWriter stream = null; if (_recording) { writer = _writers[port]; stream = (Stream1DWriter)writer.Writer; } foreach (var sample in _buffer.ZipWithValueInput(_portEn)) { if (sample.Scalar >= 0.5 && !_recording) { _firstWrittenSampleTime = sample.Stamp; StartRecording(); writer = _writers[port]; stream = (Stream1DWriter)writer.Writer; } else if (sample.Scalar < 0.5 && _recording) { EndRecording(); } if (_recording) { stream.WriteSample(sample.Sample); writer.SetNewStamp(sample.Stamp); } } }
private void Recorder2_PortConnectionChanged(object sender, ConnectionModifiedEventArgs e) { if (changingConnections) { return; } changingConnections = true; UpdateInputPorts(); var dataInputs = InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>(); if (dataInputs.All(d => d.Connection != null)) { var p = new NodeSystemLib2.FormatData1D.InputPortData1D(this, $"DIn {dataInputs.Count() + 1}"); AddPort(p, EnablePortIndex); } var valueInputs = InputPorts.OfType <NodeSystemLib2.FormatValue.InputPortValueDouble>().Except(new [] { _portEn }); if (valueInputs.All(d => d.Connection != null)) { var p = new NodeSystemLib2.FormatValue.InputPortValueDouble(this, $"VIn {valueInputs.Count() + 1}"); AddPort(p, EnablePortIndex); } changingConnections = false; }
public Recorder2(Graph g) : base("Recorder 2", g) { _firstDataIn = new NodeSystemLib2.FormatData1D.InputPortData1D(this, "DIn 1"); _firstValueIn = new NodeSystemLib2.FormatValue.InputPortValueDouble(this, "VIn 1"); _portEn = new NodeSystemLib2.FormatValue.InputPortValueDouble(this, "En"); this.PortConnectionChanged += Recorder2_PortConnectionChanged; }
public MetricAnalogOutput(NidaqSingleton.Device device, NidaqSingleton.Channel channel, Graph g) : base("AO " + channel.Path, g, UniquenessBy(channel)) { _portIn = new NodeSystemLib2.FormatData1D.InputPortData1D(this, "In"); Channel = channel; Device = device; Session = NidaqSingleton.Instance.AddToSession(this); }
private void UpdateDisplay(NodeSystemLib2.FormatData1D.InputPortData1D port) { labelTime.Text = "Time: " + port.Time.AsTimeSpan().ToString("c"); if (port.Capacity == 0) { SetPercent(0); } else { SetPercent(port.Available / (double)port.Capacity); } }
public MetricFFT(Graph graph) : base("FFT", graph) { _portOut = new NodeSystemLib2.FormatDataFFT.OutputPortDataFFT(this, "out"); _portInp = new NodeSystemLib2.FormatData1D.InputPortData1D(this, "in"); _portInp.SamplerateChanged += (s, e) => _portOut.Samplerate = _portInp.Samplerate; _attrFFTSize = new NodeSystemLib2.Generic.NodeAttributes.AttributeValueInt(this, "FFT Size", "Samples", (x) => x < 2 ? 2 : (int)Math.Pow(2, Math.Round(Math.Log(x, 2))) ); _attrFFTSize.SetRuntimeReadonly(); _attrFFTSize.Changed += (s, e) => _portOut.FFTSize = _attrFFTSize.TypedGet(); _attrFFTSize.Set(512); }
private void CreateLine(PortDataType type) { Func <int> PortCount = () => _lines.Count(l => l.Port.DataType.Equals(type)); RecorderLine line = null; if (type == PortDataTypes.TypeIdValueDouble) { var port = new NodeSystemLib2.FormatValue.InputPortValueDouble(this, $"{_portTypePrefix[type]}{PortCount()}"); line = new RecorderLineValue(port, this); } else if (type == PortDataTypes.TypeIdSignal1D) { var port = new NodeSystemLib2.FormatData1D.InputPortData1D(this, $"{_portTypePrefix[type]}{PortCount()}"); line = new RecorderLine1D(port, this); } else { throw new ArgumentException(nameof(type)); } line.Port.ConnectionChanged += LineStateChanged; _lines.Add(line); }
public Accumulator(Graph g) : base(g) { Name = "Accumulator"; _portIn = new NodeSystemLib2.FormatData1D.InputPortData1D(this, "In"); }
public RecorderLine1D(NodeSystemLib2.FormatData1D.InputPortData1D port, Recorder3 parent) : base(port, parent) { }
private void _attrFuncName_Changed(object sender, AttributeChangedEventArgs e) { for (int i = InputPorts.Count - 1; i >= 0; i--) { RemovePort(InputPorts[i]); } for (int i = OutputPorts.Count - 1; i >= 0; i--) { RemovePort(OutputPorts[i]); } if (string.IsNullOrEmpty(_attrFuncName.TypedGet())) { return; } if (_matlab == null) { if (!TryFindMatlab()) { Parent.Context.Notify(new GraphNotification(GraphNotification.NotificationType.Warning, "No matlab instance found. Make sure to enable the automation server:\nenableservice('AutomationServer', true)")); return; } } var funcHeader = FindFunction(); if (funcHeader == null) { Parent.Context.Notify(new GraphNotification(GraphNotification.NotificationType.Warning, $"Function {_attrFuncName.TypedGet()} not found or uses unsupported syntax in function header")); return; } foreach (var param in funcHeader.Parameters) { if (param.StartsWith("data")) { var port = new NodeSystemLib2.FormatData1D.InputPortData1D(this, param.Substring("data".Length)); port.SamplerateChanged += Port_SamplerateChanged; } else if (param.StartsWith("value")) { new NodeSystemLib2.FormatValue.InputPortValueDouble(this, param.Substring("value".Length)); } else { Parent.Context.Notify(new GraphNotification(GraphNotification.NotificationType.Warning, $"Unknown type of port: {param}")); } } foreach (var param in funcHeader.ReturnValues) { if (param.StartsWith("data")) { new NodeSystemLib2.FormatData1D.OutputPortData1D(this, param.Substring("data".Length)); } else if (param.StartsWith("value")) { new NodeSystemLib2.FormatValue.OutputPortValueDouble(this, param.Substring("value".Length)); } else if (param.StartsWith("used_")) { // used count } else { Parent.Context.Notify(new GraphNotification(GraphNotification.NotificationType.Warning, $"Unknown type of return value: {param}")); } } }