Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VBScript
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.
 
forRead=1
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
com.Close
 
Writing on the other hand works just fine with the following:
 
forWrite=2
Set fso = CreateObject("Scripting.FileSystemObject")
Set com = fso.OpenTextFile("COM4:9600,N,8,1", forWrite)
com.Write "Hello World"
com.Close
 
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.
Posted 15-Jul-11 5:49am
sonisan160
Edited 15-Jul-11 5:55am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Reason for that error & solution
 
Troubleshooting Code error 800A0046 - Permission Denied[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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")
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 190
1 PIEBALDconsult 150
2 BillWoodruff 148
3 DamithSL 140
4 Jochen Arndt 125
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 18 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100