public void WriteNextBatchProductType(OpcClient accessPoint, float productTypeValue) { accessPoint.WriteNode(nodeIDDictionary[NodeID.NextBatchProductType], productTypeValue); }
public TemperatureCreator(OpcClient opcClient) : base(opcClient) { //@"^.*_T[CT].*$" subStringTagName = @"^[S]\d{2,3}[_]\w*_T[CT]\d{2,3}$"; TemperatureList = new List <Temperature>(); }
public static void Main(string[] args) { //// If the server domain name does not match localhost just replace it //// e.g. with the IP address or name of the server machine. var client = new OpcClient("opc.tcp://localhost:4840/SampleServer"); client.Connect(); var methodsNode = client.BrowseNode("ns=2;s=Methods"); var methods = BrowseMethods(methodsNode).ToList(); do { Console.WriteLine("Enter index of method to call or 'exit':"); for (int index = 0; index < methods.Count; index++) { Console.WriteLine("{0}. {1}", index, methods[index].Node.DisplayName.Value); } var line = Console.ReadLine(); if (line == "exit") { break; } if (int.TryParse(line, out var methodIndex)) { var method = methods[methodIndex]; Console.WriteLine(); Console.WriteLine("Calling method '{0}' ...", method.Node.DisplayName.Value); var inputs = method.Node.GetInputArguments(); foreach (var input in inputs) { Console.WriteLine( "\t[IN] {0} : {1} // {2}", input.Name, OpcDataTypes.GetDataType(input.DataTypeId), input.Description); } var outputs = method.Node.GetOutputArguments(); foreach (var output in outputs) { Console.WriteLine( "\t[OUT] {0} : {1} // {2}", string.IsNullOrEmpty(output.Name) ? "ret" : output.Name, OpcDataTypes.GetDataType(output.DataTypeId), output.Description); } var inputArguments = new List <object>(); if (inputs.Length > 0) { Console.WriteLine(); foreach (var input in inputs) { Console.Write( "Enter '{0}' value of '{1}': ", OpcDataTypes.GetDataType(input.DataTypeId), input.Name); var value = Console.ReadLine(); if (input.DataTypeId == OpcDataTypes.String) { inputArguments.Add(value); } else if (input.DataTypeId == OpcDataTypes.Int32) { inputArguments.Add(int.Parse(value)); } } } try { var outputArguments = client.CallMethod(method.ParentId, method.Node.NodeId, inputArguments); Console.WriteLine("Call succeeded!"); for (int index = 0; index < outputs.Length; index++) { var output = outputs[index]; Console.WriteLine( "'{0}' value of '{1}': {2}", OpcDataTypes.GetDataType(output.DataTypeId), string.IsNullOrEmpty(output.Name) ? "ret" : output.Name, outputArguments[index]); } } catch (OpcException ex) { Console.WriteLine("Call failed: {0}", ex.Message); } Console.WriteLine(); } } while (true); client.Disconnect(); }
public float ReadDesiredMachineSpeed(OpcClient accessPoint) { return((float)accessPoint.ReadNode(nodeIDDictionary[NodeID.DesiredSpeed]).Value); }
public float ReadHopsAmount(OpcClient accessPoint) { return((float)accessPoint.ReadNode(nodeIDDictionary[NodeID.HopsAmount]).Value); }
public bool ReadCommandChangeRequest(OpcClient accessPoint) { return((bool)accessPoint.ReadNode(nodeIDDictionary[NodeID.CommandChangeRequest]).Value); }
public int ReadCurrentState(OpcClient accessPoint) { return((int)accessPoint.ReadNode(nodeIDDictionary[NodeID.CurrentState]).Value); }
public ProductionPlanControl() { InitializeComponent(); m_productionPlanDao = new ProductionPlanDao(); m_productionPlanList = new BindingList <Models.ProductionPlan>(); productionPlans = new List <Models.ProductionPlan>(); m_productionInfoDao = new ProductionInfoDao(); opcClient = new OpcClient(); string batchNo = DateTime.Now.ToString("yyyyMMdd"); productionPlans = m_productionPlanDao.GetDataSourceList(batchNo); gridControl.DataSource = productionPlans; Dictionary <object, string> dicButtons = new Dictionary <object, string>(); dicButtons.Add("Up", "上件"); dicButtons.Add("Stop", "暂停"); //dicButtons.Add("Finish", "结束上件"); RepositoryItemButtonEdit ribe = ItemOperation.CreateRepositoryItemButtonEdit(dicButtons); ribe.ButtonClick += new ButtonPressedEventHandler(this.ribe_ButtonClick); //绑定事件 this.gridView.Columns["Operating"].ColumnEdit = ribe; m_xmlSettings = new XMLSettings(); m_xmlSettings.ReadXMLSettings(); if (opcClient.WriteDataToOpcServer(m_xmlSettings.Count, (ushort)0)) { opcClient.WriteDataToOpcServer(new Models.ProductionPlan { BatchNo = "0", WorkpieceType = "0", PrimerColor = "0", PigmentedCoatingColor = "0", VarnishColor = "0", WorkpieceNo = "0", PrimerFirm = "0", PrimerCraft = "0", PigmentedCoatingFirm = "0", PigmentedCoatingCraft = "0", VarnishFirm = "0", VarnishCraft = "0", TotalNum = 0 }); } Task t1 = Task.Run(() => { byte data = 0; while (data < 128) { try { opcClient.WriteDataToOpcServer(m_xmlSettings.Heartbeat, data); data++; if (data == 128) { data = 0; } } catch (Exception ex) { LogManager.WriteLog(LogFile.Warning, $"t1:{ex.Message}"); } } }); Task t2 = Task.Run(() => { while (true) { try { short tagInitializationNo202 = Convert.ToInt16(opcClient.ReadData(m_xmlSettings.TagInitializationNo202).Value); short tagInitializationNo203 = Convert.ToInt16(opcClient.ReadData(m_xmlSettings.TagInitializationNo203).Value); if (tagInitializationNo202 >= tagInitializationNo203) { int value = tagInitializationNo202 <= 454 ? 454 : tagInitializationNo202; opcClient.WriteStrDataToOpcServer(m_xmlSettings.TagInitializationNo203, $"{value}"); } } catch (Exception ex) { LogManager.WriteLog(LogFile.Warning, $"t2:{ex.Message}"); } } }); }
public void set_OpcClient(OpcClient client) { client = client; }
public Form1() : base() { this.client = new OpcClient(); this.InitializeComponent(); }
private static void CommunicateWithServer(OpcClient client) { Console.WriteLine("ReadNode: {0}", client.ReadNode("ns=2;s=Machine_1/IsActive")); client.WriteNode("ns=2;s=Machine_1/IsActive", false); Console.WriteLine("ReadNode: {0}", client.ReadNode("ns=2;s=Machine_1/IsActive")); }
public static void Main() { string stringEntered = ""; bool exitSession = false; List <OpcNodeInfo> listOfNodes; using (var client = new OpcClient("opc.tcp://localhost:4840")) { client.Connect(); while (true)//(!exitSession) { Console.WriteLine("Available commands: 'view' 'edit' 'disconnect'"); Console.Write("Enter a command from the above list: "); stringEntered = Convert.ToString(Console.ReadLine()); switch (stringEntered) { case "view": { Console.WriteLine("Enter the name(s) of the node(s) separated by whitespace(s):"); string fullString = Console.ReadLine(); List <OpcNodeInfo> nodeInfoList = AddNodesToList(fullString, client); Console.WriteLine("****************************"); foreach (OpcNodeInfo infoElement in nodeInfoList) { //Start here! } Console.WriteLine("****************************"); DisplayNodeInfo(nodeInfoList); break; } case "editValue": { //EditNodeValue(); break; } case "disconnect": { client.Disconnect(); Console.WriteLine("Session is exiting..."); exitSession = true; break; } default: { Console.WriteLine(stringEntered + " is not an accepted command"); break; } } string[] splittedString = stringEntered.Split(" "); listOfNodes = new List <OpcNodeInfo>(); //or initialize it when declared and clear the list here? OpcNodeInfo machineNode; foreach (string substring in splittedString) { machineNode = client.BrowseNode($"ns=2;"); // if(!machineNode.Name.IsNull) // { OpcNodeInfo jobnode = machineNode.Child("Job"); listOfNodes.Add(machineNode); //} } OpcBrowseNode test = new OpcBrowseNode("s=Message"); IEnumerable <OpcNodeInfo> infoAboutNodes = client.BrowseNodes(test); foreach (string element in splittedString) { List <OpcReadNode> liste = new List <OpcReadNode>(); liste.Add(new OpcReadNode("s=Message")); //OpcNodeInfo info = client.BrowseNode($"ns=2;s=Message"); List <OpcBrowseNode> liste2 = new List <OpcBrowseNode>(); //OpcBrowseNode test = new OpcBrowseNode("s=Message"); IEnumerable <OpcNodeInfo> info = client.BrowseNodes(test); Console.WriteLine("\n**********************************"); Console.WriteLine("Writing the infoElements..."); Console.WriteLine("**********************************\n"); foreach (OpcNodeInfo infoElement in info) { Console.WriteLine("NodeID: " + infoElement.NodeId); Console.WriteLine("InfoElement:: " + infoElement.ToString() + "\n"); } var nodeOfInterest = client.ReadNode($"ns=2;s={stringEntered}"); if (nodeOfInterest.Value != null) { Console.Write($"The value of the node is: {nodeOfInterest.Value}\t"); Console.WriteLine($"The ID of the node is: {nodeOfInterest.DataTypeId}\n"); } } if (client.State == OpcClientState.Connected) { var temperature = client.ReadNode("ns=2;s=Temperature"); var message = client.ReadNode("ns=2;s=Message"); var level = client.ReadNode("ns=2;s=Level"); Console.WriteLine($"Current Temperature is {temperature} °C"); Console.WriteLine($"Current message is {message}"); Console.WriteLine($"Level: {level}"); } Thread.Sleep(1000); } } }
private static void ThreadBody() { try { if (LicenseKey != string.Empty) { Opc.UaFx.Licenser.LicenseKey = LicenseKey; } else { Console.WriteLine("No license key available."); Opc.UaFx.Licenser.LicenseKey = string.Empty; } opcClient = new OpcClient(Address); opcClient.Connecting += OpcClient_Connecting; opcClient.Connected += OpcClient_Connected; opcClient.BreakDetected += OpcClient_BreakDetected; opcClient.Disconnected += OpcClient_Disconnected; opcClient.Disconnecting += OpcClient_Disconnecting; opcClient.Reconnected += OpcClient_Reconnected; opcClient.Reconnecting += OpcClient_Reconnecting; opcClient.Connect(); var commands = new List <OpcSubscribeDataChange>(); if (!string.IsNullOrEmpty(NodePotentio1)) { commands.Add(new OpcSubscribeDataChange(NodePotentio1, OpcDataChangeTrigger.StatusValue, HandleDataChangedMachineLineNode)); } else { System.Console.WriteLine("Ignored empty NodePotentio1"); } if (!string.IsNullOrEmpty(NodePotentio2)) { commands.Add(new OpcSubscribeDataChange(NodePotentio2, OpcDataChangeTrigger.StatusValue, HandleDataChangedMachineLineNode)); } else { System.Console.WriteLine("Ignored empty NodePotentio2"); } if (!string.IsNullOrEmpty(NodeSwitch1)) { commands.Add(new OpcSubscribeDataChange(NodeSwitch1, OpcDataChangeTrigger.StatusValue, HandleDataChangedMachineLineNode)); } else { System.Console.WriteLine("Ignored empty NodeSwitch1"); } if (!string.IsNullOrEmpty(NodeSwitch2)) { commands.Add(new OpcSubscribeDataChange(NodeSwitch2, OpcDataChangeTrigger.StatusValue, HandleDataChangedMachineLineNode)); } else { System.Console.WriteLine("Ignored empty NodeSwitch2"); } if (!string.IsNullOrEmpty(NodeRelay1)) { commands.Add(new OpcSubscribeDataChange(NodeRelay1, OpcDataChangeTrigger.StatusValue, HandleDataChangedMachineLineNode)); } else { System.Console.WriteLine("Ignored empty NodeRelay1"); } if (!string.IsNullOrEmpty(NodeRelay2)) { commands.Add(new OpcSubscribeDataChange(NodeRelay2, OpcDataChangeTrigger.StatusValue, HandleDataChangedMachineLineNode)); } else { System.Console.WriteLine("Ignored empty NodeRelay2"); } OpcSubscription subscription = opcClient.SubscribeNodes(commands); Console.WriteLine($"Client started... (listening to '{NodePotentio1},{NodePotentio2},{NodeSwitch1},{NodeSwitch2},{NodeRelay1},{NodeRelay2}' at '{Address}')"); while (true) { // keep thread alive Thread.Sleep(1000); } } catch (System.Exception ex) { // TODO: Test for Timeout towards OPC-UA Server connection Console.WriteLine($"Fatal ThreadBody exception: {ex.Message}"); var logLevelMessage = new LogLevelMessage { logLevel = LogLevelMessage.LogLevel.Critical, code = "00", message = $"ThreadBody exception: {ex.Message}" }; SendLogLevelMessage(logLevelMessage).Wait(); Console.WriteLine("Halted..."); } }
public void WriteNextBatchSize(OpcClient accessPoint, float batchSize) { accessPoint.WriteNode(nodeIDDictionary[NodeID.NextBatchSize], batchSize); }
public float ReadBatchID(OpcClient accessPoint) { return((float)accessPoint.ReadNode(nodeIDDictionary[NodeID.BatchID]).Value); }
/// <summary> /// Create an OPC UA Client /// </summary> /// <param name="host">The hostname or IP Address of the OPC UA server</param> /// <param name="port">The port to use for connecting to the OPC UA Server</param> public UAClient(string host, int port) { _connectionString = "opc.tcp://" + host + ":" + port; _client = new OpcClient(_connectionString); base.RegisterForClientEvents(); }
public ushort ReadBatchSize(OpcClient accessPoint) { return((ushort)accessPoint.ReadNode(nodeIDDictionary[NodeID.BatchSize]).Value); }
public float ReadHumidity(OpcClient accessPoint) { return((float)accessPoint.ReadNode(nodeIDDictionary[NodeID.Humidity]).Value); }
public int ReadControlCommand(OpcClient accessPoint) { return((int)accessPoint.ReadNode(nodeIDDictionary[NodeID.ControlCommand]).Value); }
public ushort ReadMaintenanceTrigger(OpcClient accessPoint) { return((ushort)accessPoint.ReadNode(nodeIDDictionary[NodeID.MaintenanceTrigger]).Value); }
public ushort ReadDefectProducts(OpcClient accessPoint) { return((ushort)accessPoint.ReadNode(nodeIDDictionary[NodeID.DefectProducts]).Value); }
public ushort ReadNextBatchProductType(OpcClient accessPoint) { return((ushort)accessPoint.ReadNode(nodeIDDictionary[NodeID.NextBatchType]).Value); }
public bool ReadFlillingInventory(OpcClient accessPoint) { return((bool)accessPoint.ReadNode(nodeIDDictionary[NodeID.FillingInventory]).Value); }
public int ReadStopReasonValue(OpcClient accessPoint) { return((int)accessPoint.ReadNode(nodeIDDictionary[NodeID.StopReasonValue]).Value); }
public static void Main(string[] args) { //// If the server domain name does not match localhost just replace it //// e.g. with the IP address or name of the server machine. var client = new OpcClient("opc.tcp://localhost:4840/SampleServer"); client.Connect(); var statusNode = client.BrowseNode("ns=2;s=Machine_1/Status") as OpcVariableNodeInfo; if (statusNode != null) { var statusValues = statusNode.DataType.GetEnumMembers(); var currentStatus = client.ReadNode(statusNode.NodeId); var currentStatusValue = null as OpcEnumMember; foreach (var statusValue in statusValues) { if (statusValue.Value == currentStatus.As <int>()) { currentStatusValue = statusValue; break; } } Console.WriteLine( "Status: {0} ({1})", currentStatusValue.Value, currentStatusValue.Name); Console.WriteLine("-> " + currentStatusValue.Description); Console.WriteLine(); Console.WriteLine("Possible status values..."); foreach (var statusValue in statusValues) { Console.WriteLine("{0} = {1}", statusValue.Value, statusValue.Name); } Console.Write("Enter new status: "); var value = Console.ReadLine(); var newStatus = 0; if (int.TryParse(value, out newStatus)) { client.WriteNode(statusNode.NodeId, newStatus); } currentStatus = client.ReadNode(statusNode.NodeId); foreach (var statusValue in statusValues) { if (statusValue.Value == currentStatus.As <int>()) { currentStatusValue = statusValue; break; } } Console.WriteLine(); Console.WriteLine( "New Status: {0} ({1})", currentStatusValue.Value, currentStatusValue.Name); Console.WriteLine("-> " + currentStatusValue.Description); } client.Disconnect(); Console.ReadKey(true); }
public float ReadTemperature(OpcClient accessPoint) { return((float)accessPoint.ReadNode(nodeIDDictionary[NodeID.Temperature]).Value); }
internal object[] valuesForWriting; //Массив объектов для записи в OPC protected ItemsCreator(OpcClient opcClient) { this.opcClient = opcClient; nodeElementCollection = new List <OpcDaBrowseElement>(); }
public float ReadVibration(OpcClient accessPoint) { return((float)accessPoint.ReadNode(nodeIDDictionary[NodeID.Vibration]).Value); }
public static void Main(string[] args) { //// If the server domain name does not match localhost just replace it //// e.g. with the IP address or name of the server machine. var client = new OpcClient("opc.tcp://localhost:4840/SampleServer"); client.Connect(); { // Read the historical 'Raw' data. // - for one specific node. // - the whole history in one request. var rawHistory = client.ReadNodeHistory( DateTime.UtcNow.Date.AddHours(6), DateTime.UtcNow.Date.AddHours(6).AddSeconds(10), "ns=2;s=Machine_1/Position"); Console.WriteLine("Read the historical 'Raw' data..."); foreach (var item in rawHistory) { Console.WriteLine("{0} - {1}", item.Timestamp, item.Value); } } { // Read the historical 'Raw' data page wise. // - for one specific node. // - the whole history partitioned into multiple requests. var rawHistoryNavigator = client.ReadNodeHistory( DateTime.UtcNow.Date.AddHours(6), DateTime.UtcNow.Date.AddHours(6).AddSeconds(10), 2, "ns=2;s=Machine_1/Position"); Console.WriteLine("Read the historical 'Raw' data page wise..."); do { foreach (var item in rawHistoryNavigator) { Console.WriteLine("{0} - {1}", item.Timestamp, item.Value); } Console.Write("Press any key to read the next page..."); Console.ReadKey(); Console.WriteLine(); }while (rawHistoryNavigator.MoveNextPage()); } { // Read the historical 'ModifiedRaw' data. // - for one specific node. // - the whole history in one request. var modifiedRawHistory = client.ReadNodeHistoryModified( DateTime.UtcNow.Date.AddHours(6), DateTime.UtcNow.Date.AddHours(6).AddSeconds(300), "ns=2;s=Machine_1/Position"); Console.WriteLine("Read the historical 'ModifiedRaw' data..."); foreach (var item in modifiedRawHistory) { Console.WriteLine("{0} - {1}", item.Timestamp, item.Value); Console.WriteLine("\t[{0}] by {1}", item.ModificationType, item.ModificationUserName); } } { // Read the historical 'ModifiedRaw' data page wise. // - for one specific node. // - the whole history partitioned into multiple requests. var modifiedRawHistoryNavigator = client.ReadNodeHistoryModified( DateTime.UtcNow.Date.AddHours(6), DateTime.UtcNow.Date.AddHours(6).AddSeconds(300), 2, "ns=2;s=Machine_1/Position"); Console.WriteLine("Read the historical 'ModifiedRaw' data page wise..."); do { foreach (var item in modifiedRawHistoryNavigator) { Console.WriteLine("{0} - {1}", item.Timestamp, item.Value); Console.WriteLine("\t[{0}] by {1}", item.ModificationType, item.ModificationUserName); } Console.Write("Press any key to read the next page..."); Console.ReadKey(); Console.WriteLine(); }while (modifiedRawHistoryNavigator.MoveNextPage()); } { // Read the historical data 'at time'. // - for one specific node. // - the whole history for each time specified. var atTimeHistory = client.ReadNodeHistoryAtTime( new DateTime[] { DateTime.UtcNow.Date.AddHours(6), DateTime.UtcNow.Date.AddHours(6).AddSeconds(10), DateTime.UtcNow.Date.AddHours(6).AddSeconds(20), DateTime.UtcNow.Date.AddHours(6).AddSeconds(30), DateTime.UtcNow.Date.AddHours(6).AddSeconds(40), DateTime.UtcNow.Date.AddHours(6).AddSeconds(50), }, "ns=2;s=Machine_1/Position"); Console.WriteLine("Read the historical data 'at time'..."); foreach (var item in atTimeHistory) { Console.WriteLine("{0} - {1}", item.Timestamp, item.Value); } } { // Read the historical data 'processed'. // - for one specific node. // - the whole history is processed on the server side. var processedHistory = client.ReadNodeHistoryProcessed( DateTime.UtcNow.Date.AddHours(6), DateTime.UtcNow.Date.AddHours(6).AddMinutes(30), OpcAggregateType.Maximum, "ns=2;s=Machine_1/Position"); Console.WriteLine("Read the historical data 'processed'..."); foreach (var item in processedHistory) { Console.WriteLine("{0} - {1}", item.Timestamp, item.Value); } } client.Disconnect(); Console.ReadKey(true); }
public void WriteDesiredMachineSpeed(OpcClient accessPoint, float speed) { accessPoint.WriteNode(nodeIDDictionary[NodeID.MachSpeed], speed); }