找回密码
 加入
搜索
查看: 4265|回复: 10

[AU3基础] 【求助】input参数转换为int树枝,用于sleep中的问题

  [复制链接]
发表于 2012-9-10 13:51:32 | 显示全部楼层 |阅读模式
本帖最后由 小熵 于 2012-9-10 16:56 编辑

求助,为什么Sleep ($wait_tim")没有起到延迟的作用,这种参数应该怎么弄呢?
谢谢
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=d:\my_document\olt reboot onu.kxf
$Form1_1 = GUICreate("OLT重启ONU压力测试", 227, 204, 492, 224)



$Label1 = GUICtrlCreateLabel("重启次数", 40, 18, 52, 17)
$re_num = GUICtrlCreateInput("250", 96, 16, 97, 21)

$Label2 = GUICtrlCreateLabel("等待时间", 40, 54, 52, 17)
$wait_time = GUICtrlCreateInput("250", 96, 48, 97, 21)

$Label3 = GUICtrlCreateLabel("OLT地址", 40, 90, 43, 17)
$OLT_ip = GUICtrlCreateInput("127.0.0.1", 96, 88, 97, 21)
$Label4 = GUICtrlCreateLabel("Slot", 51, 122, 22, 17)
$slot = GUICtrlCreateInput("12", 96, 120, 25, 21)
$Label5 = GUICtrlCreateLabel("Link", 132, 122, 24, 17)
$link = GUICtrlCreateInput("4", 168, 120, 25, 21)
$OK = GUICtrlCreateButton("开始测试", 48, 152, 69, 25)
$Cancel = GUICtrlCreateButton("取  消", 120, 152, 69, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Cancel
                        Exit
                Case $OK
                        
                        $s=ping(GUICtrlRead($OLT_ip),200)
                                if $s Then
                                        $re_num = GUICtrlRead($re_num,0)
                                        $wait_time = GUICtrlRead($wait_time,0)
                                        $sleep_time = Int($wait_time)
                                        For $i=1 To $re_num
                                        run("telnet " & GUICtrlRead($OLT_ip))
                                        WinActivate("Telnet","")
                                        Sleep (300)
                                        Send ("y")
                                        Send ("{enter}")
                                        Sleep (300)
                                        Send ("dir") 
                                        Send ("{enter}")
                                        Sleep (1000)
                                        Send ("exit") 
                                        Send ("{enter}")
                                        Send ("{enter}")
                                        MsgBox (0,"TestCenter打流进行中","TestCenter正在打流,打流结束后继续下一次重启测试",5)
                                        Sleep ($sleep_time)
                                        Next
                                Else
                                        MsgBox(1,"OLT状态","OLT连接不通")
                                EndIf
                                Exit
                EndSwitch
        
WEnd
发表于 2012-9-10 14:22:44 | 显示全部楼层
本帖最后由 xiehuahere 于 2012-9-10 14:29 编辑

回复 1# 小熵


取出来是字符串格式的
改为 Sleep(Int($wait_time)) 试试

$wait_time 即表示控件ID,又表示数值,容易搞混,建议你换个变量名。

此外,telnet用这种send的方式比较难看,其实用 TCP 相关函数可以做的,先连接到23端口(telnet端口),然后用 TCPSend 发送命令即可,这样可以做到后台运行。
论坛有相关代码,搜索一下。
发表于 2012-9-10 14:28:54 | 显示全部楼层
13行17行,移动到31行位置 ,同一程序中不要用同样的变量名,12、13行,16、17行
发表于 2012-9-10 14:34:33 | 显示全部楼层
哈哈,我也来学习了。
发表于 2012-9-10 14:34:58 | 显示全部楼层
pcbar很利害,哈哈
 楼主| 发表于 2012-9-10 16:01:03 | 显示全部楼层
不厉害能做版主么....受教了..
 楼主| 发表于 2012-9-10 16:07:11 | 显示全部楼层
回复 2# xiehuahere


    改为改为 Sleep(Int($wait_time)) 还是不行
 楼主| 发表于 2012-9-10 16:11:02 | 显示全部楼层
本帖最后由 小熵 于 2012-9-10 16:12 编辑

回复 3# pcbar

       
    说实话,我没有看懂版主的意思,13行跟17行为什么移动到第31行位置呢?
    我只写过很简单的bat和vbs,对autoit还不太了解,跟更没用过GUI.
    其实我是想把下面的vbs脚本用AUTOIT写一遍的
    目的是每隔一定的时间telnet到某个服务器上执行一些命令
on error resume  next
dim n,sleep_time,ip,slot,link,ip1,ip2

num=inputbox("请输入OLT重启ONU的次数")
If IsEmpty(num) Then 
    wscript.quit
end if
num=num*1

do  while (num<1 or num>500)
num=num*1
if num < 1 then
  num=inputbox("重启次数不能小于0,请重新输入OLT重启ONU的次数")
      If IsEmpty(num) Then 
          wscript.quit
      end if
end if
if num > 500 then
         num=inputbox("重启次数不能大于500,请重新输入OLT重启ONU的次数")
              If IsEmpty(num) Then 
                  wscript.quit
              end if
end if
num=num*1
loop

sleep_time=inputbox("请输入重启间隔时间,以秒为单位")
 if sleep_time="" then
     sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  

do  while (sleep_time<1 or sleep_time>500)
sleep_time=sleep_time*1
if sleep_time < 1 then
  sleep_time=inputbox("重启间隔时间不能小于0,请重新输入重启间隔时间,以秒为单位")
      If IsEmpty(sleep_time) Then 
          wscript.quit
      end if
end if
if sleep_time > 500 then
      sleep_time=inputbox("重启等待时间不能大于500,请重新输入重启间隔时间,以秒为单位")
        If IsEmpty(sleep_time) Then 
             wscript.quit
        end if
end if
sleep_time=sleep_time*1
loop
sleep_time=sleep_time*1



ip=inputbox("请输入OLT的ip地址")
 if ip="" then
     sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  

'加入OLT的ip地址
ip1 = "5.5.5.10"
ip2 = "5.5.5.20"
'目前OLT只有2台,ip分别为5.10跟5.20,如果以后增加了更多的olt或者OLT的ip地址改变.
'则需要对这里进行修改,并在下面的判断中增加ip3,ip4等等,

''''''将此段复制''''
do 
if ip=ip1 then 
exit do
end if
''''''将此段复制,并把ip1改成ip2等等''''

'将ip2改成最后一台olt的ip地址
if ip=ip2 then
exit do
else 
ip=inputbox("OLT的IP地址输入错误,请重新输入OLT的ip地址")'
 if ip="" then
     sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  

end if
loop



slot=inputbox("请输入Slot号")
 if slot="" then
     sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  

do  while (slot<1 or slot>30)
slot=slot*1
if slot < 1 then
  slot=inputbox("Slot号不能小于0,请重新输入Slot号")
      If IsEmpty(slot) Then 
          wscript.quit
      end if
end if
if slot > 30 then
         slot=inputbox("Slot号不能大于30,请重新输入Slot号")
              If IsEmpty(slot) Then 
                  wscript.quit
              end if
end if
slot=slot*1
loop



link=inputbox("请输入link号")
 if link="" then
     sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  


do  while (link<1 or link>8)
link=link*1
if link < 1 then
  link=inputbox("link号不能小于0,请重新输入link号")
      If IsEmpty(link) Then 
          wscript.quit
      end if
end if
if link > 8 then
         link=inputbox("link号不能大于8,请重新输入link号")
              If IsEmpty(link) Then 
                  wscript.quit
              end if
end if
link=link*1
loop



'建立Shell对象
set sh=WScript.CreateObject("WScript.Shell")

'提示测试开始.
m=sh.popup ("参数设置完成,马上开始测试,在测试过程中,如果需要终止测试,请点击取消",3,"开始测试...",4)
 if m=7 then
     sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  
m=sh.popup ("OLT第1次重启ONU,共需重启" & num & "次本窗口会自动关闭,并开始测试",3,"开始测试...",4)

 if m=7 then
    sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  


'循环测试
dim i
i=0
while i<num

'执行重启过程
sh.Run  "telnet.exe"
WScript.Sleep 200
'向telnet发送我们平时录入的命令
sh.SendKeys "open " & ip
WScript.Sleep 200
sh.AppActivate "{ENTER}"
WScript.Sleep 200

sh.SendKeys "{ENTER}"
WScript.Sleep 200
'发送登陆用户User

sh.AppActivate "telnet " & ip
sh.SendKeys " {ENTER}"
WScript.Sleep 200
'发送登陆密码pass

sh.AppActivate "telnet " & ip
sh.SendKeys " {ENTER}"
WScript.Sleep 200
'发送登陆用户User

sh.AppActivate "telnet " & ip
sh.SendKeys "en{ENTER}"
WScript.Sleep 200
'发送登陆密码pass

sh.AppActivate "telnet " & ip
sh.SendKeys " {ENTER}"
WScript.Sleep 200
'运行相关命令pwd

sh.AppActivate "telnet " & ip
sh.SendKeys "cd gpono{ENTER}"
WScript.Sleep 200
'运行相关命令pwd

sh.SendKeys "reset slot " & slot & " link " & link & " onulist all{ENTER}"
'运行退出TELNET登陆命令
WScript.Sleep 2000
sh.Run  "taskkill /f /im telnet.exe"
'WScript.Sleep sleep_time


i=i+1

if i<num then
for x=1 to sleep_time
m=sh.popup ("Testcenter打流已进行" & x & "秒,OLT将在" & sleep_time-x & "秒后开始第" & i+1 & "次重启ONU,共需重启" & num & "次。本窗口会在等待时间结束时自动关闭。",1,"等待中....",4)
  if m=7 then
    sh.popup "选择了取消,测试终止",3,"取消测试...",64
    wscript.quit
  end if  

next

end if
wend

msgbox ("测试结束,ONU被重启" & num & "次"),64,"测试完成"
发表于 2012-9-10 16:34:44 | 显示全部楼层
回复 7# 小熵


还是多看看帮助吧

Input控件后面再创建个“确定”按钮吧,点按钮后再去获取输入框里面的值。
你直接处理 Case $OK,  Case $Cancel, 哪来这些msg啊?
 楼主| 发表于 2012-9-10 16:55:01 | 显示全部楼层
MSG是用那个GUI那个软件(koda)转过来的代码里面的
其实我也不懂是什么意思,只是$msg=关闭按钮就关闭,  $msg=取消就关闭, $msg=开始测试就继续
我也没有搞懂,这个如果我要直接按回车就开始测试呢?
 楼主| 发表于 2012-9-10 16:59:00 | 显示全部楼层
本帖最后由 小熵 于 2012-9-11 08:30 编辑

回复 2# xiehuahere


    使用tecpsend确实很好...但是还是出了问题
http://www.autoitx.com/forum.php ... id=34891&extra=
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 09:45 , Processed in 0.110143 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表