我正在使用macOS上的R通过USB连接到Arduino UNO。虽然读取数据工作正常,但是将数据写入Arduino会引发错误
我用于建立连接和读写的代码如下所示:
#loading the R package for serial communication
require(serial)
#storing the appropriate serial device name
con_dir = "/dev/"
con_arduino_cu<-list.files(con_dir, pattern ="cu.usb")
#setting up connection parameters, making sure the BAUD rate matches the one used by the Arduino
con <- serialConnection(name = "testcon"
,port = con_arduino_cu
,mode = "9600,n,8,1"
,buffering ="none"
,newline = 1
,translation = "cr"
#opening and testing the connection
open(con)
isOpen(con)
#this reads data from the Arduino and works fine
read.serialConnection(con)
#But this returns an error
write.serialConnection(con,"Hello world")
虽然可以正常读取,但写入连接会返回
'Error: [tcl] can't read "tcl_tmp_cu": no such variable'.
使用“屏幕”在终端中交换数据可以正常进行,因此连接应该很好。
在调试write.serialConnection时,似乎将此变量传递给了.Tcl,但我不知道它的用途。
关于我在这里做错什么的任何线索吗?