Here is what I do (“1” is signal to Arduino to take measurement):
- in VBA:
Open fCOM For Binary Access Read Write As #1 ' where fCOM is path to COM port ("\\.\COM10" in my case)
Put #1, , "1" ' "1" is command to Arduino to make measurement in my case
Line Input #1, mBuffer ' mBuffer is variable for result that is used by VBA
Program stops (not responding) at line with Put function
- In R:
system('mode COM10 9600,N,8,1)
ser <- file("\\\\.\\COM10", open="r+")
data <- scan(ser, what = list(numeric(length=1),numeric(length=1)), sep = ",")
This code stops (not responding) at the line with scan() function
I tied as you suggested to make 2 seconds delay after COM opening - did not solve the problem.
Again, I confirm that in both cases of R and VBA my programs start working after I open Serial Monitor, send 1 to it (get reading) and close it. After this manipulation with Serial Monitor everithing works as it suppose to work.