小编Rya*_*n B的帖子

如何从R中的串行端口读取数据

我想从串行端口绘制实时数据。我认为R是完成这项工作的好工具。我在尝试从串行端口(COM4)读取数据时遇到了麻烦。我已经验证了数据是通过terra项传入的(并在尝试R之前关闭了会话),但是我似乎无法在R中得到任何东西。

我检查了一些地方,包括这些线程: 如何在Windows上调用使用scan()的脚本? 如何在脚本中包括交互式输入以从命令行运行

我还在R论坛上找到了这个旧主题:https : //stat.ethz.ch/pipermail/r-help/2005-September/078929.html

这些已经使我走了这么远,但实际上我似乎无法从串行端口将任何数据输入到R中。

此时,我可以使用VBA在excel中流式传输数据,但是我想在R中进行此操作,以便更好地实时绘制和过滤数据。

编辑:感谢到目前为止的帮助。在编写此编辑文件时,我刚刚开始工作,所以代码如下:

#
# Reset environment
#
rm(list = ls())         # Remove environemnent variables
graphics.off()          # Close any open graphics

#
# Libraries
#
library(serial)

#
# Script
#

con <- serialConnection(name = "test_con",
                        port = "COM11",
                        mode = "115200,n,8,1",
                        buffering = "none",
                        newline = 1,
                        translation = "cr")

open(con)

stopTime <- Sys.time() + 2
foo <- ""
textSize <- 0
while(Sys.time() < stopTime)
{
    newText <- read.serialConnection(con)
    if(0 < nchar(newText)) …
Run Code Online (Sandbox Code Playgroud)

windows serial-port r uart

5
推荐指数
1
解决办法
5476
查看次数

标签 统计

r ×1

serial-port ×1

uart ×1

windows ×1