- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我尝试使用 Python 读取 Arduino 板上 DS18B20 温度传感器的值。在我的Python代码中,我使用Pyserial来访问端口,下面是代码。
import serial
def readTemp():
temp = serial.Serial('COM3', 9600)
line = temp.readline().strip()
while line:
print(line.strip())
line = temp.readline().strip()
temp.close()
def main():
readTemp()
main()
在我的 Arduino 代码中,我对其进行了编码,以便输出应该是数字。下面是 Arduino 的输出:
21.3125
22.3750
22.3750
22.3750
22.3750
但是,当我运行Python代码时,输出添加了一些字母和引号,但我不知道为什么以及如何删除它们。以下是 Python 的输出。
b'22.3750'
b'22.0625'
b'22.0625'
b'22.0625'
b'22.0625'
其次,通常当人们在shell上运行python脚本时,会有一个“>>”表示运行过程已经完成,然后就可以关闭shell了。但是,在打印我的 python 脚本的输出后,该脚本似乎仍在运行,因为没有出现“>>”。我尝试使用 ctrl+c 来杀死但无法,当我尝试关闭 shell 时,会弹出一个窗口,提示“您的程序仍在运行,是否要杀死它?”。那么打印输出后是否有办法完成运行呢?
我是Python新手,刚刚学习pyserial。非常感谢您,我将感谢您的帮助。
最佳答案
关于第一个问题,
别担心,这些值以字节形式读取。前面的b表示字节。您可以将其转换为字符串使用解码('utf-8')。
代码中需要更改
替换
print(line.strip())
与
bytesValue = line.strip()
numericValue = int(bytesVale.decode('utf-8'))
print(numericValue)
关于第二个问题,您的进程尚未完成,因为它正在监听设备。条件
while line:
使进程保持事件状态。
如果您希望程序只读取一个值并退出,可以使用 if 而不是 while。
line = temp.readline().strip()
if line:
bytesValue = line.strip()
numericValue = int(bytesVale.decode('utf-8'))
print(numericValue)
temp.close()
关于python - PySerial : weird output with letter and quotation marks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53456475/
我需要一个可以显示每个主题的最高分数计数的查询。假设 3 名学生的科学成绩需要达到 98 分 count marks subject 3 98 Maths 最佳答案 首先找到每个
对于Java中的Concurrent-Mark-Sweep垃圾收集器;我不清楚这两个阶段有什么不同。为什么需要并发标记?初始标记没有找到所有 Activity 对象吗? 最佳答案 使用CMS,即所谓的
我想知道组查询的工作 假设有一张表Student(id,name,marks) 现在如果我想输出除得分最高的学生之外的所有学生,为什么这个查询不起作用? SELECT * FROM Students
我在 VSCode 中使用 markdown 预览器,希望能够突出显示“.md”文件中的某些文本并将其包装在“”标签中,以便在查看 markdown 文件时突出显示以其呈现的格式。 有没有快速简便的方
Pragma 标记在 Localizable.strings 文件中不起作用。如果我在 Localizable.strings 中添加第二个 MARK: (#pragma mark),xcode 会出
我喜欢使用 vim(在 ms windows 上),我想每个人都有一个最喜欢的编辑器,这是我的。 在一台特定的 PC 上,我遇到了与 mark[a-zA-Z] 命令有关的问题。它不适用于字母 a 和
import java.util.*; public class loops { public static void main (String []args) { Scann
我喜欢使用 vim(在 ms windows 上),我想每个人都有一个最喜欢的编辑器,这是我的。 在一台特定的 PC 上,我遇到了与 mark[a-zA-Z] 命令有关的问题。它不适用于字母 a 和
假设我有一个包含函数的列表:。如果我想使用BASCH对它们进行基准测试,我可以这样做:。它运行得很好。然而,我对这种方法有两个小毛病。。看来,Exprs对Mark的论证应该会有所帮助,因为它允许我做一
我正在编写我的 k8s 升级 ansible 剧本,其中我需要做 apt-mark unhold kubeadm .现在,我试图避免使用 ansible command或 shell调用模块apt如果
我的 View 区域中有 2 个并排的列表控件。当我在 list1 中选择一个项目时,会填充 list2。当在 list2 中选择一个项目时,详细信息会显示在它之外的另一个 View 中。 因此,当在
目标是用括号标记字符串中的每个匹配项,并为每个匹配项标记返回相同的字符串 即: Pattern = "\\d+" Text = "e3e3e" wanted result = "e(3)e(3)e"
在我通过启动并运行一个 100% 覆盖率的小型 C++ 测试项目来了解更多关于自动化测试的过程中,我遇到了以下问题——尽管我所有的实际代码行和所有执行分支都是被测试覆盖,lcov 仍然报告两行未经测试
我实现了一个小函数,它解析 SQL INSERT 语句并在光标位于列名上时突出显示列值,反之亦然。 然后我想添加一种在列名和列值之间快速跳转的可能性。我在我的实现中使用了 push-mark,所以我可
我有一个变量searchString与包含字符串。我必须列出 titles我想要的过滤器 searchString 。我尝试使用标签 用于突出显示一段标题,但目前还无法做到。 我尝试实现一个具有 2
我在使用 AppCode IdeaVim 插件时遇到了这个奇怪的问题。安装后一切似乎都正常工作。然而我遇到了一些非常烦人的事情。每当我尝试通过运行 :marks 命令或 :registers 列出标记
这是一个关于正确实现Java的InputStream接口(interface)的问题。 我的实现不支持标记/重置功能。因此,它从 markSupported 方法返回 false。在这种情况下我应该如
我正在构建我的第一个 Tailwindcss基于网站。我想修改 标签使标记的文本看起来更漂亮。 这是我做的: mark { @apply inline-block pr-1 pl-1 py-0
我看到默认的 背景颜色为黄色。在哪里定义的? 我没有在 reference 中找到它,CSS2 system colors中没有对应的颜色. 颜色总是一样的吗?它取决于浏览器或 GUI 设置吗?有什么
我无法想出正确的正则表达式字符串来删除多个 ?人物。我想按顺序更换多个?用一个 ?,但是要转义哪些字符...正在转义我。 示例输入: Is this thing on??? or what??? 期望
我是一名优秀的程序员,十分优秀!