Exemplo n.º 1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            ConnectType type = ConnectType.USB;

            switch (selectType.SelectedIndex)
            {
            case 0:
                MessageBox.Show("Please Select Connection Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;

            case 2:
                type = ConnectType.WiFi;
                break;
            }
            eAntennaNo antNum = 0;

            if (chkAntenna1.Checked)
            {
                antNum |= eAntennaNo._1;
            }
            if (chkAntenna2.Checked)
            {
                antNum |= eAntennaNo._2;
            }
            if (chkAntenna3.Checked)
            {
                antNum |= eAntennaNo._3;
            }
            if (chkAntenna4.Checked)
            {
                antNum |= eAntennaNo._4;
            }
            int interval = Convert.ToInt32(txtTime.Value);

            Reader = GetReader(txtReaderType.SelectedIndex, interval, antNum);
            if (Reader == null)
            {
                return;
            }
            if (Reader.Connect(type))
            {
                txtConnection.Text = "Connected Successfully";
                Connect            = true;
                Log("Connected");
            }
            else
            {
                txtConnection.Text = "Connection Faild!";
                Log("Faild to connect");
            }
        }
 private void ConnectIpt(IPAddress address, int port)
 {
     _isIptConnected = false;
     try
     {
         _iptReader = IptReader.GetInstance(address, port);
         _iptReader.Connect();
     }
     catch (SocketException ex)
     {
         OnIptError(new DataReaderErrorEventArgs(ex.ErrorCode, ex.Message));
         return;
     }
     _isIptConnected = true;
 }
Exemplo n.º 3
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 ConnectScud(IPAddress address, int port)
 {
     _scudReader = ScudReader.GetInstance(address, port);
     _scudReader.Connect();
 }