private void SendKeyCodeToReceiver(int keyCode, UIR_CFG irBlasterConfiguration) { int returnValue = UIR_SendKeyCode(irBlasterConfiguration.cfgDevice, irBlasterConfiguration.cfgCodeset, keyCode); if (returnValue != (int)UIRError.UIRError_Success) { throw new Exception($"ERROR: Failed to send a key code to the satellite receiver: {returnValue}"); } }
private void GoToChannel(int channelNumber, UIR_CFG irBlasterConfiguration) { int returnValue = UIR_GotoChannel(irBlasterConfiguration.cfgDevice, irBlasterConfiguration.cfgCodeset, channelNumber); if (returnValue != (int)UIRError.UIRError_Success) { throw new Exception($"ERROR: Failed to change the channel: {returnValue}"); } }
private bool LoadBlasterConfig(ref UIR_CFG configuration) { configuration.cfgDataSize = 0x38; int returnValue = UIR_GetConfig(-1, -1, ref configuration); if (returnValue == (int)UIRError.UIRError_Success) { Console.WriteLine("Hauppauge Ir Blaster configuration ..."); Console.WriteLine(String.Format("Device: {0} Vendor: {1}", configuration.cfgDevice, configuration.cfgVendor)); Console.WriteLine(String.Format("Region: {0} Code Set: {1}", configuration.cfgRegion, configuration.cfgCodeset)); Console.WriteLine(String.Format("Digit Delay: {0} Minimum Digits: {1}", configuration.DigitDelay, configuration.MinDigits)); Console.WriteLine(String.Format("Send Power On: {0} Power On Delay: {1}", configuration.SendPowerOn, configuration.PowerOnDelay)); Console.WriteLine(String.Format("One Digit Delay: {0} Tune Delay: {1}", configuration.OneDigitDelay, configuration.TuneDelay)); Console.WriteLine(String.Format("Need Enter: {0} Enter Delay: {1}", configuration.NeedsEnter, configuration.EnterDelay)); } else { throw new Exception($"ERROR: Failed to read IR blaster configuration: {returnValue}"); } return(true); }
public int WakeUp(string channel) { // 1. Send WAKE UP to the receiver // 2. Wait 1 second // 3. Change the channel of the receiver // 4. Wait 1 second // 5. Stop Hauppauge Recording Service // 6. Start Hauppauge Recording Service // 7. Put the machine back to sleep mode if there are no active processes int returnResult = 0; WindowsServiceController windowsServiceController = new WindowsServiceController(Settings.Default.HauppaugeRecordingServiceName); try { int channelNumber; if (Int32.TryParse(channel, out channelNumber) == false) { throw new Exception($"ERROR: Failed to convert command line parameter: {channel} to channel number"); } // activate the IR blaster port OpenIrBlasterPort(); // read the IR blaster configuration structure UIR_CFG irBlasterConfiguration = new UIR_CFG(); LoadBlasterConfig(ref irBlasterConfiguration); // 1. Send WAKE UP to the receiver SendKeyCodeToReceiver(WAKE_UP_CODE, irBlasterConfiguration); // 2. Wait 1 second Thread.Sleep(1000); // 3. Change the channel of the receiver GoToChannel(channelNumber, irBlasterConfiguration); // 4. Wait 1 second Thread.Sleep(1000); // close the ir blaster port CloseIrBlasterPort(); // 5. Stop Hauppauge Recording Service windowsServiceController.StopService(); } catch (Exception ex) { Console.WriteLine("HirContoller.WakeUp() ERROR: {0}", ex.ToString()); returnResult = 1; } finally { // 6. Start Hauppauge Recording Service windowsServiceController.StartService(); // 7. Put the MCE back to sleep mode if there are no active processes SetSuspendState(false, false, false); // sleep mode, do not force processes, enable wake up events } return(returnResult); }
private static extern int UIR_GetConfig(int device, int codeset, ref UIR_CFG cfgPtr);
private static int Main(string[] args) { Console.WriteLine("HCW PVR Tuner"); Console.WriteLine(); IrssLog.LogLevel = IrssLog.Level.Debug; IrssLog.Open("Dbox Tuner.log"); if (args.Length != 1) { Console.WriteLine("Usage:"); Console.WriteLine(" HcwPvrTuner.exe <Channel Number>"); Console.WriteLine(); return(ReturnError); } bool deviceOpen = false; try { int channelNumber; if (!int.TryParse(args[0], out channelNumber)) { throw new ArgumentException(String.Format("Failed to convert command line parameter ({0}) to channel number", args[0])); } Info("Attempting to tune channel {0} ...", channelNumber); int returnValue = UIR_Open(0, 0); if (returnValue == 0) { throw new InvalidOperationException(String.Format("Failed to start device access ({0})", returnValue)); } else { deviceOpen = true; } UIR_CFG config = new UIR_CFG(); config.a = 0x38; returnValue = UIR_GetConfig(-1, -1, ref config); if (returnValue == 0) { Info("Device configuration ..."); Info("Device: {0} Vendor: {1}", config.d, config.e); Info("Region: {0} Code Set: {1}", config.c, config.f); Info("Digit Delay: {0} Minimum Digits: {1}", config.j, config.i); Info("One Digit Delay: {0} Tune Delay: {1}", config.n, config.m); Info("Need Enter: {0} Enter Delay: {1}", config.k, config.l); } else { throw new InvalidOperationException(String.Format("Failed to retrieve device configuration ({0})", returnValue)); } returnValue = UIR_GotoChannel(config.d, config.f, channelNumber); if (returnValue == 0) { throw new InvalidOperationException(String.Format("Failed to tune channel ({0})", returnValue)); } } catch (Exception ex) { Info(ex.ToString()); return(ReturnError); } finally { if (deviceOpen) { UIR_Close(); } } Info("Done."); IrssLog.Close(); return(ReturnSuccess); }
private static int Main(string[] args) { Console.WriteLine("HCW PVR Tuner"); Console.WriteLine(); IrssLog.LogLevel = IrssLog.Level.Debug; IrssLog.Open("Dbox Tuner.log"); if (args.Length != 1) { Console.WriteLine("Usage:"); Console.WriteLine(" HcwPvrTuner.exe <Channel Number>"); Console.WriteLine(); return ReturnError; } bool deviceOpen = false; try { int channelNumber; if (!int.TryParse(args[0], out channelNumber)) throw new ArgumentException(String.Format("Failed to convert command line parameter ({0}) to channel number", args[0])); Info("Attempting to tune channel {0} ...", channelNumber); int returnValue = UIR_Open(0, 0); if (returnValue == 0) throw new InvalidOperationException(String.Format("Failed to start device access ({0})", returnValue)); else deviceOpen = true; UIR_CFG config = new UIR_CFG(); config.a = 0x38; returnValue = UIR_GetConfig(-1, -1, ref config); if (returnValue == 0) { Info("Device configuration ..."); Info("Device: {0} Vendor: {1}", config.d, config.e); Info("Region: {0} Code Set: {1}", config.c, config.f); Info("Digit Delay: {0} Minimum Digits: {1}", config.j, config.i); Info("One Digit Delay: {0} Tune Delay: {1}", config.n, config.m); Info("Need Enter: {0} Enter Delay: {1}", config.k, config.l); } else { throw new InvalidOperationException(String.Format("Failed to retrieve device configuration ({0})", returnValue)); } returnValue = UIR_GotoChannel(config.d, config.f, channelNumber); if (returnValue == 0) throw new InvalidOperationException(String.Format("Failed to tune channel ({0})", returnValue)); } catch (Exception ex) { Info(ex.ToString()); return ReturnError; } finally { if (deviceOpen) UIR_Close(); } Info("Done."); IrssLog.Close(); return ReturnSuccess; }
static HCWIRBlaster() { HCWRetVal = 0; HCWIRConfig = new UIR_CFG(); }