Ejemplo n.º 1
0
		public static void Main(string[] args) 
		{
			switch (mode) {
			case Mode.Keyboard:
				receiver = new KeyboardCommandReceiver();
				break;
			case Mode.Socket:
				receiver = new SocketCommandReceiver();
				break;
			default:
				Console.WriteLine("Unknown mode: " + mode.ToString ());
				Environment.ExitCode = 1;
				return;
			}

			if (!test) {
				port = new SerialPort ("/dev/tty.usbmodem1421", 9600);
				port.Open ();
			}

			try {
				CancellationTokenSource cancelStop = null;
				char? lastCmd = null;
				do {
					char cmd = receiver.BlockUntilNextCmd();

					if (cancelStop != null)
						cancelStop.Cancel();

					if (lastCmd == null
						|| lastCmd.Value != cmd) {
						Send(cmd);
					} 

					lastCmd = cmd;

					cancelStop = new CancellationTokenSource();
					Task.Delay(TimeSpan.FromMilliseconds(750), cancelStop.Token)
						.ContinueWith(task => {
							if (!task.IsCanceled) {
								cancelStop = null;
								lastCmd = null;
								Send('Q');
							}
						});
				} while (receiver.AnotherCommand());

				Send('Q');
			} finally {
				port.Close();
			}
		}
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            switch (mode)
            {
            case Mode.Keyboard:
                receiver = new KeyboardCommandReceiver();
                break;

            case Mode.Socket:
                receiver = new SocketCommandReceiver();
                break;

            default:
                Console.WriteLine("Unknown mode: " + mode.ToString());
                Environment.ExitCode = 1;
                return;
            }

            if (!test)
            {
                port = new SerialPort("/dev/tty.usbmodem1421", 9600);
                port.Open();
            }

            try {
                CancellationTokenSource cancelStop = null;
                char?lastCmd = null;
                do
                {
                    char cmd = receiver.BlockUntilNextCmd();

                    if (cancelStop != null)
                    {
                        cancelStop.Cancel();
                    }

                    if (lastCmd == null ||
                        lastCmd.Value != cmd)
                    {
                        Send(cmd);
                    }

                    lastCmd = cmd;

                    cancelStop = new CancellationTokenSource();
                    Task.Delay(TimeSpan.FromMilliseconds(750), cancelStop.Token)
                    .ContinueWith(task => {
                        if (!task.IsCanceled)
                        {
                            cancelStop = null;
                            lastCmd    = null;
                            Send('Q');
                        }
                    });
                } while (receiver.AnotherCommand());

                Send('Q');
            } finally {
                port.Close();
            }
        }