从Python Shell初学者问题中检索值
我可以使用此 python file 来自图书馆的文件通过BACNET协议读取温度传感器值的请求,通过从终端运行此命令:
echo'read读取12345:2模拟函数:2 PresentValue'| py -3.9 readproperty.py
,我可以在控制台中看到67.029999114990234
的值。
如果这个问题看起来真的很愚蠢且入门级,我深表歉意,但是我可以将此脚本称为并为传感器阅读分配一个值吗?任何技巧都非常感谢。
例如,如果我运行此操作:
import subprocess
read = "echo 'read 12345:2 analogInput:2 presentValue' | python ReadProperty.py"
sensor_reading = subprocess.check_output(read, shell=True)
print("sensor reading is: ",sensor_reading)
它将仅打印0
,但希望找出一种打印67.0299991149990234
的传感器读数的方法。我认为引擎盖下发生的事情是BACNET库带来了一种使用STD In/Out/Flush的外壳脚本。
I can use this python file from a library to make a read request of a temperature sensor value via BACnet protocol by running this command from terminal:
echo 'read 12345:2 analogInput:2 presentValue' | py -3.9 ReadProperty.py
And I can see in the console the value of 67.02999114990234
is returned as expected.
I apologize if this question seems real silly and entry level, but could I ever call this script and assign a value to the sensor reading? Any tips greatly appreciated.
for example if I run this:
import subprocess
read = "echo 'read 12345:2 analogInput:2 presentValue' | python ReadProperty.py"
sensor_reading = subprocess.check_output(read, shell=True)
print("sensor reading is: ",sensor_reading)
It will just print 0
but hoping to figure out a way to print the sensor reading of 67.02999114990234
. I think what is happening under the hood is the BACnet library brings up some sort of shell scripting that is using std in/out/flush.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OS.System
不会从Stdout返回输出,而是执行程序/代码的退出代码。请参阅 docs 有关更多信息:
要将输出从Stdout进入程序中,您必须使用
子系统
模块。外面有很多有关如何使用子系统
的教程,但这是一种简单的方法:os.system
does not return the output from stdout, but the exit code of the executed program/code.See the docs for more information:
For getting the output from stdout into your program, you have to use the
subsystem
module. There are plenty of tutorials outside on how to usesubsystem
, but this is an easy way: