Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

USB-UIRT Function Library, Direct IR Remote, AHK interaction


  • Please log in to reply
27 replies to this topic
specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
USB-UIRT Function Library
Direct Infrared Remote Control with AHK, Version 1.1 released 6/18/12
WinLIRC No longer needed.

After a lot a trial and error and a tremendous amount of patience I was able to follow what had been started by Laszlo, cynopsys and Thracx,
http://www.autohotke...pic.php?t=43255
and complete (almost) a library for all the functions of the USB-UIRT IR transceiver.
http://www.usbuirt.com/

:D Use the IR button code from any remote as labels in your scripts.
:D Transmit IR from your computer to control anything that has it's own remote control.
:D Learn IR codes from your remotes or download codes from the internet.
:D IR labels can be used in any script simply by calling the library function in the auto execute section. IR codes captured with USB-UIRT are suitable to copy and paste directly into your scripts as labels making direct control of any subroutine possible using any IR remote control.

The library contains all available USB-UIRT functions, example scripts of every function and the original developers notes.
View/download it here.
Temporary link while ahk.net is down.
USBUIRT.ahk


Version 1.1 updates
1. Added USBUIRT_Abort(LearnPID) as a means to abort the learn processes.
2. Added a repeat parameter when transmitting IR codes. USBUIRT_SendIRRaw(IRCode,RepeatCount=1)
3. Corrected mistakes and typos suggested by wtg, thank you.
4. Updated many of the example scripts.
5. Removed seemingly unnecessary get/set batchlines/windelay.


This is not only my first attempt at accessing a dll but also my first attempt at creating a library so I'm sure there will be several things that could be improved upon. There are three two parts of functions I have not been able to figure out but all major functions are operational such as Receiving IR, Transmitting IR, Learning IR codes, querying and changing transceiver settings, and querying DLL and hardware info.

To learn how to use IR codes as labels see the example script "Receiving IR". IR for use as labels does not need to be learned, just point your remote at the transceiver and press a button. The IR code is copied into the top edit box. Copy your IR code in place of the code in the labels at the bottom of the script. It's that simple.

The "Almost" part. There are three two parts of the library I was unable to figure out on my own.

1 - Getting the return of the receive IR function. The return is not needed to use IR codes as labels. Edit, removed the temporary workaround in the library. Replaced the example script with one script that demonstrates using IR codes as labels and another that captures the IR codes. The capture script contains the needed functions and does not call the library.

2 - The learn progress function is not operational, no way to tell if the learn is progressing.

3 - The learn abort is not operational. While in learn mode the gui is locked, you cannot interact with it. If no IR code is received the process must be killed in task manager.The new abort function kills the script process from another script.

If anyone can assist in getting these two things functioning I would greatly appreciate it. Suggestions for improvements are also welcome. I also have no way of knowing if I am correctly getting the return of "User Data" other than assigning a string to the variable and making sure it gets copied to the edit box.

Edit, just found another bug. When first ran ConfigInfo returns a value of 19 when it looks as if it should only return 0-7. Although I can tell the configuration is set it only returns the correct value after setting it again.

I have seen several request for help with IR remotes just in the last couple of months. I hope this library will be useful for the AHK community.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Looks promising! Thanks for sharing!

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


TheGood
  • Members
  • 589 posts
  • Last active: Mar 22 2014 03:22 PM
  • Joined: 30 Jul 2007
Nice! I'll test it later.
Did this allow you to catch that ever-elusive Power button on your remote?

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

Nice! I'll test it later.
Did this allow you to catch that ever-elusive Power button on your remote?

No, that remote is strictly RF but I have gotten someone to help me build a library for the advanced HID DLL you showed me. Not sure how that going to work out yet.

This being my first library I would appreciate any pointers. I probably should have posted this in the help section with as many "Did I do this correctly?" questions I have.

Edit, I could really use your advice on getting the return IRcode in the IRReceive function. It looks as though I need to use the same method you did in the AHKHID examples but I haven't been able to get it to work so I'm using a temp workaround.

wtg
  • Members
  • 251 posts
  • Last active: Dec 19 2012 03:54 PM
  • Joined: 04 Oct 2006
Looking forward to trying this out... of course I have to work this weekend! :x

Thanks again for all your hard work!

r0lZ
  • Members
  • 192 posts
  • Last active: Feb 11 2012 11:19 PM
  • Joined: 21 Apr 2007
Does it work under X64 systems? (Windows 7)
r0lZ

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

Does it work under X64 systems? (Windows 7)


I only have XP so I can't test it but I believe it should.
The Win7 drivers are here,
http://www.usbuirt.com/support.htm

If you decide to try it please post your results.

Gerakon
  • Members
  • 11 posts
  • Last active: Aug 08 2013 04:15 PM
  • Joined: 14 Sep 2010
Does this require the USBUIRT hardware, or will other USB infrared devices work such as
http://www.newegg.co...#scrollFullInfo
or
<!-- m -->http://www.newegg.co... ... -_-Product<!-- m -->

What hardware are you using?

I'm very interested in this as I have been trying to find a way to control my TV from the computer and have found that documentation for the console port on the TV is lacking. This looks like it would make things very simple.

Thanks,
Gerakon

r0lZ
  • Members
  • 192 posts
  • Last active: Feb 11 2012 11:19 PM
  • Joined: 21 Apr 2007
Good question. I have also another hardware: the Microsoft remote sold separately and without model number, but suitable to use with the M$ Media Center. I would like to throw away WinLIRC, but the script given here doesn't seem to do something. The dialog stays blank for ever.

BTW, currently, I use the latest version of WinLIRT (v0.8.7a, that works again with Windows7 x64) and the standard WinLIRT client Ahk script, that requires AutoHotkey_L x32 ANSI version (all other versions do not work under Win7 x64). So, it is a good news that it is possible to use WinLIRT again with a recent version of Windows and/or an x64 processor. Of course, I would prefer an integrated solution, like the one in this thread...
r0lZ

wtg
  • Members
  • 251 posts
  • Last active: Dec 19 2012 03:54 PM
  • Joined: 04 Oct 2006
This library is for the USB-UIRT hardware only, as I understand it.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
@Gerakon
This is a library of the API functions of USBUIRT. It likely won't work with anything else. However if the other hardware manufacturers supply an API for their device you might be able to use this as a map to write a library for your device.

The IR send command would work well for controlling a tv, I use it to control a projector and sometimes a fan.

@r0lZ
USBUIRT does have drivers for Win7 and I believe 64 bit drivers as well. Doesn't AHK work in Win7? I've never looked but I think it does and so should this library.

What script are you trying to run that "Stays blank forever"?

Although the library isn't compatible with either of your receivers USBUIRT will work with those or any IR remote. I use an old iPaq RX3715 running Remote Control ll, this allows me to custom build all my remote pages just how I want them.

You only need specific IR codes if your transmitting IR such as controlling a TV. To receive IR to use as labels in your scripts any code can be used. ie, pick any random code to use as a script label and have the script transmit a specific tv code.

Am I droning on to much? Ok I'll quit now. Feel free to ask more questions.

Edit,
Now that I think about it some other IR receivers use the UIRT protocol. It is possible this library may work with those receivers but I have no idea.

r0lZ
  • Members
  • 192 posts
  • Last active: Feb 11 2012 11:19 PM
  • Joined: 21 Apr 2007
Yes, Ahk work with Win7, even under x64 with 64 bit support with AHK_L_x64, but most DLLCalls must be modified to pass the right arguments types (integers are 64 bit longs).

I've tried several of your scripts, including the two scripts that give information on the device, but the output was blank. Anyway, as I said above, I don't have the right hardware, so it's not surprising.

I really don't know what hardware I have, except that it is sold by Microsoft. There is no brand or model number on the remote. But it works, and I don't want to experiment with other drivers. I'll continue to use WinLIRT for now.

Thanks!
r0lZ

jmsosullivan
  • Members
  • 1 posts
  • Last active: Aug 06 2011 05:58 PM
  • Joined: 28 Jul 2011
Hi,

I'm a complete noob at autohotkey. I have a usb-uirt device and I would love to use AHK to control it.

How exactly do you use the script posted here? It says "Once installed the uuirt.dll should be in C:\WINDOWS\system32\", but what is it that you install? It's just one long text file.

Sorry for being stupid, and thanks for your help.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

Hi,

I'm a complete noob at autohotkey. I have a usb-uirt device and I would love to use AHK to control it.

How exactly do you use the script posted here? It says "Once installed the uuirt.dll should be in C:\WINDOWS\system32", but what is it that you install? It's just one long text file.


I'm referring to the USBUIRT driver. If you already have your USBUIRT installed then there should not be a problem. This script just needs to access it, it will not install the driver for you.

If your having problems figuring out how to use the examples you might try Easy Automation which includes the same functions. Using it you just select what you want to do from drop down list, you don't have to be able to write scripts. Be sure to check "Start With Windows" in the file menu to always have your IR commands available.

Easy Automation is a beta script and still has many bugs but I use it every day with my USBUIRT and that part works fine, just don't try the test function.

I'll be happy to answer any question you have but I travel every weekend and have limited access to check my email so be patient.

wtg
  • Members
  • 251 posts
  • Last active: Dec 19 2012 03:54 PM
  • Joined: 04 Oct 2006
specter333,

Thank you so much for supplying these functions. I've long planned to try and do this myself but never got around to it. Your library allowed me to get my USBUIRT out of the closet and finally put it to good use.

I noticed a few bugs in the USBUIRT_AirCode procedure though:
* The second parameter is Data instead of UserData, which is how it's referred to everywhere else, including the rtncode expression.
* The initial call to VarSetCapacity should have a size of 12 instead of 2048.
* The BatchLines and WinDelay values aren't restored because they are preceded by a return statement. (Actually this error exists in several of the USBUIRT.ahk functions)
* The callback is documented to not have a return value so I removed the rtncode expression and return statement entirely.Here are the corrections:
USBUIRT_AirCode(IrEventStr,[color=red]User[/color]data){
	currentbatch = %A_BatchLines%
	curentwind = %A_WinDelay%
	SetBatchLines -1
	SetWinDelay -1
	VarSetCapacity(IrCode, [color=red]12[/color]) 
	DllCall("lstrcpy", Str, IrCode, UInt, irEventStr) ; Copy the string into the script's variable.
	VarSetCapacity(IrCode, -1) ; Update the variable's internally-stored length to reflect its new contents.
[color=red]	SetBatchLines %currentbatch%
	SetWinDelay %curentwind%
[/color]	If IsLabel(IRcode)  
		GoSub, %IRcode%
	;retcode := NumGet(IRcode,0) "-" Userdata 
	;Return retcode
}
Also, I've restored the BatchLines and WinDelay values before the branch to the user-supplied label. This should prevent the -1 values from causing trouble in the user code.

By the way, have you found that the SetBatchLines and SetWinDelay = -1 commands are absolutely necessary, and if so, wouldn't a Critical or Threads NoTimers accomplish the same without the need to save and restore the default script values? Just curious - I'm not really experienced with any of these commands and wondering out loud.

Finally, I encountered a few things that I haven't seen anyone else mention and I'm curious if this is just unique to my setup or if you or others have had this occur too. I'm using a Harmony remote, setup to send MCE remote codes.

First, I found a number of buttons returns two codes, alternating between button presses. For instance, pressing "Play" will result in one of the two codes 412E97F050F1 and 412E96F040F1, alternating with each new press of the button.

Second, I found a single button press can result in multiple calls to the callback routine so I get undesirable behavior. One "Up" button press might result in 3 calls to the up routine, and thus undesirable behavior. Even though "UP" generates two alternating codes, a single button press always generates multiple calls with only one of the codes. The next button press generates multiple calls with the alternate code. To deal with this I've added a repeat delay to my code - equivalent to how one configures keyboard repeating in Windows - and this solves the problem.

Finally, I have one button, the "Previous Channel" button, that generates multiple calls to USBUIRT_AirCode with different IRCodes with a single press. A single press results in 3 calls to the callback routine with 3 different codes in sequence: 4780000000A5, 4780000000EF, 4780000000AD. The solution for this problem is just to only recognize the last code as a button press and ignore the first 2.

In anyone's interested I'll post my code for configuring repeat button presses, and I've also modified USBUIRT_ReceiveIR() to accept an optional callback procedure that gets called with every button press after USBUIRT_AirCode has processed it. This allows the dll calls in the library to remain encapsulated, and gives the user the option of a single procedure that handles their button presses or a label/subroutine for specific buttons.

Anyway, thanks again for making this library available.