Author Topic: Help with looping  (Read 1343 times)

0 Members and 2 Guests are viewing this topic.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Help with looping
« on: July 29, 2014, 06:12:06 PM »

I am working on LAN Scanner ... basically it builds an xml of device name and IP... it has few applications, including pinging devices with dynamic IP to figure if they are on or of ... 
work is based  on: this thread http://voxcommando.com/forum/index.php?topic=1561.0
 and this thread http://voxcommando.com/forum/index.php?topic=1301.msg11240#msg11240

however for some reason that I can't figure the loop is not working, any insights will be great.

one more question ... is there is a way to make {i} starts from number other than one ?


Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.3-->
<command id="450" name="LAN Scanner" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="True" loopDelay="5" loopMax="255" description="">
  <action>
    <cmdType>OSD.showText</cmdType>
    <params>
      <param>LAN Scanner</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>NetPrefix</param>
      <param>192.168.5</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Launch.Capture</cmdType>
    <params>
      <param>C:\Windows\System32\ping.exe</param>
      <param>-a {Var.NetPrefix}.{i}</param>
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param>Sent.*?(\d+).*Received.*?(\d+).*Lost.*?(\d+).*?(\d+).*Minimum.*?(\d+).*Maximum.*?(\d+).*Average.*?(\d+)</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{Match.1.3}&amp;&amp;0</ifParams>
    <then>
      <action>
        <cmdType>Results.RegExSingle</cmdType>
        <params>
          <param>Pinging\s(.*)\..*\s\[</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>PayloadXML.AddPair</cmdType>
        <params>
          <param>C:\Extensions\Vox Commando\payloads\Network_IP_Table.xml</param>
          <param>{Var.NetPrefix}.{i}</param>
          <param>{Match.1.1}</param>
          <param>false</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.addText</cmdType>
        <params>
          <param>Device {Match.1.1} added with IP {Var.NetPrefix}.{i}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>OSD.addText</cmdType>
        <params>
          <param>no device found on {Var.NetPrefix}.{i}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <event>LAN.Scan</event>
</command>
When Voice command gets tough, use hand gestures

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Help with looping
« Reply #1 on: July 30, 2014, 09:14:42 AM »
It's amazing what people do around here "just for fun".  :biglaugh

The main issue you're having is a misunderstanding of {i}. {i} refers to the number of iterations of a repeated *action*. It has no relationship to command-level looping.

Command looping was originally created for doing things like scrolling through lists. It doesn't keep track of the number of times that it's been allowed to loop. If you want, you can create your own variable and increment it. But sadly, that will require the much-maligned Python.

This is not really a job well-suited for the macro builder. It can be done much more easily and efficiently using Python. But if, for fun, you want to figure out ways to do this in the macro builder, we would do something like this:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.3-->
<commandGroup open="True" name="crazy loops" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="288" name="initiate pings" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>LAN scanner</param>
        <param>5000</param>
        <param>-10</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>VC.TriggerEvent</cmdType>
      <params>
        <param>crazyPing</param>
        <param>{i}</param>
      </params>
      <cmdRepeat>255</cmdRepeat>
    </action>
    <phrase>initiate pings</phrase>
  </command>
  <command id="464" name="crazyPing" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="5" loopMax="255" description="This stops the looping at 100 -- so, it runs for IP addresses in the range 192.168.5.255 to .100">
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)&lt;(B)</ifType>
      <ifParams>{1}&amp;&amp;100</ifParams>
      <then>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>IPaddress</param>
        <param>192.168.5.{1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Launch.Capture</cmdType>
      <params>
        <param>C:\Windows\System32\ping.exe</param>
        <param>-a {Var.IPaddress} -n 1 -w 500</param>
        <param>True</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>Lost.*?(\d+)</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)==(B)</ifType>
      <ifParams>{Match.1.1}&amp;&amp;0</ifParams>
      <then>
        <action>
          <cmdType>Results.RegEx</cmdType>
          <params>
            <param>Pinging\s(.*?)(.lan)*(\swith|\s\[)</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>PayloadXML.AddPair</cmdType>
          <params>
            <param>payloads\Network_IP_Table.xml</param>
            <param>{Var.IPaddress}</param>
            <param>{Match.1.1}</param>
            <param>false</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.addText</cmdType>
          <params>
            <param>Device {Match.1.1} added with IP {Var.IPaddress}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>OSD.addText</cmdType>
          <params>
            <param>no device found on {Var.IPaddress}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>crazyPing</event>
  </command>
</commandGroup>
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)