private void Change() { try { CreateActual(); if (actual.Types != null) { List <Tuple <string, object> > t = actual.Types; if (!types.Equals(t)) { types = t; int n = t.Count; data = new object[n]; measurements = new IMeasurement[n]; for (int i = 0; i < n; i++) { measurements[i] = new DataMeasurement(this, i); data[i] = t[i].Item2; } } } } catch (Exception exception) { exception.ShowError(); } }
public void SimplyMeasurement_Ok() { //Arrange Measurement m = new Measurement(); DataMeasurement dM = new DataMeasurement(); Mic c1 = new Mic(); Mic c2 = new Mic(); FRF m1 = new FRF(); FRF m2 = new FRF(); FFT m3 = new FFT(); FFT m4 = new FFT(); //Act c1.Time = 0; c1.Pressure = -1.47F; c2.Time = 0; c2.Pressure = 0.59F; m1.Frequency = 0; m1.Amplification = 0; m2.Frequency = 0; m2.Amplification = 0; m3.Frequency = 0; m3.Amplitude = 0; m4.Frequency = 0; m4.Amplitude = 0; dM.Id = 1; dM.C1 = c1; dM.C2 = c2; dM.M1 = m1; dM.M2 = m2; dM.M3 = m3; dM.M4 = m4; m.Id = new System.Guid(); m.Date = new System.DateTime(2019, 04, 08, 14, 45, 34); m.Temperature = 15; m.AtmosphericPressure = 0; m.Measurements.Add(dM); //Assert Assert.AreEqual(1, m.Measurements.Count); Assert.AreEqual(0, m.Measurements.First().M3.Frequency); Assert.AreEqual(-1.47F, m.Measurements.First().C1.Pressure); }
private static void ExportToPiWeb(string serverUri, string inspectionName, IEnumerable <Characteristic> data, Dictionary <string, ushort> attributeMapping) { //1. Create the client var client = new DataServiceRestClient(new Uri(serverUri)); //2. Check the server configuration foreach (var entry in attributeMapping) { Configuration.CheckAttribute(client, Entity.Characteristic, entry.Value, entry.Key, AttributeType.Float); } //2.1 Make sure the essential time and value attributes are present Configuration.CheckAttribute(client, Entity.Measurement, WellKnownKeys.Measurement.Time, "Time", AttributeType.DateTime); Configuration.CheckAttribute(client, Entity.Value, WellKnownKeys.Value.MeasuredValue, "Value", AttributeType.Float); //3. Check the inspection plan //3.1 Check the inspection plan part var part = InspectionPlan.GetOrCreatePart(client, inspectionName); var characteristicMapping = new Dictionary <Characteristic, InspectionPlanCharacteristic>(); //3.2 Check the inspection plan characteristics foreach (var characteristic in data) { var inspectionPlanCharacteristic = InspectionPlan.GetOrCreateCharacteristic(client, part.Path.Name, characteristic.Name, attributeMapping, characteristic.Attributes); characteristicMapping.Add(characteristic, inspectionPlanCharacteristic); } //4. Create the measurement var dataCharacteristics = characteristicMapping.Select(pair => new DataCharacteristic { Uuid = pair.Value.Uuid, Path = pair.Value.Path, Value = new DataValue { Attributes = new[] { new Attribute(1, pair.Key.Value) } } }).ToArray(); var measurement = new DataMeasurement { Uuid = Guid.NewGuid(), PartUuid = part.Uuid, Time = DateTime.UtcNow, Attributes = new[] { new Attribute(WellKnownKeys.Measurement.Time, DateTime.UtcNow) }, Characteristics = dataCharacteristics }; //4.1 Write the measurement to the database client.CreateMeasurementValues(new[] { measurement }).Wait(); }
public void GetFormValue(DateTime date, Form fm) { try { if (fm == null) { return; } // получим список тегов из формы, с учетом объектов List <int> lists = this.forms.GetIDTags(fm, this.trObjs.Cast <int>().Select(o => o).ToArray()); // получим переменные для запроса на выборку TData.TDataSources t_data = new TData.TDataSources(); SQLParameter[] sqlpars = new SQLParameter[] { new SQLParameter() { where = type_where.DATE, value = date } }; // получим значения тегов после выборки List <DataMeasurement> list_data_measurement = t_data.GetDataMeasurement(lists, sqlpars); // Заполним значениями форму foreach (Group ged in fm.Groups.OrderBy(g => g.position)) { foreach (TReport.TRForms.Type ted in ged.Types.OrderBy(t => t.position)) { foreach (Item item in ted.Items.OrderBy(i => i.position)) { foreach (ItemObject io in item.ItemObjects.OrderBy(o => o.trobj)) { trObj obj = this.trObjs.Find(o => o == (trObj)io.trobj); if (obj != trObj.not) { foreach (ItemValue iv in io.ItemValues) { foreach (Value val in iv.Values) { try { DataMeasurement dm = val != null && val.tag > 0 ? list_data_measurement.Find(m => m.id == val.tag) : null; DBValueMeasurement param = dm != null ? (DBValueMeasurement)list_data_measurement.Find(m => m.id == val.tag).value_measurement : null; val.value = param != null && val.multiplier != null ? (DBValueMeasurement)param.ConvertMultiplier((Multiplier)val.multiplier) : param; } catch (Exception e) { e.WriteError(String.Format("Ошибка полученния параметра :{0}, объект: {1}, tag: {2}", item.name, io.Object, val.tag), eventID); } } } } else { item.ItemObjects.Remove(io); // Удалить объект } } } } } } catch (Exception e) { e.WriteErrorMethod(String.Format("GetFormValue(date={0}, fm.name={1})", date, fm.name), eventID); } }
private async void creatNewDemo(string demoType) { try { creatSuccessed = true; var partPath = PathHelper.String2PartPathInformation("/Demo/"); var parts = await _RestDataServiceClient.GetParts(partPath); if (parts.Count() != 0) { var Part = (InspectionPlanPart)parts.ToList()[0]; var attributes = new List <Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute>(); //demo type attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20043, demoType + "_Demo")); //serial number string date = DateTime.Now.ToString("yyyyMMddHHmmss"); attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)14, CC_Data["CC"] + date)); //CC attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)801, CC_Data["CC"])); //owner if (comboBox1.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20028, comboBox1.Text.Trim())); } else { MessageBox.Show("专案负责人未填写!"); creatSuccessed = false; } //sales if (comboBox2.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20004, comboBox2.Text.Trim())); } else { MessageBox.Show("销售联系人未填写!"); creatSuccessed = false; } //application engineer if (comboBox3.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20003, comboBox3.Text.Trim())); } else { MessageBox.Show("Demo工程师未填写!"); creatSuccessed = false; } //customer if (comboBox4.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)1062, comboBox4.Text.Trim())); } else { MessageBox.Show("客户名称未填写!"); creatSuccessed = false; } //province if (comboBox5.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20001, comboBox5.Text.Trim())); } else { MessageBox.Show("客户所在省份未填写!"); creatSuccessed = false; } //city if (comboBox6.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20002, comboBox6.Text.Trim())); } else { MessageBox.Show("客户所在城市未填写!"); creatSuccessed = false; } //customer Contact person attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20053, textBox1.Text.Trim())); //customer phone number attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20054, textBox2.Text.Trim())); //customer address attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20055, textBox3.Text.Trim())); //customer person count attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20056, textBox4.Text.Trim())); //cmm info if (comboBox7.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20051, comboBox7.Text.Trim())); } else { MessageBox.Show("三坐标信息未填写!"); creatSuccessed = false; } //sensor info if (comboBox8.Text != "") { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20052, comboBox8.Text.Trim())); } else { MessageBox.Show("传感器信息未填写!"); creatSuccessed = false; } //time K4 attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)4, DateTime.Now)); //check report if (checkBox1.Checked) { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20048, "已完成")); } //check handover attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20029, textBox5.Text)); //part number attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20041, 1)); //process status if (checkBox2.Checked) { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20027, "技术交接完成")); } else { attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20027, "创建完成")); } var Measurement = new DataMeasurement { Uuid = Guid.NewGuid(), PartUuid = Part.Uuid, Time = DateTime.Now, Attributes = attributes.ToArray() }; if (creatSuccessed) { //Create measurement on the server await _RestDataServiceClient.CreateMeasurementValues(new[] { Measurement }); } else { creatSuccessed = false; } } else { creatSuccessed = false; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); creatSuccessed = false; } finally { if (creatSuccessed) { DirectoryInfo path_exe = new DirectoryInfo(Application.StartupPath); //exe目录 RealAction(path_exe + @"\PiWebInterface.exe", " 主界面"); //写入完成 DialogResult dr = MessageBox.Show("创建Demo完成,是否继续创建Demo?", "创建Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { //询问是否清空界面内容 comboBox2.Text = ""; comboBox3.Text = ""; comboBox4.Text = ""; comboBox5.Text = ""; comboBox6.Text = ""; comboBox7.Text = ""; comboBox8.Text = ""; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; textBox4.Text = ""; checkBox1.Checked = false; checkBox2.Checked = false; textBox5.Text = ""; } else { Application.Exit(); } } } }