private void DisconnectScud()
 {
     _scudReader.Disconnect();
     _scudReader.Dispose();
 }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("BobRfid starting up.");
            appSettings.SettingsSaving += AppSettings_SettingsSaving;

            InitializeClient();

            if (args.Length > 0 && args.Contains("--test"))
            {
                reader = new FakeReader();
            }
            else
            {
                reader = new RealReader();
            }

            if (args.Length > 0 && args.Contains("--register"))
            {
                RegistrationMode = true;
                logger.Trace("Started in registration mode.");
            }

            var lowPower = false;

            if (args.Length > 0 && args.Contains("--lowpower"))
            {
                lowPower = true;
            }

            Task.Run(() => ProcessTags());

            if (args.Length > 0 && args.Contains("--verifytrace"))
            {
                try
                {
                    VerifyTrace();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex}");
                }

                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();

                return;
            }

            Task.Run(() => SubmitLaps());

            Console.WriteLine($"Waiting {appSettings.StartupDelaySeconds} seconds for reader to start up.");
            Thread.Sleep(TimeSpan.FromSeconds(appSettings.StartupDelaySeconds));

            try
            {
                Connect(lowPower);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to connect to reader: {ex}");
            }

            Task.Run(() => CheckConnections());

            if (args.Length > 0 && args.Contains("--form"))
            {
                Console.WriteLine("Form GUI is not currently supported.");
            }
            else
            {
                string input = string.Empty;
                Console.WriteLine("Type 'exit' to stop.");
                while (true)
                {
                    Console.Write("BobRfid:> ");
                    input = Console.ReadLine().Trim();
                    if (input.Equals("exit", StringComparison.InvariantCultureIgnoreCase))
                    {
                        break;
                    }
                    else if (input.Equals("connect", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine("Connecting...");
                        reader.Connect();
                    }
                    else if (input.Equals("disconnect", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine("Disconnecting...");
                        reader.Disconnect();
                    }
                    else if (input.Equals("instance", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine($"Currently connecting to '{appSettings.ServiceBaseAddress}'.");
                        Console.Write("New instance name (blank to leave unchanged):> ");
                        var newInstance = Console.ReadLine().Trim();
                        if (!string.IsNullOrWhiteSpace(newInstance))
                        {
                            appSettings.ServiceBaseAddress = $"http://legsofsteel.bob85.com/{newInstance}/";
                            appSettings.Save();
                        }
                    }
                    else if (input.Equals("timeout", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine($"Current service timeout is {appSettings.ServiceTimeoutSeconds} seconds.");
                        Console.Write("New value in seconds (blank to leave unchanged:> ");
                        var newTimeout = Console.ReadLine().Trim();
                        if (!string.IsNullOrWhiteSpace(newTimeout))
                        {
                            if (int.TryParse(newTimeout, out int timeout) && timeout > 0)
                            {
                                appSettings.ServiceTimeoutSeconds = timeout;
                                appSettings.Save();
                            }
                            else
                            {
                                logger.Warn($"Invalid timeout value '{newTimeout}'.");
                            }
                        }
                    }
                    else if (input.Equals("ip", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine($"Currently connecting to reader at host '{appSettings.ReaderIpAddress}'.");
                        Console.Write("New hostname or IP address (blank to leave unchanged):> ");
                        var newReaderHost = Console.ReadLine().Trim();
                        if (!string.IsNullOrWhiteSpace(newReaderHost))
                        {
                            appSettings.ReaderIpAddress = newReaderHost;
                            appSettings.Save();
                        }
                    }
                    else if (input.Equals("startupdelay", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Console.WriteLine($"Current startup delay is {appSettings.StartupDelaySeconds} seconds.");
                        Console.Write("New value in seconds (blank to leave unchanged:> ");
                        var newStartupDelay = Console.ReadLine().Trim();
                        if (!string.IsNullOrWhiteSpace(newStartupDelay))
                        {
                            if (int.TryParse(newStartupDelay, out int delay) && delay >= 0)
                            {
                                appSettings.StartupDelaySeconds = delay;
                                appSettings.Save();
                            }
                            else
                            {
                                logger.Warn($"Invalid startup delay value '{newStartupDelay}'.");
                            }
                        }
                    }
                    else if (reader is FakeReader)
                    {
                        ((FakeReader)reader).SendCommand(input);
                    }
                }
            }

            try
            {
                Console.WriteLine("Exiting...");
                reader.Stop();
                reader.Disconnect();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to disconnect upon exit: {ex}");
            }
            finally
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
 private void DisconnectIpt()
 {
     _iptReader.Disconnect();
     _iptReader.Dispose();
     _isIptConnected = false;
 }