Author Topic: TCP Plugin result not available to next command in same action  (Read 5030 times)

0 Members and 3 Guests are viewing this topic.

hpooni

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 0
    • View Profile
TCP Plugin result not available to next command in same action
« on: January 17, 2014, 09:12:39 AM »
I'm trying to implement mute toggle for Denon via IP control.  Unfortunately Denon does not have command to directly toggle mute so you must obtain the current mute status and then send the discrete (MUON/MUOFF) command.
I would like to do all this under one action.  Unfortunately, when I attempt to fetch the mute status using TCP.WriteLn the result is not available in {LastResult} or {1} until the action has completed all commands within the respective action.
Is there any way around this as I would like to avoid multiple actions to perform one function.
Thanks

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #1 on: January 17, 2014, 09:34:28 AM »
Let us see what you've got so far.

Does the receiver send out events, or some update messages when the volume  or mute status changes?

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #2 on: January 17, 2014, 09:41:11 AM »
Hi hpooni,

If you're not yet sure how to post the XML for your command, see: http://voxcommando.com/mediawiki/index.php?title=XML_on_the_forum#Posting_Your_Code_to_the_Forum

thx
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

hpooni

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 0
    • View Profile
Re: TCP Plugin result not available to next command in same action
« Reply #3 on: January 17, 2014, 12:05:15 PM »
Following contains the connection to my denon receiver.
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<!--C:\Utils\voxcommando\export\VcGrp_TCP Connections.xml-->
<VoiceCommands version="">
    <!--this is an exported VoxCommando group-->
    <commandGroup open="True" name="TCP Connections" enabled="True" prefix="" priority="0" requiredProcess="" description="">
        <command id="742" name="TCP iTachFlex Client" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>TCP.Client.Connect</cmdType>
                <cmdString>iTachFlex&amp;&amp;192.168.0.21&amp;&amp;4998</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <event>VC.Loaded</event>
        </command>
        <command id="748" name="TCP FamilyroomAVR Client" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>TCP.Client.Connect</cmdType>
                <cmdString>DenonAVR{M:Rooms.Familyroom}&amp;&amp;192.168.0.28&amp;&amp;23</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <event>VC.Loaded</event>
        </command>
    </commandGroup>
</VoiceCommands>

Following contains a simple mute status action with result popup.
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<!--C:\Utils\voxcommando\export\VcGrp_Denon.xml-->
<VoiceCommands version="">
    <!--this is an exported VoxCommando group-->
    <commandGroup open="True" name="Denon" enabled="True" prefix="" priority="0" requiredProcess="" description="">
        <command id="343" name="DenonMuteStatus" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
            <action>
                <cmdType>Tcp.Client.WriteLn</cmdType>
                <cmdString>DenonAVR1&amp;&amp;MU?</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>Results.SetVar</cmdType>
                <cmdString>DenonAVRMuteStatus1</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
            <action>
                <cmdType>OSD.ShowText</cmdType>
                <cmdString>{Var.DenonAVRMuteStatus1}</cmdString>
                <cmdRepeat>1</cmdRepeat>
            </action>
        </command>
    </commandGroup>
</VoiceCommands>

The denon receiver definitely returns data as 'DenonAVR1' event gets logged in the history window with the expected response containing '{1} MUOFF\x0D'

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #4 on: January 17, 2014, 01:45:42 PM »
If you're not yet sure how to post the XML for your command, see: http://voxcommando.com/mediawiki/index.php?title=XML_on_the_forum#Posting_Your_Code_to_the_Forum

I guess you didn't see this post?

You just need to copy and paste groups from the tree to the forum.  It looks like you exported a group, then edited it and copied from there into the forum.  This is not only more work for you, it won't work for us when someone tries to copy and paste back to our trees.  If you choose to export a group as a file then you should attach that file to your post, rather than copying the xml from it.
« Last Edit: January 17, 2014, 01:53:23 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #5 on: January 17, 2014, 02:05:55 PM »
It may be possible for me to modify the plugin to include a new action that queries for a value and then waits a set amount of time for a response which gets stored into LastResult.  At the moment it is not possible and I can't say when I will get around to it, so it will be better if we can find a solution using the current plugin available.

Your Denon is responding with the information you want using an event when you query it for the volume, which is good.  I was wondering if the Denon also generates that event whenever the mute status changes.  In other words, after you have connected to it with the TCP client action, if you change the mute status on the Denon by some other means, such as a remote control, does it send an event without being asked?  Probably not, but if it does it would make our lives a bit easier.

With the current event that you get back you need to have a command that responds to the event and stores the payload in a variable, or does some kind of logic based on the payload.

If I have done it properly, this command should display your response from the Denon.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="355" name="denon mute event" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{1}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>DenonAVR1</event>
</command>

I may try to create a similar solution for my Onkyo, and then you can just modify the protocol a bit to make it work with yours.

I'm not too sure why you need a toggle action.  Usually the problm people face is that they only have toggle and they need a way to perform discrete mute on/off.

hpooni

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 0
    • View Profile
Re: TCP Plugin result not available to next command in same action
« Reply #6 on: January 17, 2014, 03:35:12 PM »
My bad about the incorrect code pasting.  Will remember for next time.

It may be possible for me to modify the plugin to include a new action that queries for a value and then waits a set amount of time for a response which gets stored into LastResult.  At the moment it is not possible and I can't say when I will get around to it, so it will be better if we can find a solution using the current plugin available.
I think this pretty much answers my question.  I will implement a second action which resonds to the event generated by the mute status action, as you've suggested below.

Your Denon is responding with the information you want using an event when you query it for the volume, which is good.  I was wondering if the Denon also generates that event whenever the mute status changes.  In other words, after you have connected to it with the TCP client action, if you change the mute status on the Denon by some other means, such as a remote control, does it send an event without being asked?  Probably not, but if it does it would make our lives a bit easier.
It actually does generate events for remote key presses and you're right I could use that as trigger to toggle the mute but I was hoping to do the whole thing as one complete package.

With the current event that you get back you need to have a command that responds to the event and stores the payload in a variable, or does some kind of logic based on the payload.
Correct.

If I have done it properly, this command should display your response from the Denon.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="355" name="denon mute event" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{1}</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>DenonAVR1</event>
</command>

I may try to create a similar solution for my Onkyo, and then you can just modify the protocol a bit to make it work with yours.
Correct. I had already done this and it works but as I stated before I was hoping to do everything within one action.

I'm not too sure why you need a toggle action.  Usually the problm people face is that they only have toggle and they need a way to perform discrete mute on/off.
Mainly for hard-button remote.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #7 on: January 17, 2014, 04:07:04 PM »
It actually does generate events for remote key presses and you're right I could use that as trigger to toggle the mute but I was hoping to do the whole thing as one complete package.
Correct. I had already done this and it works but as I stated before I was hoping to do everything within one action.
I think you mean one command, not one action.  But my point is that you can store information that comes from the Denon as it is delivered and then it is ready for you whenever you need it.  When you want to toggle the mute (for whatever reason ;)) you can do it all in one command very quickly without having to ask the Denon for the mute status because it will already be stored in a variable.  The same would be true if you needed to know the volume for some reason.  If I were going to write a custom plugin for the Denon, this is exactly how I would do it anyway.  You just need to do some results.regex on the command that receives the DenonAVR1 event, so you can decide what to store, in which variable.

Mainly for hard-button remote.
I still don't understand.  It's OK.  I don't need to.
« Last Edit: January 17, 2014, 04:40:38 PM by jitterjames »

hpooni

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 0
    • View Profile
Re: TCP Plugin result not available to next command in same action
« Reply #8 on: January 17, 2014, 04:52:28 PM »
Ok I will experiment a bit and see if I can implement your suggestions.
Thanks for your help.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #9 on: January 17, 2014, 05:31:23 PM »
If you need help with the regex for the returned values let me know.  I will need to see what kind of different messages you get from the Denon for volume, mute, and anything else that you think would be relevant.

hpooni

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 0
    • View Profile
Re: TCP Plugin result not available to next command in same action
« Reply #10 on: January 20, 2014, 02:30:21 PM »
If you need help with the regex for the returned values let me know.  I will need to see what kind of different messages you get from the Denon for volume, mute, and anything else that you think would be relevant.
Thanks.  I'm actually trying to use the PY plugin and pass {1} and {LastEvent} as parameters to the python script file.
The action is PY.ExecFile C:\Utils\voxcommando\data\DenonStatus.py {1} {LastEvent}
The above is triggered successfully by DenonAVR1 event and following is captured in the history window.
PY.ExecFile:C:\Utils\voxcommando\data\DenonStatus.py&&MUOFF\x0D&&DenonAVR1

My question is, how do I retrieve the {1} and {LastEvent} values inside the script so I can process them?  FYI, I'm using PY instead of regex directly as its more flexible and I may do some other processing in the script.

Thank again for your help.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #11 on: January 20, 2014, 02:42:59 PM »
It is fine to use python but you can certainly do what you want without it.

You are adding the data in the parameter where the filename is supposed to go, so that won't work.

You need to define a function in your file and load that file once using PY.ExecFile once (usually done using the VC.Loaded event) and then you send the data in a call to the function.

You can call the function and pass it parameters like this:

PY.ExecString  myFunction({1},{LastEvent})

If you need specific help with this still, please post your code.  P.S. version 2 of VC will allow you to get a response from the server in a new action Tcp.Client.Query

hpooni

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 0
    • View Profile
Re: TCP Plugin result not available to next command in same action
« Reply #12 on: January 20, 2014, 03:01:23 PM »
It is fine to use python but you can certainly do what you want without it.
You're probably right but I like python and need the practice :)

You are adding the data in the parameter where the filename is supposed to go, so that won't work.

You need to define a function in your file and load that file once using PY.ExecFile once (usually done using the VC.Loaded event) and then you send the data in a call to the function.

You can call the function and pass it parameters like this:

PY.ExecString  myFunction({1},{LastEvent})
Yeah I read this in the documentation but wasn't sure if I could pass parameters directly to the script file.  I will implement using a function.

If you need specific help with this still, please post your code.  P.S. version 2 of VC will allow you to get a response from the server in a new action Tcp.Client.Query
Thanks.  I look forward to V2.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: TCP Plugin result not available to next command in same action
« Reply #13 on: January 20, 2014, 03:12:08 PM »
it is much better to define a function anyway.

Here is a little light reading that might help ;)

http://voxcommando.com/forum/index.php?topic=1301.0

hpooni

  • $upporter
  • Jr. Member
  • *****
  • Posts: 27
  • Karma: 0
    • View Profile
Re: TCP Plugin result not available to next command in same action
« Reply #14 on: January 20, 2014, 04:24:01 PM »
Agreed, using functions is a better approach.
Thanks for the reference material.  Works well now. 8)