Reading Serial data using VBS on Windows 10

I have found the simple VBscript code in some old posts that worked for most:

Const ForReading = 1
Const ForWriting = 2

Set fso = CreateObject("Scripting.FileSystemObject")
Set com = fso.OpenTextFile("COM6:9600,N,8,1", ForReading)
s = com.ReadLine
MsgBox(s)

com.Close()

The issue is that if I plug Arduino Uno to my PC and run a script, the script get stuck at: s = com.ReadLine
If I just open and close Serial Monitor in Arduino IDE and then run VBS after, it runs every time.
I have tried adding delays after each command with WScript.Sleep(500) but it did't work. I tried it on different computers but the same happened. For testing I am using Examples/Basic/AnalogReadSerial sketch.
The goal for this script is to get current value of temperature sensor from Arduino to PC software, which only support external variables from VBS.
I will expand VBS later to be sure it catches something usefull if I can get communication to work.
I would be realy happy for any solutions since I am stuck with this for a few days.

From many similar posts in the past, I recall the VB program must wait for the Arduino to reset after the data line is opened.
Paul

Thank you for a replay. I tried with delays up to 5000ms and it didn't work.
I tried reading data using VB and C# and everything worked fine.

I think I will compile an exe file with c# that will read from com port and save data to txt. And then run this file from VBS.

Could be that the line "s=comReadLine" is waiting for a line terminator either CR or NL. Does your arduino transmit line use "Serial.println("data"), emphasis on println.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.