/// <summary> /// Thread um alle Standardvariablen hinzuzufügen /// </summary> /// <created>janzen_d,2018-09-22</created> private void ThreadStandardVariablen() { try { List <string> tmpListstdvar = global.config.ConfigReadWriter.GetSTDVARIABLES; List <int> tmpListid = new List <int>(); if (tmpListstdvar.Count > 0) { foreach (string stritem in tmpListstdvar) { OPCTag oPCTag = new OPCTag(stritem); if (listOpcTags.Contains(oPCTag)) { tmpListid.Add(listOpcTags.IndexOf(oPCTag)); } } AddListids(tmpListid.ToArray(), 1078); } } catch (Exception) { throw; } }
public override OPCTag.OPCTagStatisticsInternal GetTagStatistics(long Identifier) { OPCTag stats = OPCTag.AllTags[Identifier]; stats.UpdateInternals(); return(stats.StatisticsInternal); }
public OPCTag UpdateOPCTag(OPCTag newOPCTag) { try { _opcTagDal.Update(newOPCTag); } catch (RepositoryException ex) { throw new AisinoMesServiceException("更新OPCTag出错", ex.InnerException); } return(newOPCTag); }
private OPC_Interface.OPC_Interface_Tag[] Tags ( OPCCliConfiguration.ItemsRow[] items, OPC_Interface server, OPC_Interface.OPCGroup oPCGroup ) { OPCClientTag[] tags = new OPCClientTag[ items.Length ]; int idx = 0; #region foreach ( OPCCliConfiguration.ItemsRow row in items ) foreach ( OPCCliConfiguration.ItemsRow row in items ) { OpcDa.Item item = row.Item; double measurement_low = double.NaN; double measurement_hi = double.NaN; double engineer_low = double.NaN; double engineer_hi = double.NaN; OPCCliConfiguration.ConversionsRow[] conversions = row.GetConversionsRows(); if ( conversions.Length > 0 ) { if ( conversions.Length != 1 ) throw new Exception( "Too many ConversionsRows for item " + row.Name ); //musimy konwersje uruchomic measurement_low = conversions[ 0 ].MeasuredValue1; measurement_hi = conversions[ 0 ].MeasuredValue2; engineer_low = conversions[ 0 ].EngineeringValue1; engineer_hi = conversions[ 0 ].EngineeringValue2; } //odczytanie odpowiednich property z pliku opisów global::Opc.Da.ItemPropertyCollection properties = BaseStation.ItemDescriber.ItemDescriber2OpcDA.GetItemPropertiesCollection( row.Name, Main.m_ds_dsc ); if ( properties.Count == 0 ) { //nalezy sprawdzic jeszcze - czy moze nie ma nazewnictwa path/ tagname: properties = BaseStation.ItemDescriber.ItemDescriber2OpcDA.GetItemPropertiesCollection ( server.Name + "/" + oPCGroup.Name + "/" + row.Name, Main.m_ds_dsc ); } OPCTag tagStatistics = new OPCTag( (uint)row.ID, row.Item, measurement_low, measurement_hi, engineer_low, engineer_hi ); string path = server.Name + "/" + oPCGroup.Name + "/"; OPCClientTag tag = new OPCClientTag ( tagStatistics, oPCGroup, null, OpcDa.qualityBits.badNotConnected, properties, path, row.Item ); tag.ClientHandle = idx; tags[ idx++ ] = tag; } #endregion foreach ( OPCCliConfiguration.ItemsRow row in items ) return tags; }
private OPC_Interface.OPC_Interface_Tag[] Tags (OPCCliConfiguration.ItemsRow[] items, OPC_Interface server, OPC_Interface.OPCGroup oPCGroup) { OPC_Interface.OPC_Interface_Tag[] tags = new OPC_Interface.OPC_Interface_Tag[items.Length]; int idx = 0; #region foreach ( OPCCliConfiguration.ItemsRow row in items ) foreach (OPCCliConfiguration.ItemsRow row in items) { Opc.Da.Item item = row.Item; double measurement_low = double.NaN; double measurement_hi = double.NaN; double engineer_low = double.NaN; double engineer_hi = double.NaN; OPCCliConfiguration.ConversionsRow[] conversions = row.GetConversionsRows(); if (conversions.Length > 0) { if (conversions.Length != 1) { throw new Exception("Too many ConversionsRows for item " + row.Name); } //musimy konwersje uruchomic measurement_low = conversions[0].MeasuredValue1; measurement_hi = conversions[0].MeasuredValue2; engineer_low = conversions[0].EngineeringValue1; engineer_hi = conversions[0].EngineeringValue2; } OPCTag tagStatistics = new OPCTag((uint)row.ID, row.Item, measurement_low, measurement_hi, engineer_low, engineer_hi); string path = server.Name + "/" + oPCGroup.Name + "/"; OPC_Interface.OPC_Interface_Tag tag = new OPC_Interface.OPC_Interface_Tag (tagStatistics, oPCGroup, null, Opc.Da.qualityBits.badNotConnected, null, path, row.Item); tag.ClientHandle = idx; tags[idx++] = tag; this.Add(UniqueIdentyfier(server.Name, oPCGroup.Name, row.Name), tag); } #endregion foreach ( OPCCliConfiguration.ItemsRow row in items ) return(tags); }
static async Task Execute() { try { GetClient(new HandlerConfig().WithElement("SetVariableAsync", SetVariableAsync).Elements); CustomLogger logger = new CustomLogger(); var opcConnectionString = @"opc.tcp://127.0.0.1:49320"; MyClient = new OPCClient(opcConnectionString, "", "", logger, "Mytest2", SecurityPolicy.Basic128, MessageSecurity.Sign); R1 = (OPCTag)MyClient.AddTag("RAMP1", "ns=2;s=TEST_OPC.RAMP.RAMP1", typeof(float)); T0 = (OPCTag)MyClient.AddTag("WRITE1", "ns=2;s=TEST_OPC.WRITE.WRITE1", typeof(float)); T1 = (OPCTag)MyClient.AddTag("WRITE2", "ns=2;s=TEST_OPC.WRITE.WRITE2", typeof(float)); T2 = (OPCTag)MyClient.AddTag("WRITE3", "ns=2;s=TEST_OPC.WRITE.WRITE3", typeof(float)); var T3 = (OPCTag)MyClient.AddTag("Cast", "ns=2;s=TEST_OPC.WRITE.WRITESLOW1", typeof(double)); T3.ReadItem(); List <string> TagNameList = new List <string>(); TagNameList.Add(T0.Name); TagNameList.Add(T1.Name); TagNameList.Add(T2.Name); TagNameList.Add(R1.Name); var baseName1 = "ns=2;s=TEST_OPC.RAMP.RAMP"; var baseName2 = "ns=2;s=TEST_OPC.RAND.RAND"; for (int i = 1; i <= 150; i++) { var tagName1 = $"{baseName1}{i}"; MyClient.AddTag(tagName1, tagName1, typeof(float)); TagNameList.Add(tagName1); var tagName2 = $"{baseName2}{i}"; MyClient.AddTag(tagName2, tagName2, typeof(int)); TagNameList.Add(tagName2); } while (true) { MyClient.ReadTags(TagNameList); IotMessage message = new IotMessage(); message.Datetime = DateTime.Now; message.DeviceId = "PLC0001"; message.Data = new List <Payload>(); foreach (var x in TagNameList) { double y = 0; if (MyClient.GetTag(x)?.Value != null) { y = Double.Parse(MyClient.GetTag(x).Value.ToString()); } message.Data.Add(new Payload() { datetime = DateTime.Now, name = MyClient.GetTag(x).Name, value = y }); Console.WriteLine(MyClient.GetTag(x).Name + " | " + MyClient.GetTag(x).Value); } SendEvent(_deviceClient, message).GetAwaiter().GetResult(); Thread.Sleep(100); Console.WriteLine("----"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { try { Tag_List = new ObservableCollection <OPCTag>(); CustomLogger logger = new CustomLogger(); var opcConnectionString = @"opc.tcp://127.0.0.1:49320"; //var opcConnectionString = @"opc.tcp://10.0.2.170:49320"; //var endpoint1 = OPCCoreUtils.SelectEndpointBySecurity(opcConnectionString, SecurityPolicy.Basic128, MessageSecurityMode.Sign, 10000); MyClient = new OPCClient(opcConnectionString, "", "", logger, "Mytest2", SecurityPolicy.Basic128, MessageSecurity.Sign); T = (OPCTag)MyClient.AddTag("RAMP1", "ns=2;s=TEST_OPC.RAMP.RAMP1", typeof(float)); T0 = (OPCTag)MyClient.AddTag("WRITE1", "ns=2;s=TEST_OPC.WRITE.WRITE1", typeof(float)); T1 = (OPCTag)MyClient.AddTag("WRITE2", "ns=2;s=TEST_OPC.WRITE.WRITE2", typeof(float)); T2 = (OPCTag)MyClient.AddTag("WRITE3", "ns=2;s=TEST_OPC.WRITE.WRITE3", typeof(float)); float val = 5; var writeResult = T0.WriteItem(val); T0.ReadItem(); var T3 = (OPCTag)MyClient.AddTag("CAst", "ns=2;s=TEST_OPC.WRITE.WRITESLOW1", typeof(double)); T3.ReadItem(); Console.WriteLine(T3.Value); //T0 = (OPCTag)MyClient.AddTag("Write01", "ns=4;s=MAIN.iMS0", typeof(short)); //T0.WriteItem((short)5); //T0.ReadItem(); //val = 100f; //T0.WriteItem(val); //T0.ReadItem(); //T0.SubscribeItem(null,null, Newvalue); List <string> TagNameList = new List <string>(); List <object> TagObjectList = new List <object>(); TagNameList.Add(T0.Name); TagNameList.Add(T1.Name); TagNameList.Add(T2.Name); TagObjectList.Add(101f); TagObjectList.Add(102f); TagObjectList.Add(103f); bool Readok = MyClient.ReadTags(TagNameList); bool Writeok = MyClient.WriteTags(TagNameList, TagObjectList); //Tag_List.Add(T); //Tag_List.Add(T); //this.DataContext = Tag_List; ////T.WriteItem(10); // Read multiple variables at once var baseName1 = "ns=2;s=TEST_OPC.RAMP.RAMP"; var baseName2 = "ns=2;s=TEST_OPC.RAND.RAND"; tagsToRead = new List <string>(); for (int i = 1; i <= 150; i++) { var tagName1 = $"{baseName1}{i}"; MyClient.AddTag(tagName1, tagName1, typeof(float)); tagsToRead.Add(tagName1); var tagName2 = $"{baseName2}{i}"; MyClient.AddTag(tagName2, tagName2, typeof(int)); tagsToRead.Add(tagName2); } concurrentQueue = new ConcurrentQueue <Tuple <bool, long> >(); Timer _timer = new Timer(50); _timer.Elapsed += _timer_Elapsed; _timer.Start(); Timer _health = new Timer(1000); _health.Elapsed += _health_Elapsed; _health.Start(); //MyClient.SubScribeTag(T, 0, 0, null); MyClient.SubscribeTag(T0, 0, 0, Newvalue); //var name = Console.ReadLine(); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Thread um Twizard analisieren /// </summary> /// <param name="twizardpath"></param> /// <created>janzen_d,2018-09-21</created> private void ThreadAnalyzeTWOPC(object twizardpath) { if (twizardpath != null && twizardpath.ToString().Length > 3) { // // analyze pv_process // if (Directory.Exists(twizardpath.ToString() + "\\uhlmann\\tc\\pv_process")) { string[] paths_pv_process = Directory.GetFiles(twizardpath.ToString() + "\\uhlmann\\tc\\pv_process"); foreach (string item in paths_pv_process) { string extension = Path.GetExtension(item); if (extension == ".xml" || extension == ".XML") { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.XmlResolver = null; xmlDocument.Load(item); foreach (XmlNode xmlNode in xmlDocument.SelectNodes("PPVS/PPV[@name]")) { try { OPCTag oPCTag = new OPCTag(xmlNode.Attributes["name"].Value); if (!listOpcTags.Contains(oPCTag)) { listOpcTags.Add(oPCTag); oPCTag.LISTID = listOpcTags.IndexOf(oPCTag); oPCTag.MODULENAME = twizardpath.ToString(); oPCTag.PVPROCESSPATH = item; foreach (XmlAttribute xmlAttribute in xmlNode.Attributes) { if ("Sealing_TMP_Heating.CurrentTemp" == xmlNode.Attributes["name"].Value) { } switch (xmlAttribute.Name) { case "varTxt": // Text-ID oPCTag.TEXTID = xmlAttribute.Value; break; case "cmt": // Kommentar oPCTag.COMMENT = xmlAttribute.Value; break; case "opcActive": oPCTag.OPCACTIVE = xmlAttribute.Value; break; case "opcDataType": oPCTag.OPCDATATYPE = xmlAttribute.Value; break; case "opcRwu": oPCTag.OPCRWU = xmlAttribute.Value; break; case "opcAlias": oPCTag.OPCALIAS = xmlAttribute.Value; break; case "semantic": oPCTag.SEMANTIC = xmlAttribute.Value; break; case "dcReadPeriod": oPCTag.DCREADPERIOD = xmlAttribute.Value; break; case "dcLogThreshold": oPCTag.LOGTHRESHOLD = xmlAttribute.Value; break; case "dcMaxPersistence": oPCTag.DCMAXPERSISTENCE = xmlAttribute.Value; break; case "pdaCounterType": oPCTag.PDACOUNTERTYPE = xmlAttribute.Value; break; default: break; } } } } catch (Exception) { continue; } } } } } // // pv_equipment analysieren // if (Directory.Exists(twizardpath.ToString() + "\\uhlmann\\tc\\pv_equipment")) { string[] paths_pv_equipment = Directory.GetFiles(twizardpath.ToString() + "\\uhlmann\\tc\\pv_equipment"); foreach (string path in paths_pv_equipment) { string extension = Path.GetExtension(path); if (extension == ".xml" || extension == ".XML") { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.XmlResolver = null; xmlDocument.Load(path); foreach (XmlNode xmlNode in xmlDocument.SelectNodes("EPVS/EPV[@name]")) { try { OPCTag oPCTag = new OPCTag(xmlNode.Attributes["name"].Value); if (listOpcTags.Contains(oPCTag)) { int index = listOpcTags.IndexOf(oPCTag); foreach (XmlAttribute xmlAttribute in xmlNode.Attributes) { switch (xmlAttribute.Name) { case "size": listOpcTags[index].ARRAYSIZE = xmlAttribute.Value; listOpcTags[index].PVEQUIPMENTPATH = path; break; default: break; } } } } catch (Exception) { throw; } } } } } // // pv_equipment analysieren // if (Directory.Exists(twizardpath.ToString() + "\\uhlmann\\tc\\pv_batch")) { string[] paths_pv_equipment = Directory.GetFiles(twizardpath.ToString() + "\\uhlmann\\tc\\pv_batch"); foreach (string path in paths_pv_equipment) { string extension = Path.GetExtension(path); if (extension == ".xml" || extension == ".XML") { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.XmlResolver = null; xmlDocument.Load(path); foreach (XmlNode xmlNode in xmlDocument.SelectNodes("APVS/APV[@name]")) { try { OPCTag oPCTag = new OPCTag(xmlNode.Attributes["name"].Value); if (listOpcTags.Contains(oPCTag)) { int index = listOpcTags.IndexOf(oPCTag); foreach (XmlAttribute xmlAttribute in xmlNode.Attributes) { switch (xmlAttribute.Name) { case "name": listOpcTags[index].BATCHVARIABLE = xmlAttribute.Value; listOpcTags[index].PVBATCHPATH = path; break; default: break; } } } } catch (Exception) { throw; } } } } } } }