- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用在 Ubuntu 主机上运行的 pySerial 来自动测试嵌入式 Controller 。我可以在终端窗口(例如 PuTTY)中输入命令,并整天得到 EC 的响应。但是,当我尝试使用 pySerial 程序做同样的事情时,EC 会在一段时间后停止回显命令,就在回显命令的中间。从那时起,EC 停止响应程序,包括不发送被中断命令的结果。
如果我终止程序并尝试再次使用终端连接到 EC,则 EC 无响应。如果发生导致 EC 将输出写入终端的外部事件,则该信息将正确显示。问题一直存在,直到我重新启动 EC - 这也会删除问题发生时 EC 上发生的任何日志。 (日志只能通过串口访问...)
似乎 pySerial 正在做的事情导致 EC 的输入处理停止。我尝试键入 Ctrl-Q (XON),希望有一些不明显的软件流控制正在进行,但这并没有什么不同。我尝试在程序中发送交替命令,在发送命令之间发送空行,在发送命令之间插入延迟 - 但每次处理几个命令后它都会死掉。
这是我目前正在使用的脚本:
import serial
from datetime import datetime
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1)
print('Starting up')
# send an empty command to ensure a prompt is displayed
ser.write(b'\r\n')
commandToSend = 'battery current'
failed = 0
running = True
while running:
while running:
# read from the EC until a timeout occurs with no data available
try:
# wait for the EC prompt
rcvData = ser.read_until(b' ec> ')
now = datetime.now().time()
print('{}\tRead from device: "{}"'.format(now, rcvData))
decoded = rcvData.decode('ascii')
if len(decoded) == 0:
# timeout, nothing read from EC, send next command
failed += 1
break
# normalize line terminations then split the data into lines
lines = decoded.replace('\r\r\n','\r\n').split('\r\n')
for line in lines:
print('{}{}'.format(' '*34, line))
break
except KeyboardInterrupt:
print('\nKeyboard interrupt, aborting')
running = False
break
except Exception as e:
print(e) # this branch never executes, from my observation
pass
now = datetime.now().time()
if failed > 1:
print('{}\tCommunication with the EC has failed'.format(now))
break
if running:
# send the command when there's no data to read
print('{}\tWriting: "{}\\r\\n"'.format(now, commandToSend))
ser.write('{}\r\n'.format(commandToSend).encode())
ser.flush()
运行上述脚本的典型结果是:
$ ./ec-uart-test.py
Starting up
20:19:10.620998 Read from device: "b'\r\n ec> '"
ec>
20:19:11.622234 Read from device: "b''"
20:19:11.622345 Writing: "battery current\r\n"
20:19:11.627921 Read from device: "b'\r\n ec> '"
ec>
20:19:11.628690 Read from device: "b'battery current\r\n0ma\r\r\n ec> '"
battery current
0ma
ec>
20:19:11.628777 Writing: "battery current\r\n"
20:19:11.635899 Read from device: "b'\r\n ec> '"
ec>
20:19:12.637335 Read from device: "b'battery cu'"
battery cu
20:19:12.637439 Writing: "battery current\r\n"
20:19:13.644800 Read from device: "b''"
20:19:14.646080 Read from device: "b''"
20:19:14.646172 Communication with the EC has failed
除了打开 EC 并在其上放置硬件分析器之外,我还应该尝试其他什么方法来使此代码正常工作吗?
最佳答案
看来测试程序实际上是错误的:按照我同事的一个例子,我在终端中输入“电池电流”命令,得到响应,然后使用向上箭头键重新运行命令 - 这似乎整天工作。
但是,这不是同一个测试:向上箭头(从 EC 的历史记录中检索最后一个命令)与重复输入命令并发送它不同。
当我尽可能快地将命令重复粘贴到终端窗口时,EC 失败的方式与使用 pySerial 发送命令的方式完全相同:失败是 EC 内部的,而不是 pySerial 在通信线路上所做的事情。
关于python - pySerial问题: embedded controller stops echoing commands,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70442561/
我有一个 HTML 文件,当您单击按钮时,Ajax 会加载一个 PHP 文件,然后 PHP 文件将一些文本回显到 HTML 文件。 问题是,如果我第二次(或第三次、第四次等)单击该按钮,下一个 ech
我正在尝试使用以下方法调用数据库中的 HTML/PHP 内容: 当调用该行时,HTML 会正确显示,但 PHP 不会。我相信这是主 echo 内部 echo 的原因。 Hello \
我正在尝试使用复选框来显示和更新 MySQL 数据库中的记录。我想根据复选框是选中还是未选中来更改复选框的值。但是我收到了这个错误: 解析错误:语法错误,意外的 T_ENCAPSED_AND_WHIT
我遇到了重定向符号的不同位置( > , &2 message message echo message >&2 message >&2 echo message message 对于所有表单,我得到了
这个问题在这里已经有了答案: Source files in a bash script (2 个回答) 2年前关闭。 https://askubuntu.com/questions/250012/h
我注意到当我在 DOS 中使用 echo 将某些内容打印到文件时,会在字符串后附加一个空格。我需要打印没有尾随空格的字符串。有没有办法做到这一点,或者作为一种解决方法,从文件中删除尾随空格? 最佳答案
不确定我在这里做错了什么,但结果总是空的。只有当没有选择答案时,脚本才应该输出“你没有选择答案”,否则它应该输出给定的答案: 我已经按照提到的更新了脚本,但即使给出了答案,仍然得到空输出:/ 感谢到目
不确定我在这里做错了什么,但结果总是空的。只有当没有选择答案时,脚本才应该输出“你没有选择答案”,否则它应该输出给定的答案: 我已经按照提到的更新了脚本,但即使给出了答案,仍然得到空输出:/ 感谢到目
echo 'Welcome echo $_SESSION["username"];'; 在上面的代码中,它没有显示用户名变量。相反,它只是简单地回显 Welcome $_SESSION["userna
我试图在 php echo 语句中回显一个 php 变量。 我在 MySql 数据库中有一个名为 display_code 的列,其中包含一个值,例如 $num_rows_customers。 我从数
如上所述,我想知道为什么我们使用@Echo off/on 而不是Echo off/on。这是有什么原因还是只是为了可见性?根据这个,它在视觉上似乎没有什么不同: C:\Users\Jack> Echo
我希望能够将新的 ECHO 消息连接到先前的 ECHO 消息,如下所示: 命令: ECHO PROCESSING... REM some process here ECHO DONE 结果: PROC
我不了解 jQuery,所以如果这是一个愚蠢的问题,我很抱歉。 当我将值从 php 传递到 javascript 时,即使之前用 echo 打印的消息也被传递,我怎样才能避免这种情况? php $
请有人解释一下下面的结果差异 echo intval(1e10); 输出1410065408 echo 1e10; 输出10000000000 最佳答案 有符号整数有最大值。在 32 位系统上,它
我正在制作导航菜单,我想添加一个事件类这是我的代码 我想输出 CSTYLE 并使用 'if 来回显事件类 %s %s ', $row['CSTYLE'], $row['id'], $row['na
echo -n 的终端手册页如下: -n Do not print the trailing newline character. This may also be achie
直到今天它突然停止工作时,它一直工作得很好......(我知道这不是很有帮助,但我到处都看了看) 我正在遍历从 mySQL 查询返回的值,并将每个值放入一个数组中,然后将这个数组放入另一个数组中。然后
目前我正在这样做: $lines = file('data/index'); foreach ($lines as $value) list($title, $location) =
我在 PHP CLI 中运行以下脚本: 什么都没有显示。如何启用输出? 最佳答案 在您的终端中运行它: php -r 'echo "Hello World!\n";' 关于echo - 在 PHP
希望这是一个简单的问题... 我正在使用批处理文件来移动一些文件,不幸的是,出于各种原因,这有点复杂。要正常运行,需要右键单击并“以管理员身份运行”。 为了提醒未清洗的大众和我执行该步骤,我希望第一行
我是一名优秀的程序员,十分优秀!