Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hope this is in the right place.

Attempting to read from serail port, XP, admin accnt.

if there are chars in the buffer, then the following throws error: Permission denied, code: 800A0046 on the check of AtEndOfStream.

Set fso = CreateObject("Scripting.FileSystemObject")
Set comObj = fso.OpenTextFile("COM3:9600,N,8,1", for Read)
if not comObj.AtEndOfStream then
 msgbox comObj.ReadLine
end if

Writing on the other hand works just fine with the following:

Set fso = CreateObject("Scripting.FileSystemObject")
Set com = fso.OpenTextFile("COM4:9600,N,8,1", forWrite)
com.Write "Hello World"

Not sure its relevant but I'm using com0com to connect the two ports (3 & 4)
I should perhaps also add that using the MSCOMM obj in VB6 I can read and write no problem.

Any ideas why the permission denied for the read.
Updated 15-Jul-11 4:55am

Share this answer
You're trying to treat the COM port as a file. This is not going to work.

Since you've already done this in VB6, VBScript is no different. You can sitll use the MSCOMM component in VBScript.

It all starts with
Dim comPort
Set comPort = CreateObject("MSCommLib.MSComm")
Share this answer
Thanks thatraja for your reply - however I'd googled that one before I posted here - first hit if I remeber correctly - but having read it - it wasn't relevant to my particular problem.

Thanks Dave for your reply.
However when you say:
"You're trying to treat the COM port as a file. This is not going to work."
I'm afraid that is incorrect. It's now working just fine. The problem was with com0com. If I use my scripts exactly as posted above on a "real" port all is fine.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900