Connecting modem thru code

M

Mota

Hi;
I want to send an AT command (one of a Hayes Command set) to my
modem(installed on Com3)and verify its returned answer,and if the answer is
OK(in ready-to-use condition the answer is ok) ,ask it to dial a
number,using this command:ATDT12345678.
When i use: Open "Com3" For Random As #1 ,a "Device I/O Error" occures,and
in addition,i dont know how to read the returning answer from com3.
Using Windows HyperTerminal,I do this simply and it shows there is no
problem in hardware.
So my problem is to connect to com3 directly and without MSComm Activex
control(that has in turn some limitations in properties and methods),and
reading the answer from it,after sending a command.
Can anyone please help me to do that?
I will be so grateful to you and thank you so much in advance.
 
A

Adrian Jansen

Its fairly tricky to do this without using something like the MsComm
control, but doable.

First you need the right syntax for the Open command:

Open"Com3:" for random as #1 ' you need the colon.

'then all i/o has to be done with Put and Get, 1 byte at a time
'UNTESTED CODE:
Dim ch as byte
Dim k as long
Dim strOut as string
Dim strIn as string

strOut = "ATI" 'Hayes command to return an "OK"

for k = 1 to len(strOut)
ch = asc(mid(strOut,k,1) 'get each character in string
put#1, ,ch 'send out port, note the two commas !
next k

do until ch = 13 'loop waiting for reply, assumes end with a <CR>
Get#1, ,ch
strIn = strIn & chr(ch) 'concat into a string
loop

debug.print strIn 'do whatever with the return

In a working program, of course, you would put all this low level stuff in
subroutines.

Hope this helps.
--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
T

TC

You don't want Random mode. The commands and responses are just plain text,
no? Try normal ASCII read/write mode, as if you were writing to a flat text
file. (I don't recall what the parameters are. Just try treating it like a
flat text file.)

HTH,
TC
 
A

Adrian Jansen

You cant open a port ( or a file for that matter ) for both input and output
simultaenously, unless you open it as Random.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
T

TC

Erk! Sure it doesn't work with Binary? I'll have to stop guessing & do more
testing!

Cheers,
TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top