How to read data from serial ports in R

I want to draw real-time data from the serial port. I think R is a good tool for this job. I encountered a stumbling block while trying to read data from the serial port (COM4) I have verified that the data is entered via terra term (and closed the session before trying R), but I can’t seem to get anything in R.

I checked a few places, Include these threads:
How to invoke script that uses scan() on Windows?
How to include interactive input in script to be run from the command line

I also found it on the R forum Up this old post:
https://stat.ethz.ch/pipermail/r-help/2005-September/078929.html

These have got me so far, but I seem to I cannot get any data from the serial port to R.

At this time, I can use VBA to transfer data in excel, but I want to do some better real-time drawing and data filtering in R.

< p>Edit: Thanks for your help so far. I only worked when writing this edit, so here is the code:

#
# 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() {
newText <- read.serialConnection(con)
if(0 {
foo <- paste(foo, newText)
}
}

cat("\r\n" , foo, "\r\n")

close(con)

foo ends up as a long string with new lines, just like I want:

3181, -53120, -15296, 2, 
3211, -53088, -15328, 2,
3241, -53248, -15456, 1,
3271, -53216, -15424, 2,
3301, -53184, -15488, 2,
3331, -53344, -15360, 1,
3361, -53440, -15264, 1,

enter image description here

Thanks again for all the help!

I am using the serial package provided on CRAN (here). This is to satisfy your Developed on demand. Reading and sending data tables and RS232 connections. I do recommend this because “mode.exe” does not seem to work with virtual COM ports. See NPort-Server, etc.

< p>I want to plot real-time data from the serial port. I think R is a good tool for this job. I encountered a stumbling block when trying to read data from the serial port (COM4). I have verified that the data is through terra term entered (and closed the session before trying R), but I can’t seem to get anything in R.

I checked several places, including these threads:
How to invoke script that uses scan() on Windows?
How to include interactive input in script to be run from the command line

I also found this old post on the R forum:
https ://stat.ethz.ch/pipermail/r-help/2005-September/078929.html

These have got me so far, but I can’t seem to get any data from the serial port to R.

At this time, I can use VBA to transfer data in excel, but I want to do some better real-time drawing and data filtering in R.

Edit: Thank you for your help. So far. I only worked while writing this editor, so here is the code:

#
# 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() {
newText <- read.serialConnection(con)
if(0 {
foo <- paste(foo, newText)
}
}

cat("\r\n", foo, "\r\ n")

close(con)

foo ends up as a long string with new lines, just like I want:

3181, -53120, -15296, 2, 
3211, -53088, -15328, 2,
3241, -53248, -15456, 1,
3271 , -53216, -15424, 2,
3301, -53184, -15488, 2,
3331, -53344, -15360, 1,
3361, -53440, -15264, 1 ,

enter image description here

Thanks again for all help!

I am using the serial package provided on CRAN (here). This is developed to meet your needs. Read and send data tables and RS232 and other connections. I do recommend this because “mode.exe” does not seem to be applicable to virtual COM ports. See NPort-Server, etc.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1272 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.