private static void TestLearn(Controller mc, CodeFormat learnFormat, LearnCodeModifier learnCodeModifier)
{
learnCompletedEventArgs = null;
Console.WriteLine("<Press x to abort Learn>");
mc.Learning += new UsbUirt.Controller.LearningEventHandler(mc_Learning);
mc.LearnCompleted += new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted);
try
{
try
{
mc.LearnAsync(learnFormat, learnCodeModifier, learnCompletedEventArgs);
}
catch(Exception ex)
{
Console.WriteLine("*** ERROR calling LearnAsync! ***");
throw;
}
while (learnCompletedEventArgs == null)
{
string s = Console.ReadLine();
if (s.Length != 0 && s[0] == 'x')
{
if (learnCompletedEventArgs == null)
{
Console.WriteLine("Calling LearnAsyncCancel...");
mc.LearnAsyncCancel(learnCompletedEventArgs);
Thread.Sleep(1000);
break;
}
}
else
{
Console.WriteLine("<Press x to abort Learn>");
}
}
if (learnCompletedEventArgs != null &&
learnCompletedEventArgs.Cancelled == false &&
learnCompletedEventArgs.Error == null)
{
irCode = learnCompletedEventArgs.Code;
Console.WriteLine("...Done...IRCode = {0}", irCode);
transmitFormat = learnFormat;
}
}
finally
{
mc.Learning -= new UsbUirt.Controller.LearningEventHandler(mc_Learning);
mc.LearnCompleted -= new UsbUirt.Controller.LearnCompletedEventHandler(mc_LearnCompleted);
}
}