Ejemplo n.º 1
0
        public ProductionTask GetCurrentTaskResult()
        {
            bool   success;
            string message;

            ProductionTask taskResult = new ProductionTask();

            using (OpcClient client = new OpcClient(endpoint))
            {
                client.Connect();
                object[] result = client.CallMethod(
                    "ns=3;s=\"OpcUaMethodGetTaskResult\"",
                    "ns=3;s=\"OpcUaMethodGetTaskResult\".Method"
                    );
                success = Convert.ToBoolean(result[0]);
                message = Convert.ToString(result[1]);
                if (success)
                {
                    taskResult.ID         = Convert.ToInt32(result[2]);
                    taskResult.PiceAmount = Convert.ToInt16(result[3]);
                    taskResult.Operator   = Convert.ToString(result[4]);

                    taskResult.FinishDate = DateTime.Now;
                }
                else
                {
                    throw new Exception(message);
                }
            }

            return(taskResult);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// отправить в ПЛК задание
 /// </summary>
 public void SendTask(ProductionTaskExtended task)
 {
     Log.logThis($"SendTask: {task.Task.TaskNumber}");
     using (OpcClient client = new OpcClient(endpoint))
     {
         try
         {
             client.Connect();
             object[] result = client.CallMethod(
                 "ns=3;s=\"OpcUaMethodSendNewTask\"",
                 "ns=3;s=\"OpcUaMethodSendNewTask\".Method",
                 (Int32)task.Task.ID,
                 (string)task.Task.TaskNumber,
                 (Int16)task.Task.Diameter,
                 (Int16)task.Task.Thickness,
                 (float)task.Task.PieceLength1,
                 (Int16)task.Task.PieceQuantity1,
                 (Int16)task.serialLabel.StartSerial,
                 (string)task.Task.Labeling1Piece1,
                 (string)task.Task.Labeling2Piece1,
                 (string)task.serialLabel.EndLabel
                 );
         }
         catch (Exception e)
         {
             Log.logThis(e.Message);
         }
     }
 }
Ejemplo n.º 3
0
        public void SendTask(TaskProxy.Task task)
        {
            using (client = new OpcClient("opc.tcp://192.168.10.2:4840"))
            {
                client.Connect();

                object[] result = client.CallMethod(
                    "ns=3;s=\"SendNewTask\"",
                    "ns=3;s=\"SendNewTask\".Method",
                    (Int16)task.ID,
                    (String)task.Number.Trim(),
                    (String)task.Item.Trim(),
                    (String)task.StartSerial.Trim(),
                    (Int16)task.TargetCount);
                Log.GetLog().logThis(task.PrintToString());
            }
        }
Ejemplo n.º 4
0
        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();
        }