Python 当Pexpect存在时,Pyserial不工作
我想使用Pyserial与路由器通信(更改ip地址)。只要运行以下代码,它就可以工作: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\
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地址的目的)。很抱歉给你带来了困惑。但它不起作用。。。