コード例 #1
0
ファイル: GenericState.cs プロジェクト: GeneralKenobi/ECAT
        /// <summary>
        /// Constructor with parameters
        /// </summary>
        /// <param name="nodeIndices">Nodes present in this instance</param>
        /// <param name="activeComponentsIndices">Active components indices present in this instance</param>
        /// <param name="defaultValueFactory">Func used for generating initial values in <see cref="Potentials"/> and <see cref="Currents"/>,
        /// if null (which is the default value) <see cref="default(T)"/> will be used</param>
        /// <param name="sourceDescription">Description of source that produced this state. Can be null - it means that it's indetermined or
        /// many sources produced this state</param>
        public GenericState(IEnumerable <int> nodeIndices, IEnumerable <int> activeComponentsIndices, ISourceDescription sourceDescription,
                            Func <T> defaultValueFactory = null)
        {
            // Null checks
            if (nodeIndices == null)
            {
                throw new ArgumentNullException(nameof(nodeIndices));
            }

            if (activeComponentsIndices == null)
            {
                throw new ArgumentNullException(nameof(activeComponentsIndices));
            }

            // Make an entry for each node
            foreach (var node in nodeIndices)
            {
                Potentials.Add(node, defaultValueFactory == null ? default(T) : defaultValueFactory());
            }

            // Make an entry for each index
            foreach (var index in activeComponentsIndices)
            {
                Currents.Add(index, defaultValueFactory == null ? default(T) : defaultValueFactory());
            }

            // Assign source description
            SourceDescription = sourceDescription;
        }
コード例 #2
0
ファイル: GraphViewModel.cs プロジェクト: heater404/HTOL
        /// <summary>
        /// 监控仪表电压和电流
        /// </summary>
        /// <param name="timeout">查询时间间隔,单位ms</param>
        public void MonitorInstrument(int timeout, DateTime time)
        {
            Voltages.Clear();
            Currents.Clear();

            if (!t6332A.Open())
            {
                return;
            }

            //if (!t6942A.Open())
            //    return;

            CsvHelper csvHelper = new CsvHelper($@"D:\HTOL\{time:yyyyMMddHHmmss}\InstrumentData.csv");

            csvHelper.WirteLine(new string[] { "Time(MMdd:HH:mm:ss)", "CH1_Voltage(V)", "CH2_Voltage(V)", "CH3_Voltage(V)", "CH1_Current(A)", "CH2_Current(A)", "CH3_Current(A)" });

            isMonitorInstrument = true;
            while (isMonitorInstrument)
            {
                var now = DateTime.Now;

                double[] voltages = t6332A.QueryVoltage();
                Voltages.Add(new GraphModel
                {
                    DateTime = now,
                    Value    = voltages[0]
                });

                double[] currents = t6332A.QueryCurrent();
                Currents.Add(new GraphModel
                {
                    DateTime = now,
                    Value    = currents[0]
                });

                csvHelper.WirteLine(new string[]
                                    { now.ToString("MMdd:HH:mm:ss"),
                                      voltages[0].ToString("0.000"),
                                      voltages[1].ToString("0.000"),
                                      voltages[2].ToString("0.000"),
                                      currents[0].ToString("0.000"),
                                      currents[1].ToString("0.000"),
                                      currents[2].ToString("0.000"), });

                SetAxisLimits(now);
                //lets only use the last 15 values
                if (Voltages.Count > 120)
                {
                    Voltages.RemoveAt(0);
                }
                if (Currents.Count > 120)
                {
                    Currents.RemoveAt(0);
                }
                Thread.Sleep(timeout);
            }
        }