I need to be able to initiate a serial terminal through a VBS app. I know
that the supplied mscomm32.ocx ActiveX control allows this, but I can't find
any samples of how this would be done in VB Script. I've seen the VB sample
on the msdn site, but not being a VB programmer, it dont make much sense.
Could some kind soul please give me some example code in VBScript? I need to
open the serial port, read/write some data to it, and the close it.
Ta,
B.
dim comm
sub main()
dim instring
set comm=CreateObject("MSCOMMLib.MSComm.1")
' set the comm port
comm.CommPort = 4
' set the speed and parity
comm.Settings = "9600,N,8,1"
' Tell the control to read entire buffer when Input
' is used.
comm.InputLen = 0
' Open the port.
comm.PortOpen = True
' Send the attention command to the modem.
comm.Output = "AT" + Chr(13)
' Wait for data to come back to the serial port.
' may want to time out here
'Do
' hs.waitevents
'Loop Until comm.InBufferCount >= 2
' Read the "OK" response data in the serial port.
'Instring = comm.Input
' Close the serial port.
comm.PortOpen = False
end sub
call main
But get the error "class is not licensed for use" ??????
B.
"Ben Holko" <b...@globalcenter.net.au> wrote in message
news:96b16.30522$xW4.2...@news-server.bigpond.net.au...
Instead of using set comm=CreateObject("MSCOMMLib.MSComm.1")
Try:-
Add the Microsoft Comm Control 6 as a component, and add an instance of it
to your form, this will become MSComm1.
then code
MSComm1.CommPort = 4
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = "AT" + Chr(13)
Do While MSComm1.InBufferCount <=2
Loop
Instring = MSComm1.Input
MSComm1.PortOpen = False
This works fine.
Also because you used CreateObject you can run into problems if you want to
install your app on another machine because it will not compile your app
with the MSCOMMLib, however, if you include it as a component in your app
the P&D Wizard will send a copy of it with your distribution disks.
Hope this helps
Mark
"Ben Holko" <b...@globalcenter.net.au> wrote in message
news:Ujc16.30587$xW4.2...@news-server.bigpond.net.au...
Is this client-side code, or server side? If server-side, the best approach
is to create an ActiveX EXE in VB that performs your serial comms, and call
this EXE from your VS. An alternative would be to call XMCommVBA.ocx
(download from my homepage), and use CeateObject with it. The mComm example
code on my homepage shows a way to call MSComm or XMComm using CreateObject
(VB6 source code). However, MSComm is not licensed for use outside of
Visual Studio compiled applications, so using it from VB script may be a
challenge -- I haven't tried. XMCommVBA has no licensing restrictions.
BTW, I have example code in my book (see below) that is similar to the
ActiveX EXE that I was suggesting. In fact, even though it was designed for
a slightly different purpose, the ShareComm example should work without
modification when called from server-side script.
--
Richard Grier (Microsoft Visual Basic MVP)
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO 80228
303-986-2179 (voice)
303-986-3143 (fax)
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition ISBN 1-890422-25-8 (355 pages).
For information look on my homepage at http://www.hardandsoftware.net.
Use the Books link to order. For faster service contact the publisher at
http://www.mabry.com/vbpgser.
dim comm
sub main()
dim instring
set comm=CreateObject("MSCOMMLib.MSComm.1")
end sub
call main
B.
.