Control a Projector with AHK and USB-UIRT

Put simple Tips and Tricks that are not entire Tutorials in this forum
rbinckahk
Posts: 2
Joined: 13 Aug 2021, 17:32

Control a Projector with AHK and USB-UIRT

13 Aug 2021, 19:58

I have a projector that I needed to have shutdown when the power fails for more that a small outage to allow the cool down to occur. I have the projector powered by a UPS, but it does not have any method like a PC does to allow th UPS to initiate a shutdown. Since it is possible to detect a power failure on a laptop using a dll call to check the ac line state.

Since I use a Lenovo V560 with the Hauppauge WinTV-DualHD Dual USB 2.0 HD TV Tuner for Windows and Windows Media Center on Windows 7, it occurred to me that I could use a AHK script with an IR transmitter to trigger the shutdown. So I ordered a USB-UIRT from ebay and with the following script I was in business:

Code: Select all

#SingleInstance Force

settimer, PowerCheck, 1000							;Check power once a second (could be longer)

!x::												;Exit App Hotkey	
ExitApp

PowerCheck:
VarSetCapacity(powerstatus, 1+1+1+1+4+4)
success := DllCall("kernel32.dll\GetSystemPowerStatus", "uint", &powerstatus)

acLineStatus:=ReadInteger(&powerstatus,0,1,false)
;batteryFlag:=ReadInteger(&powerstatus,1,1,false)								;Used for other issues
;batteryLifePercent:=ReadInteger(&powerstatus,2,1,false)
;batteryLifeTime:=ReadInteger(&powerstatus,4,4,false)
;batteryFullLifeTime:=ReadInteger(&powerstatus,8,4,false)

;tooltip OffTime: %OffTime% `n acLineStatus: %acLineStatus%, 500,100			;testing
if (acLineStatus <> 1)
	OffTime++
else
	OffTime := 0
If (OffTime > 60)																;Allow 1 minute in case power fail is momentary
{
	PowerFailFlag := 1															;Set Power Fail Flag used for orderly shutdown in case recording
	PJoff:
	run, C:\uutx "0000 006D 0000 0022 0157 00AC 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0015 0016 0041 0016 0015 0016 0015 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0015 0016 0015 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0016 0016 0040 0016 05D3"
	
	sleep 1000		;Must send twice for PJ to shutdown
	run, C:\uutx "0000 006D 0000 0022 0157 00AC 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0015 0016 0041 0016 0015 0016 0015 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0041 0016 0015 0016 0041 0016 0041 0016 0041 0016 0015 0016 0015 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0016 0016 0040 0016 05D3"
	
}
return
ExitApp

ReadInteger( p_address, p_offset, p_size, p_hex=true )
{
  value = 0
  old_FormatInteger := a_FormatInteger
  if ( p_hex )
    SetFormat, integer, hex
  else
    SetFormat, integer, dec
  loop, %p_size%
    value := value+( *( ( p_address+p_offset )+( a_Index-1 ) ) << ( 8* ( a_Index-1 ) ) )
  SetFormat, integer, %old_FormatInteger%
  return, value
}
Obviously, you can use the USB-UIRT to do any other operations by your PC the remote will allow like changing stations automatically or switching inputs, etc.

To get the code the projector required to initiate the shutdown I used an app lrnhelper which allow you to point the remote at the USB-UIRT and learn the button code. The copy and paste into your AHK script.

There is also the possibility to submit a file containing all of your remote codes in a .txt file and invoke the send like this:
run, C:\uutx -f<filename.txt> <IRCodeName> Example: run, C:\uutx C:\remote\codes.txt play
The function is case sensitive, so play and PLAY are different.

In the file the codes are entered like this:
; Format: <IRCodeName> <IRCode> (you can add comments in the file with ; )
play 0000 0067 0000 0004 0011 0011 0022 0022 0011 0022 0011 0387
pause 0000 0067 0000 0004 0011 0011 0022 0022 0011 0022 0011 0388

Use tabs after the IRcodeName then the learned code

For other control by an AHK script will be a matter of calling the uutx app with the appropriate filename and IRCodeName.

To download the USB-UIRT driver goto the USB-UIRT webpage at http://www.usbuirt.com/getstart.htm and select the Windows system you have. Use the i386 folder.
To download the uutx app here is the download link: http://www.etcwiki.org/dl/uutx_0_3.zip
To download the lrnhelper apphttp://www.usbuirt.com/lrnhelper_0_0_5.zip

You will also need the uuirtdrv.dll file available in the i386 folder for the driver.
Once installed the uuirtdrv.dll should be moved from the i386 folder to C:\WINDOWS\system32\
Once the USB-UIRT driver is downloaded, the driver is installed using the device manager per the instructions on the USB-UIRT getstart page.

Return to “Tips and Tricks (v1)”

Who is online

Users browsing this forum: No registered users and 15 guests