private static void LearnAndTransmitACode() { using (var driver = new Driver()) { Console.WriteLine(Driver.GetVersion(driver).ToString()); Console.WriteLine("Receiving..."); var receiver = new Receiver(driver); receiver.GenerateLegacyCodes = false; receiver.Received += OnReceive; var learner = new Learner(driver); learner.Learning += OnLearning; Console.WriteLine("Learning..."); var result = learner.Learn(); Console.WriteLine("Learned code: " + result); Console.WriteLine("Hit enter to Transmit"); Console.ReadLine(); var transmitter = new Transmitter(driver); transmitter.TransmitCompleted += OnTransmitComplete; transmitter.TransmitAsync(result, emitter: Emitter.Internal) .ContinueWith(t => Console.WriteLine(t.Exception == null ? "Transmit Complete - from task" : t.Exception.ToString())); } }
public UsbUirtProcessor(IList<IrCommandEvent> commands) { _driver = new Driver(); Log.Debug(string.Format("Usbuirt found version {0}", Driver.GetVersion(_driver))); _receiver = new Receiver(_driver); _receiver.GenerateLegacyCodes = false; _receiver.Received += OnIrReceive; _transmitter = new Transmitter(_driver); _learner = new Learner(_driver); _commands = commands; _learnCommand = null; //Event from ep source OnSourceEvent = (@event, sender) => { if (@event.Channel != Channel && !string.IsNullOrEmpty(@event.Channel)) return; switch (@event.Name) { case "ir-transmit": var ir = System.Text.Encoding.Default.GetString(@event.Data); _transmitter.TransmitAsync(ir); break; case "ir-learn": _learnCommand = @event as IrCommandEvent; _learner.LearnAsync(CodeFormat.Uuirt, LearnCodeModifier.Default, null); break; } }; //Error from ep source OnSourceError = (exception, sender) => { Log.Error("Error from source endpoint", exception); }; //Close connection with ep source OnSourceClose = (sender) => { //Close HBus endpoint Stop(); Log.Debug("closed on source close"); }; }