- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将一个文本文件从 Excel 发送到 Raspberry Pi,Pi 将读取该文件并获取其中的输入。输入只有一行,而且是一个简单的数字,没有其他内容(40,38 等)
当我运行这个宏时,我可以在我的电脑中完美地看到输入文件,但是当我在 Pi 中打开它时,它会发生变化,例如:
我电脑中的输入文件是:
65
Raspberry 中的输入文件是:
ÿþ6
我如何确保这个号码按原样发送给 Pi。或者我如何将其解码为我的 python 脚本可以理解的内容。我不会对这个数字使用小数,如果它作为字符串发送也没关系,因为我可以稍后在我的 python 代码中解析它。
下面是我的 Excel 宏
Sub Send()
Dim sleeptime As String
sleeptime = InputBox("Duration between each reading in seconds?")
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("C:\Users\xx\Desktop\VBA\input.txt", True, True)
Fileout.Write sleeptime
Fileout.Close
Set fso = Nothing
Set Fileout = Nothing
Const cstrSftp As String = """C:\Program Files\PuTTY\pscp.exe"""
Dim strCommand As String
Dim pUser As String
Dim pPass As String
Dim pHost As String
Dim pFile As String
Dim pRemotePath As String
pUser = "pi" '//user on remote system
pPass = "xx" '//user's password on remote system
pHost = "192.168.x.xx" '//ip address of remote system
pFile = "C:\Users\xx\Desktop\VBA\input.txt" '//file to transfer
pRemotePath = "/home/pi/Temp_Codes" '//directory where file will be transferred to
strCommand = cstrSftp & " -sftp -l " & pUser & " -pw " & pPass & _
" " & pFile & " " & pHost & ":" & pRemotePath
Debug.Print strCommand
Shell strCommand, 0 ' vbHide
End Sub
这些是我使用此输入文件的 Raspberry Pi 脚本中的行。我稍后在 time.sleep 中使用这个 sleep 时间值。
with open('input.txt', 'r') as myfile:
sleeptime = myfile.read()
sleeptime = float(sleeptime.strip())
这是我运行的一个简单代码,只是为了测试这个编码:
#!/usr/bin/env python
import io
with io.open('input.txt', 'r', encoding='utf-8-sig') as myfile:
sleeptime = myfile.read()
sleeptime = float(sleeptime.strip())
这是我到目前为止遇到的错误。
pi@raspberrypi:~/Temp_Codes $ python try.py
Traceback (most recent call last):
File "try.py", line 6, in <module>
sleeptime = myfile.read()
File "/usr/lib/python2.7/codecs.py", line 314, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
File "/usr/lib/python2.7/encodings/utf_8_sig.py", line 66, in _buffer_decode
return codecs.utf_8_decode(input, errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: invalid start byte
最佳答案
当 Excel/VBA 通过“CreateTextFile”创建 Unicode 文件时,它会将其保存为 UTF-16 编码。您看到的是 BOM(字节顺序标记)。
你可以改变
CreateTextFile("C:\Users\xx\Desktop\VBA\input.txt", True, True)
到
CreateTextFile("C:\Users\xx\Desktop\VBA\input.txt", True, False)
这将另存为 ASCII 文本文件。或者您可以使用
在 Pi/Python 端进行更改open('input.txt', 'r', encoding='utf-16')
关于python - 将输入文件从 Excel VBA 发送到 Raspberry Pi 而不更改内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52006789/
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在使用带有Grove Pi +(1.2.2固件)的Raspberry Pi 3 B模型和用于Robots Image的Raspbian。 我在I2C-1端口中插入了多 channel 气体传感器,
这看起来非常简单,但我似乎无法弄清楚如何将 -Pi 和 Pi 之间的角度映射到 0 到 2Pi 的范围内。我尝试使用 np.select 但由于某种原因它卡住了我的程序。我需要这个范围内的角度,因为它
在使用 SciPy 和 NumPy 的项目中,我应该使用 scipy.pi , numpy.pi , 或 math.pi ? 最佳答案 >>> import math >>> import numpy
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我有一个运行 Raspbian 的 Raspberry Pi 1。我尝试在 Raspberry Pi 3 上运行 SD 卡,但它没有启动。 我已经阅读了有关升级 Raspberry Pi 2 安装以在
#include using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #d
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我目前正在尝试RadiusNetworks发布的Raspberry Pi iBeacon教程,网址为 http://developer.radiusnetworks.com/2013/10/09/ho
我无法在运行Raspbian的Raspberry Pi 3上安装我创建的 Electron 应用程序。我已经使用了electronic-packager来创建软件包,然后创建了一个debian安装程序
我想在Linux上为Raspberry Pi 1设置交叉编译环境。 特别是我想尝试最新版本,即Raspbian测试+ Qt5开发分支。 这个问题: How can I create a modern
我想要从我的 Raspberry Pi Zero 到手机的低延迟流式传输。据我了解,移动浏览器不支持 RTMP 流式传输,HLS 流式传输具有高延迟,而 webRTC 是我最好的选择。 有谁知道从零开
我的公司使用 Raspberry Pi 3 作为产品中的嵌入式 Controller 。用户不会优雅地关闭它,他们只是扳动一个开关。为避免损坏,/boot 和/root 文件系统是只读的。这似乎是防弹
如何使用 Raspberry Pi 作为 b/w USB Tethered 手机和路由器的桥接器,使用“以太网电缆 b/w Raspberry Pi 和路由器”和“USB 电缆 b/w 手机和 Ras
我正在尝试在Raspberry Pi 3上安装Rakudo Star 2018.04。 我做: sudo perl Configure.pl --gen-moar --gen-nqp --prefix
我正在寻找一些可以有效完成的不错的 C 代码: while (deltaPhase >= M_PI) deltaPhase -= M_TWOPI; while (deltaPhase T Mod(T
我正在尝试为 raspberry Pi 构建跨环境以在 Eclipse CDT for windows 上构建二进制文件。 我得到了用于访问 GPIO 的 Wiring Pi,我需要使用“Window
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我正在寻找一些可以有效完成的不错的 C 代码: while (deltaPhase >= M_PI) deltaPhase -= M_TWOPI; while (deltaPhase T Mod(T
这个问题在这里已经有了答案: C: How to wrap a float to the interval [-pi, pi) (15 个答案) 关闭 9 年前。 我想知道是否可以定义一个只能取 -
我是一名优秀的程序员,十分优秀!