scripts: trace_usb_capture: Clean up on exit
When the user presses Ctrl+c to exit the infinite capturing loop, ensure that the cleanup funciton is always executed. Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
8ab712a235
commit
5a13cdcf52
1 changed files with 13 additions and 13 deletions
|
@ -86,18 +86,18 @@ def main():
|
||||||
buff = usb.util.create_buffer(8192)
|
buff = usb.util.create_buffer(8192)
|
||||||
read_endpoint.read(buff, 10000)
|
read_endpoint.read(buff, 10000)
|
||||||
|
|
||||||
with open(output_file, "wb") as file_desc:
|
try:
|
||||||
while True:
|
with open(output_file, "wb") as file_desc:
|
||||||
buff = usb.util.create_buffer(8192)
|
while True:
|
||||||
length = read_endpoint.read(buff, 100000)
|
buff = usb.util.create_buffer(8192)
|
||||||
for index in range(length):
|
length = read_endpoint.read(buff, 100000)
|
||||||
file_desc.write(chr(buff[index]).encode('latin1'))
|
for index in range(length):
|
||||||
|
file_desc.write(chr(buff[index]).encode('latin1'))
|
||||||
usb.util.release_interface(usb_device, interface)
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
print('Data capture interrupted, data saved into {}'.format(args.output))
|
||||||
|
usb.util.release_interface(usb_device, interface)
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
try:
|
main()
|
||||||
main()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print('Data capture interrupted, data saved into {}'.format(args.output))
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue