Пример #1
0
        public void Start()
        {
            _listener.Start();

            while (true)
            {
                var  colorPacket     = WaitForColorByteCommand();
                byte colorByteToSend = CalculateColorByteForOrb(colorPacket);
                _orb.TurnLightningOn(colorByteToSend);
            }
        }
Пример #2
0
            new UsbDeviceFinder(0x16C0, 0x05DB); // specify vendor, product id

        #endregion

        public static void Main(string[] args)
        {
            ErrorCode ec = ErrorCode.None;

            try
            {
                var argValues = new ArgParser(args);

                if (argValues.IsRemoteClientMode)
                {
                    using (var serverClient = new TcpClientOrb(argValues, new ColorByteConverter()))
                    {
                        serverClient.Send(argValues.Color);
                        Console.WriteLine("\r\nDone!\r\n");
                        return;
                    }
                }

                // Find and open the usb device.
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
                // If the device is open and ready
                if (MyUsbDevice == null)
                {
                    throw new Exception("Device Not Found.");
                }
                SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true);
                _orb = new BuildOrbDevice(MyUsbDevice);
                if (argValues.IsClientMode)
                {
                    _orb.TurnLightningOn(argValues.Color);
                }
                else
                {
                    var server = new TcpServerOrb(argValues, _orb);
                    Console.WriteLine("Server was started on interface {0}", server.ServerIpAddress);
                    server.Start();
                }

                Console.WriteLine("\r\nDone!\r\n");
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
            }
            finally
            {
                ReleaseResourcesIfRequired();
            }
        }