作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试运行 RFSniffer 进程来监听传入的 433mhz 信号。
如果我运行该过程,它只会输出来自 433mhz 接收器的值。我想用 Python 读取此输出,以便执行特定操作。
我找到了很多运行它并使用 Python 获取输出的方法,但其中的命令是自终止的 (ls -ial
)。 RFSniffer 进程一直运行到您手动停止它为止。
这是我现在拥有的(不工作):
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess, time, os, sys
cmd = ["sudo", "/home/pi/433Utils/RPi_utils/RFSniffer"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1)
for line in iter(p.stdout.readline, b''):
print line,
p.stdout.close()
p.wait()
最佳答案
这个解决方案应该有效:
os.system("sudo /home/pi/433Utils/RPi_utils/RFSniffer >output.txt & pkill --signal SIGINT RFSniffer")
f = open("output.txt","r")
readf = f.read()
for line in readf:
print line,
#close file
if f.closed == "False":
f.close()
您可以将它放在一个 while 循环中以不断扫描,直到找到一个参数。
这是我遇到的唯一一种可以将实时扫描(无限且不停止,不像 ls -l)输出到文件然后读取值的方法。
这是我使用蓝牙进行的实时扫描之一的示例:
sensortag=0
while sensortag != "B4:99:4C:64:33:E0":
#call the command and write to scan.txt file and then fill the process.
#loop to find if the MAC address given is available
os.system("hcitool lescan> scan.txt & pkill --signal SIGINT hcitool")
scan = open("scan.txt","r")
readscan = scan.read()
if "B4:99:4C:64:33:E0" in readscan:
print "SensorTag found."
sensortag = "B4:99:4C:64:33:E0"
关于python - Raspberry RFSniffer 使用 python 读取输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26948861/
我正在尝试运行 RFSniffer 进程来监听传入的 433mhz 信号。 如果我运行该过程,它只会输出来自 433mhz 接收器的值。我想用 Python 读取此输出,以便执行特定操作。 我找到了很
我是一名优秀的程序员,十分优秀!