Beispiel #1
0
        public static int Main(string[] args)
        {
            Console.WriteLine(".Net Core OPC UA Complex Types Client sample");

            // command line options
            bool   showHelp        = false;
            int    stopTimeout     = Timeout.Infinite;
            bool   autoAccept      = false;
            bool   writeComplexInt = false;
            bool   noTypes         = false;
            bool   noBrowse        = false;
            bool   verbose         = false;
            bool   json            = false;
            bool   jsonReversible  = false;
            string username        = null;
            string pw = null;
            string reverseConnectUrlString = null;
            Uri    reverseConnectUrl       = null;

            Mono.Options.OptionSet options = new Mono.Options.OptionSet {
                { "h|help", "show this message and exit", h => showHelp = h != null },
                { "a|autoaccept", "auto accept certificates (for testing only)", a => autoAccept = a != null },
                { "t|timeout=", "the number of seconds until the client stops.", (int t) => stopTimeout = t },
                { "w|writeint", "Read and increment all complex types with an Int32.", w => writeComplexInt = w != null },
                { "n|notypes", "Do not load the type system dictionary from the server.", n => noTypes = n != null },
                { "b|nobrowse", "Do not browse the address space of the server.", n => noBrowse = n != null },
                { "u|username="******"Username to access server.", (string n) => username = n },
                { "p|password="******"Password to access server.", (string n) => pw = n },
                { "v|verbose", "Verbose output.", v => verbose = v != null },
                { "j|json", "Print custom nodes as Json.", j => json = j != null },
                { "r|jsonreversible", "Use Json reversible encoding.", r => jsonReversible = r != null },
                { "rc|reverseconnect=", "Connect using the reverse connection.", (string url) => reverseConnectUrlString = url },
            };

            IList <string> extraArgs = null;

            try
            {
                extraArgs = options.Parse(args);
                if (extraArgs.Count > 1)
                {
                    foreach (string extraArg in extraArgs)
                    {
                        Console.WriteLine("Error: Unknown option: {0}", extraArg);
                        showHelp = true;
                    }
                }
                if (reverseConnectUrlString != null)
                {
                    reverseConnectUrl = new Uri(reverseConnectUrlString);
                }
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                showHelp = true;
            }

            if (showHelp)
            {
                // show some app description message
                Console.WriteLine("Usage: dotnet NetCoreConsoleClient.dll [OPTIONS] [ENDPOINTURL]");
                Console.WriteLine();

                // output the options
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return((int)ExitCode.ErrorInvalidCommandLine);
            }

            string endpointURL;

            if (extraArgs.Count == 0)
            {
                // use OPC UA .Net Sample server
                endpointURL = "opc.tcp://localhost:51210/UA/SampleServer";
            }
            else
            {
                endpointURL = extraArgs[0];
            }

            MySampleClient client = new MySampleClient(endpointURL, autoAccept, stopTimeout)
            {
                Verbose             = verbose,
                LoadTypeSystem      = !noTypes,
                BrowseAdddressSpace = !noBrowse,
                WriteComplexInt     = writeComplexInt,
                PrintAsJson         = json,
                JsonReversible      = jsonReversible,
                Username            = username,
                Password            = pw,
                ReverseConnectUri   = reverseConnectUrl
            };

            return((int)client.Run());
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            Console.WriteLine(
                (Utils.IsRunningOnMono() ? "Mono" : ".Net Core") +
                " OPC UA Console Client sample");

            // command line options
            bool showHelp    = false;
            int  stopTimeout = Timeout.Infinite;
            bool autoAccept  = false;

            Mono.Options.OptionSet options = new Mono.Options.OptionSet {
                { "h|help", "show this message and exit", h => showHelp = h != null },
                { "a|autoaccept", "auto accept certificates (for testing only)", a => autoAccept = a != null },
                { "t|timeout=", "the number of seconds until the client stops.", (int t) => stopTimeout = t }
            };

            IList <string> extraArgs = null;

            try
            {
                extraArgs = options.Parse(args);
                if (extraArgs.Count > 1)
                {
                    foreach (string extraArg in extraArgs)
                    {
                        Console.WriteLine("Error: Unknown option: {0}", extraArg);
                        showHelp = true;
                    }
                }
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                showHelp = true;
            }

            if (showHelp)
            {
                // show some app description message
                Console.WriteLine(Utils.IsRunningOnMono() ?
                                  "Usage: mono MonoConsoleClient.exe [OPTIONS] [ENDPOINTURL]" :
                                  "Usage: dotnet NetCoreConsoleClient.dll [OPTIONS] [ENDPOINTURL]");
                Console.WriteLine();

                // output the options
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return((int)ExitCode.ErrorInvalidCommandLine);
            }

            string endpointURL;

            if (extraArgs.Count == 0)
            {
                // use OPC UA .Net Sample server
                endpointURL = "opc.tcp://localhost:51210/UA/SampleServer";
            }
            else
            {
                endpointURL = extraArgs[0];
            }

            MySampleClient client = new MySampleClient(endpointURL, autoAccept, stopTimeout);

            client.Run();

            return((int)MySampleClient.ExitCode);
        }
Beispiel #3
0
        public static int Main(string[] args)
        {
            Console.WriteLine(".Net Core OPC UA Complex Types Client sample");

            // command line options
            bool showHelp        = false;
            int  stopTimeout     = Timeout.Infinite;
            bool autoAccept      = false;
            bool writeComplexInt = false;
            bool noloadTypes     = false;
            bool verbose         = false;
            bool json            = false;

            Mono.Options.OptionSet options = new Mono.Options.OptionSet {
                { "h|help", "show this message and exit", h => showHelp = h != null },
                { "a|autoaccept", "auto accept certificates (for testing only)", a => autoAccept = a != null },
                { "t|timeout=", "the number of seconds until the client stops.", (int t) => stopTimeout = t },
                { "w|writeint", "Read and increment all complex types with an Int32.", w => writeComplexInt = w != null },
                { "n|noloadtypes", "Load the type system dictionary from the server.", n => noloadTypes = n != null },
                { "v|verbose", "Verbose output.", v => verbose = v != null },
                { "j|json", "Print custom nodes as Json.", j => json = j != null },
            };

            IList <string> extraArgs = null;

            try
            {
                extraArgs = options.Parse(args);
                if (extraArgs.Count > 1)
                {
                    foreach (string extraArg in extraArgs)
                    {
                        Console.WriteLine("Error: Unknown option: {0}", extraArg);
                        showHelp = true;
                    }
                }
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                showHelp = true;
            }

            if (showHelp)
            {
                // show some app description message
                Console.WriteLine("Usage: dotnet NetCoreConsoleClient.dll [OPTIONS] [ENDPOINTURL]");
                Console.WriteLine();

                // output the options
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return((int)ExitCode.ErrorInvalidCommandLine);
            }

            string endpointURL;

            if (extraArgs.Count == 0)
            {
                // use OPC UA .Net Sample server
                endpointURL = "opc.tcp://localhost:51210/UA/SampleServer";
            }
            else
            {
                endpointURL = extraArgs[0];
            }

            MySampleClient client = new MySampleClient(endpointURL, autoAccept, stopTimeout)
            {
                Verbose         = verbose,
                LoadTypeSystem  = !noloadTypes,
                WriteComplexInt = writeComplexInt,
                PrintAsJson     = json
            };

            return((int)client.Run());
        }