我试图用python编写代码以自动化我通常手动完成的工作。这项工作只是修改C代码的某些部分,然后将以下命令插入终端以为每个Z1 Zolertia微粒构建,编译和引导C代码。
sudo scons board=z1 toolchain=mspgcc bootload=/dev/ttyUSB0 oos_openwsn
该命令在终端或bash脚本中运行正常,但是当我从python脚本运行时,该命令无法正常运行。
我相信问题是:构建和编译阶段已成功完成,但是引导加载阶段(质量擦除)运行了两次,因此端口已关闭并且不再可见。
这部分代码使麻烦:
subprocess.call('(cd /home/ilkin/git/Yadhunandana-testbed/openwsn-fw ; sudo scons board=z1 toolchain=mspgcc bootload=/dev/ttyUSB0 oos_openwsn)', shell=True)
这是构建,编译和引导加载阶段的输出。如您所见,“批量擦除”同时运行,因此失败。
sudo python automate.py
scons: Reading SConscript files ...
___ _ _ _ ___ _ _
| . | ___ ___ ._ _ | | | |/ __>| \ |
| | || . \/ ._>| ' || | | |\__ \| |
`___'| _/\___.|_|_||__/_/ <___/|_\_|
|_| openwsn.org
none
scons: done reading SConscript files.
scons: Building targets ...
Dynifying build/z1_mspgcc/openapps/openapps_dyn.c
msp430-size build/z1_mspgcc/projects/common/03oos_openwsn_prog
text data bss dec hex filename
51442 532 6598 58572 e4cc build/z1_mspgcc/projects/common/03oos_openwsn_prog
z1_bootload(["build/z1_mspgcc/projects/common/03oos_openwsn_prog.phonyupload"], ["build/z1_mspgcc/projects/common/03oos_openwsn_prog.ihex"])
starting bootloading on /dev/ttyUSB0
MSP430 Bootstrap Loader Version: 1.39-goodfet-8
Mass Erase...
MSP430 Bootstrap Loader Version: 1.39-goodfet-8
Mass Erase...
Traceback (most recent call last):
File "bootloader/z1/z1-bsl-nopic", line 1925, in <module>
main(0);
File "bootloader/z1/z1-bsl-nopic", line 1840, in main
for f in toinit: f()
File "bootloader/z1/z1-bsl-nopic", line 1102, in actionMassErase
0xa506) #Required setting for mass erase!
File "bootloader/z1/z1-bsl-nopic", line 761, in bslTxRx
self.bslSync(wait) #synchronize BSL
File "bootloader/z1/z1-bsl-nopic", line 720, in bslSync
raise BSLException(self.ERR_BSL_SYNC) #Sync. failed
__main__.BSLException: Bootstrap loader synchronization error
done bootloading on /dev/ttyUSB0
scons: done building targets.
当我从终端手动运行命令时情况并非如此,“ Mass Erase”部分仅运行一次并且引导加载成功完成。我期望这样的输出:
(cd /home/ilkin/git/Yadhunandana-testbed/openwsn-fw ; sudo scons board=z1 toolchain=mspgcc bootload=/dev/ttyUSB0 oos_openwsn)
scons: Reading SConscript files ...
___ _ _ _ ___ _ _
| . | ___ ___ ._ _ | | | |/ __>| \ |
| | || . \/ ._>| ' || | | |\__ \| |
`___'| _/\___.|_|_||__/_/ <___/|_\_|
|_| openwsn.org
none
scons: done reading SConscript files.
scons: Building targets ...
Dynifying build/z1_mspgcc/openapps/openapps_dyn.c
msp430-size build/z1_mspgcc/projects/common/03oos_openwsn_prog
text data bss dec hex filename
51442 532 6598 58572 e4cc build/z1_mspgcc/projects/common/03oos_openwsn_prog
z1_bootload(["build/z1_mspgcc/projects/common/03oos_openwsn_prog.phonyupload"], ["build/z1_mspgcc/projects/common/03oos_openwsn_prog.ihex"])
starting bootloading on /dev/ttyUSB0
MSP430 Bootstrap Loader Version: 1.39-goodfet-8
Mass Erase...
Transmit default password ...
Invoking BSL...
Transmit default password ...
Current bootstrap loader version: 2.13 (Device ID: f26f)
Changing baudrate to 38400 ...
Program ...
51974 bytes programmed.
Reset device ...
done bootloading on /dev/ttyUSB0
scons: done building targets.
提前谢谢!
答案 0 :(得分:0)
幸运的是,我已经解决了这个问题。发生问题是因为在我的代码中使用了一个功能来列出连接的串行设备。主要原因是因为此功能在列出串行设备后将其关闭。因此,在短时间内看不到串行端口,因为在关闭串行端口(以微秒为单位)后,引导加载阶段会在几行之后开始。
def serial_ports():
ports = glob.glob("/dev/ttyUSB*")
result = []
for elements in reversed(ports):
try:
s = serial.Serial(elements)
s.close()
result.append(elements)
except (IOError, serial.SerialException):
pass