AutoHotkey Community

It is currently May 27th, 2012, 5:22 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 27th, 2011, 7:22 am 
Offline

Joined: January 15th, 2007, 2:37 pm
Posts: 573
USB-UIRT Function Library
Direct Infrared Remote Control with AHK
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.autohotkey.com/forum/viewtopic.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.
http://www.autohotkey.net/~specter333/USB-UIRT/USBUIRT.ahk

Edited to save the script's batchline and windelay settings and restore them when each function completes.
Second Edit, Removed the temporary work around in the USBUIRT_ReceiveIR() function.
Edit 1-30-11, Fixed error in learn function.

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 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 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.

If anyone can assist in getting these three 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.


Last edited by specter333 on January 30th, 2011, 11:16 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2011, 10:40 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Looks promising! Thanks for sharing!

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2011, 12:55 am 
Offline

Joined: July 30th, 2007, 11:32 pm
Posts: 581
Nice! I'll test it later.
Did this allow you to catch that ever-elusive Power button on your remote?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2011, 3:27 am 
Offline

Joined: January 15th, 2007, 2:37 pm
Posts: 573
TheGood wrote:
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2011, 1:43 pm 
Offline

Joined: October 4th, 2006, 2:15 am
Posts: 250
Location: Louisville, KY
Looking forward to trying this out... of course I have to work this weekend! :x

Thanks again for all your hard work!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2011, 11:31 pm 
Offline

Joined: April 21st, 2007, 9:16 pm
Posts: 178
Does it work under X64 systems? (Windows 7)

_________________
r0lZ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2011, 6:34 am 
Offline

Joined: January 15th, 2007, 2:37 pm
Posts: 573
r0lZ wrote:
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.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 8th, 2011, 4:14 pm 
Offline

Joined: September 14th, 2010, 8:47 pm
Posts: 11
Does this require the USBUIRT hardware, or will other USB infrared devices work such as
http://www.newegg.com/Product/Product.aspx?Item=12-200-172&SortField=0&SummaryType=0&PageSize=100&SelectedRating=-1&VideoOnlyMark=False&IsFeedbackTab=true#scrollFullInfo
or
http://www.newegg.com/Product/Product.a ... -_-Product

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2011, 5:38 pm 
Offline

Joined: April 21st, 2007, 9:16 pm
Posts: 178
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2011, 5:39 pm 
Offline

Joined: October 4th, 2006, 2:15 am
Posts: 250
Location: Louisville, KY
This library is for the USB-UIRT hardware only, as I understand it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2011, 11:06 am 
Offline

Joined: January 15th, 2007, 2:37 pm
Posts: 573
@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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 9th, 2011, 11:17 am 
Offline

Joined: April 21st, 2007, 9:16 pm
Posts: 178
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2011, 11:48 pm 
Offline

Joined: July 28th, 2011, 11:44 pm
Posts: 1
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 29th, 2011, 2:53 pm 
Offline

Joined: January 15th, 2007, 2:37 pm
Posts: 573
jmsosullivan wrote:
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 7th, 2011, 5:43 pm 
Offline

Joined: October 4th, 2006, 2:15 am
Posts: 250
Location: Louisville, KY
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:
Code:
USBUIRT_AirCode(IrEventStr,Userdata){
   currentbatch = %A_BatchLines%
   curentwind = %A_WinDelay%
   SetBatchLines -1
   SetWinDelay -1
   VarSetCapacity(IrCode, 12)
   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.
   SetBatchLines %currentbatch%
   SetWinDelay %curentwind%
   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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: nomissenrojb and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group