PDA

View Full Version : String from window to command



CSGilks
January 27th, 2006, 06:32 AM
First, thank you to the very supportive and responsive people who monitor this forum.

I have NetRemote working well with an Ipaq, HSGirder and Homeseer running on a PC and a Global Cache box, controlling 20+ X10 devices and 11 infrared boxes in three rooms, all for a quadraplegic.

What I need now is some advice on how to get started (or even if it is possible) on the following:

As I said, the system is for a quadraplegic. One of the infrared devices that is now controlled from NR is a hands-free phone controlled using infrared. What I would like to do is close the gap between the Contacts list in the IPAQ and the phone control in NR, to allow a stored number to be dialed from the phone fairly automatically. Now the question:

Is there a way to create a window in NR, to be able to paste a string (a phone number in this case) into it and then get NR to parse the numeric part of the string from the window and generate one command for each numeric character (in this case, infrared commands to Global Cache)? I'm not sure if this is even possible, and have no idea how to start - researching Lua, the NRBasic plug-in or what? Any examples of something related, help or guidance would be very much appeciated. Apologies in advance if I'm wasting your time, and again thanks for a very useful product and support team

Rob H
January 27th, 2006, 07:10 AM
That all sounds doable to me at least with the latest beta of NR 1.5

You'll need some Lua certainly, but it should be fairly straightforward.

CSGilks
January 27th, 2006, 11:14 AM
Thanks for letting me know that I am not completely out of line.

To get me started, can I ask the specific question then:
1. is there an example anywhere of creating a window in NR and assigning the contents to a string variable?

OK, I know that I am struggling and showing my complete ignorance but I am genuinely looking for somewhere to start. I just cannot get a handle from the help files and have really basic question, for example, do I try and create a button or a frame on the page that I want the window to be on, or with some kind of entry script to the page?

By the way, I have done a lot of programming and scripting in the past, but in Basic and HS scripts.

It's very hard to get a handle on this stuff in NR, and I cannot seem to be able to find examples on the Proximis site, and can't seem to figure out how to put together a search string in Google to get me to some examples. Even a couple of suggested Lua commands would really help (and some idea of where they would go and what would call them)!!

Rob H
January 27th, 2006, 11:39 AM
Okay, you need to be using NR Designer first of all, it really makes things easier.

Put a button on a page, and in the action designer drop an AvidUtils|Text String and type in the name of the variable you want to use (e.g. PhoneNumber). Don't check any of the checkboxes.

In your CCF's .lua file (right click on System in the tree and select 'Edit Lua script file'. Add the following code :-



function phoneFunc(variable, value)
for num in string.gfind(value, '%d') do
dialdigit(num)
end
end

function OnCCFLoad()
RegisterVariableWatch('PhoneNumber', phoneFunc)
end



Now all that is needed is to implement the function dialdigit()

Rob H
January 27th, 2006, 12:02 PM
Currently, GetElementByName() can only find elements on the current page so you'd need to put the buttons that control the phone there

dialdigit would then look something like this :-


function dialdigit(num)
local digitName = 'DIGIT'..num
local btn = NetRemote.GetElementByName(digitName)
if btn then
btn:ButtonDown(true) -- if we pass true here then it will show the buttons being pressed
end
end

Please bear in mind that none of this code is tested.

CSGilks
January 27th, 2006, 12:03 PM
Thanks, Rob, that was exactly what I neede to get me off the ground. And I am using NetRemote Designer - well worth the price, by the way.

It's something that I've found in, for example, scripting in Microsoft Office as well as in Homeseer scripting, you have to have somewhere to start otherwise you can have absolutely no idea what to look for in the help files, even if you have some knowledge of what to do and how to do it - Proximis seems to have at least one in thing in common with Microsoft (just joking, sort of!) - a lack of real starting points for somebody who, like me, only uses this stuff once in a while when you really need to do something - a few well-worked examples, properly indexed, are worth an encyclopaedia's worth of help files!

CSGilks
January 27th, 2006, 04:00 PM
Ok, Rob,
In spite of your excellent help so far, I'm still struggling a bit here, and have not yet been able to get your example working (nothing at all happening when a number is pasted into the text input button). Some specific questions:

1. I can't quite figure out whether the 10 digit button elements on the page containing the text input button should be simply named "1" through "0" or "DIGIT1" through "DIGIT0", or even possibly "DIGIT 1" through "DIGIT 0"?

2. I am seeing no action at all on the buttons. Can you tell me what I could insert into functions to debug print the value of the variable PhoneNumber?

3. I gather from your suggested solution that the function dialdigit should be called when the variable simply changes at any time? If somebody typed a number into the text button one digit at a time, would the whole number be parsed each time a new digit was typed in?

I'm really looking forward to getting this solution working as it looks really neat so far. One probable modification that I will make (depending on the answer to 3 above), is a "Dial" button on the page to call dialdigit by the user rather than have it called on a data change - allow a user to modify a number if necessary before it is dialed.

Sorry to continue dense, but thanks in advance for any more help that you can give. I'm not sure if I should be grateful for starting to get exposed to the Lua help files that you have given me an entry into - fine and dandy for an experienced user, no doubt, but in my case where are the EXAMPLES for the complete tyro!?!?!? Must be my age showing!

Rob H
January 27th, 2006, 05:20 PM
Ok, Rob,
1. I can't quite figure out whether the 10 digit button elements on the page containing the text input button should be simply named "1" through "0" or "DIGIT1" through "DIGIT0", or even possibly "DIGIT 1" through "DIGIT 0"?

They should be called DIGIT0 to DIGIT9


2. I am seeing no action at all on the buttons. Can you tell me what I could insert into functions to debug print the value of the variable PhoneNumber?

Yes, you should only need to use print(PhoneNumber) - if you're testing this on Win32 then you should download DebugView from www.sysinternals.com to see the output from the print function


3. I gather from your suggested solution that the function dialdigit should be called when the variable simply changes at any time? If somebody typed a number into the text button one digit at a time, would the whole number be parsed each time a new digit was typed in?

That is certainly likely


I'm really looking forward to getting this solution working as it looks really neat so far. One probable modification that I will make (depending on the answer to 3 above), is a "Dial" button on the page to call dialdigit by the user rather than have it called on a data change - allow a user to modify a number if necessary before it is dialed.

That's the way I would do it to be perfectly honest.

CSGilks
January 28th, 2006, 05:42 AM
Rob, thanks again.
The debug function works like a dream, thank you for that. Also now I can see the correlation between the element name and the link in the scripting.

Please bear with me. I can find no reference to the statement elementID:ButtonDown(True) in the help documentation, or find a reference to ButtonDown on the Proximis site.

When I run your original version of the Lua script, using DebugView, I can see the correct element name passed to the dialdigit function, but nothing happens and the log shows what is apparently an error:

. . . file ref . . . :17: attempt to index local 'btn' (a user data value)

generated apparently when the function reaches the DIGIT1:ButtonDown(True) statement. Any help on what is going on would be appreciated.

Rob H
January 28th, 2006, 06:04 AM
This only works with version 1.5 (beta) of NetRemote - is that the version you are using?

If so then please post your CCF's .lua file here so that I can see just what's in there.

CSGilks
January 28th, 2006, 07:40 AM
THanks for the prompt response. I am using a legit, registered copy of NetRemote Pro+IR 1.1.0.44.

Can I just overwrite this with the Beta version? And, OK, where do I find the Beta version that you are referring to on the Proximis site? I really am feeling like the proverbial Mancunian idiot here!

Lua script below from the CCF, for future reference and to save time if necessary later:

function phoneFunc(variable, value)
for num in string.gfind(value, '%d') do
dialdigit(num)
end
end

function OnCCFLoad()
RegisterVariableWatch('PhoneNumber', phoneFunc)
end

function dialdigit(num)
local digitName = 'DIGIT'..num
local btn = NetRemote.GetElementByName(digitName)
print(PhoneNumber)
print(digitName)
-- if btn then
btn:ButtonDown(true) -- if we pass true here then it will show the buttons being pressed
-- end
end


And the compiled action from the text button:

0;PhoneNumber

Rob H
January 28th, 2006, 07:47 AM
http://www.promixis.com/phpBB2/viewtopic.php?p=135158#135158 for the link to download the beta.

I'd hesitate to recommend overwriting your existing installation, but if everything is backed up it shouldn't really be a major problem.

CSGilks
January 28th, 2006, 08:34 AM
Hi, again,
Thanks, Rob, I did find the Beta, loaded it and now the buttons do work from the script as advertised.

The big snag is that I lost all the text on the buttons. All my text is Tonto 6pt - I'm not sure but it looks as though the Beta version of NetRemote is not handling display of the 6pt text, and probably displaying at a high point number?

I hope that somebody can look into this and that a fix will be forthcoming in the near future (do I need to post this bug elsewhere?).

I'm going to continue to work on a version of the phone dialer using the NR Beta version and hope that the text bug gets fixed. Thanks again for all your help - it's great to now be able to get into the scripting in NR - like Homeseer, it looks as if the NR scripting really is where the jam gets put on the bread and butter!

Rob H
January 28th, 2006, 08:36 AM
Bug reports related to the beta version currently seem to go in the thread where you downloaded the beta from.

CSGilks
January 29th, 2006, 04:54 AM
Just to complete the circle, I'm attaching a CCF of the phone dialer that works from a button after pasting or typing the number. It only works with the Beta version of NetRemote because of the ButtonDown/ButtonUp commands.

This leads me to another question - because of the above-mentioned text display bug in the 1.5 Beta, I cannot use it til the bug is fixed. I was trying to work out how to send infrared commands directly from Lua (as opposed to activating a button containing the IR command as in the attached file). I believe that it would be done using the NetRemote.ExecuteAction([pluginid], [actionid1], [actionid2], [params], [callno]) command, but I cannot get this working, and I am not sure what I am doing wrong. Is this the right command? And, if so, could you give me an example of how the command would actually appear in the script (to send a command to the -3 IR instance)?

Thank you for all the help that I have had so far to get me started. It is very much appreciated

Rob H
January 29th, 2006, 05:08 AM
At present there is no other way to send IR from Lua I'm afraid.

Rob H
January 29th, 2006, 05:37 AM
Actually, I'm not 100% sure that is the case if you have a GlobalCaché

CSGilks
January 29th, 2006, 05:58 AM
Yes, I am using Global Cache devices. Some hope, then?

Rob H
January 29th, 2006, 07:40 AM
I was thinking that this would be possible using GIP, but that requires 1.5 beta anyway and would be more complex.

Other than that I believe you could do it with NR 1.1 if you're using Girder 4. But I think those are your only options.

CSGilks
January 29th, 2006, 07:46 AM
I'm using Homeseer with HSGirder. I did try early on to use the Touchpad interface on HS2.0, but ran into too many roadblocks with the interface, so switched to NR. You've started me thinking - can you give me a sample line showing how a lua command sends something via the Girder plug-in to Girder? HSGirder directly calls an HS script with parameters (I'm already using that route for X10 control), and I could use the same route to generate IR commands - bit complex and round the houses, but certainly workable, and I have no idea when NR1.5 will be available for use

Rob H
January 29th, 2006, 07:51 AM
I think Ben has said that he's planning on uploading a new beta fairly soon (today or tomorrow).

But - you'd use NetRemote.ExecuteAction(-1, 0, 1, GirderCommand) where GirderCommand is the string to be sent to Girder as an event string. If you need to pass a parameter then you can put it in parentheses. The -1 there is the plugin instance of the default Girder plugin. If you're hsGirder plugin is using a different instance number then use that instead.

CSGilks
February 13th, 2006, 10:45 AM
I got a lot further down the road with this, in sending an HSGirder command from the lua script, but then ran into the following problem with the script function that was activated by HSGirder in Homeseer. I wonder if anybody on this board has seen this problem or something similar to it? I've been playing with different ways around it, but cannot seem to manage to get an IR command to the Global Cache device originating from an HSCirder script function, no matter how I try it (delays, activating events that generate the command, memory bits in HS, whatever - still locks up the GC unit and leaves the HGirder script hanging). I have had it posted on the Homeseer board for a few days, but no responses from there:

I am trying to get an IR command originating from a lua script in an NR client through to a Global Cache device using HSGirder. Can anyone tell me why, whether I use a simple HS script IR command, for example, hs.SendIR "VCR,A", or use the command sequence Set GC = hs.Plugin("Global Cache GC100") and then GC.PlayIR(98) it just plain does not work in a script function called using NR/HSGirder?

Either method works fine in a script sub called directly from an HS event, but when I use either of the above command sequences in the function called by HSGirder or even in a separate script sub that is "Run" from the HSGirder function, Homeseer reports on the log screen that the one or all called scripts continue to run indefintiely and nothing happens on the GC device. The GC device then seems to lock-up and can only be got working from HS again by restarting HS.

I can only assume that there is a problem calling one plugin while another is running a script, or something along those lines, but I really do not see why?

Ben S
February 14th, 2006, 12:42 PM
Are you saying there is problems in the HS side or in the NR side? It sounds like you are saying "a problem once HS gets ahold of it".

Perhaps one of the other HS users (jwilson, perhaps) can ring it here if this _is_ the case.

CSGilks
February 15th, 2006, 04:40 AM
Yes, you are probably right in saying that it appears to be a Homeseer scripting problem (or finger-trouble using same) of some kind, or at least a problem related to the Global Cache device being controlled from two sources (Homeseer and NetRemote). The problem dies seem to involve the interraction of Homeseer with NetRemote and HSGirder when the Global Cache device is the common method for delivering infrared commands.

I cannot be sure, but this may be the first time that somebody has tried to use Homeseer to send an infrared command that originated from NetRemote and HSGirder to a Global Cache device, rather than just sending the command directly to the Global Cache device from a button in NetRemote.

The problem is easily reproducible - when I simply add an IR command (hs.SendIR "VCR,A", to be specific, which works fine when called from a Homeseer event) into the HSGirder script that I use all the time to control X10 devices and never gives problems, the script just hangs and no other infrared commands (or even NR/HSGirder/X10 commands) work, oroginating either from Homeseer or from NetRemote, until Homeseer is restarted.

To be clear, I would not be trying to do this if the ButtonDown and ButtonUp lua commands were available in a released version of NetRemote. It looks as if I will just have to give up trying to get a phone autodilaer to work until the NR 1.5Beta version gets released. Ah, well, time to leave you guys alone, perhaps!