/// <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); } }
// On tap, get an input line and perform a buffer and clip operation private async void mapView1_Tap(object sender, MapViewInputEventArgs e) { if (BusyVisibility == Visibility.Visible) { MessageBox.Show("Please wait until the current operation is complete."); return; } // Show busy UI BusyVisibility = Visibility.Visible; // Clear previous results TapPoints.Clear(); Currents.Clear(); // Create graphic and add to tap points var g = new Graphic() { Geometry = e.Location }; TapPoints.Add(g); string error = null; // Initialize the Geoprocessing task with the drive time calculation service endpoint Geoprocessor task = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" + "Specialty/ESRI_Currents_World/GPServer/MessageInABottle")); // Initialize input parameters var parameter = new GPInputParameter() { OutSpatialReference = SpatialReferences.WebMercator }; var projectedMapPoint = GeometryEngine.Project(e.Location, SpatialReferences.Wgs84); parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", projectedMapPoint)); parameter.GPParameters.Add(new GPDouble("Days", Days)); try { // Run the operation var result = await task.ExecuteAsync(parameter); // Check that layers were returned from the operation var outputLayers = result.OutParameters.OfType <GPFeatureRecordSetLayer>(); if (outputLayers.Count() > 0) { // Get the first layer returned - this will be the drive time areas var outputLayer = outputLayers.First(); if (outputLayer.FeatureSet != null && outputLayer.FeatureSet.Features != null) { // Instead of adding ocean current features one-by-one, update the collection all at once to // allow the map to render the new features in one rendering pass. Currents = new ObservableCollection <Graphic>(outputLayer.FeatureSet.Features); } else { error = "No results returned"; } } else { error = "No results returned"; } } catch (Exception ex) { error = "Calculation failed: " + ex.Message; } // If operation did not succeed, notify user if (error != null) { MessageBox.Show(error); } // Hide busy UI BusyVisibility = Visibility.Collapsed; }