Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当Pexpect存在时,Pyserial不工作_Python_Pyserial_Pexpect - Fatal编程技术网

Python 当Pexpect存在时,Pyserial不工作

Python 当Pexpect存在时,Pyserial不工作,python,pyserial,pexpect,Python,Pyserial,Pexpect,我想使用Pyserial与路由器通信(更改ip地址)。只要运行以下代码,它就可以工作: def ipaddr_set(): ser = serial.Serial("/dev/tty_dgrp_aa_0",baudrate=115200) ser.open() channel =fdpexpect.fdspawn(ser.fd) channel.send("\n\n") time.sleep(2) channel.send("\nusername\

我想使用Pyserial与路由器通信(更改ip地址)。只要运行以下代码,它就可以工作:

def ipaddr_set():
    ser = serial.Serial("/dev/tty_dgrp_aa_0",baudrate=115200)
    ser.open()
    channel =fdpexpect.fdspawn(ser.fd)
    channel.send("\n\n")
    time.sleep(2)
    channel.send("\nusername\npassword\n")
    time.sleep(2)
    channel.send("\n ip-adress 114.293.232.20\n")
    time.sleep(2)
    channel.send("exit\n")
    ser.close()
但是如果我使用pexpect添加一个函数:

def ftp_firmware_update():
    child = pexpect.spawn('ftp 114.293.232.20')
    child.delaybeforesend = 0.1
    child.expect('(?i)name .*: ')
    child.sendline('username')
    child.expect('(?i)Password')
    child.sendline('pass')
    child.expect('ftp> ')
    child.sendline('put firmware.bin')
    child.expect('Upgrade')
    child.sendline('close')
    child.expect('221')
    print child.before,child.after
    child.sendline('quit')
    child.close()
    print "Upgrade firmware finished, sleep..."
    time.sleep(20)
ipaddr_set()无法正常工作(它会被执行,但ip不会更改)。有人有办法解决这种情况吗


非常感谢

更新固件可能会重置设置。首先更新,然后更改ip。@J.F.Sebastian实际上我先更新,然后更改ip(这就是更改ip地址的目的)。很抱歉给你带来了困惑。但它不起作用…更新固件可能会重置设置。首先更新,然后更改ip。@J.F.Sebastian实际上我先更新,然后更改ip(这就是更改ip地址的目的)。很抱歉给你带来了困惑。但它不起作用。。。