Opening a COM port in Excel 2000

R

Ron

I'm running Excel 2000 on a Windows 2000 PC. I want to read data from a meter through a serial com port, and store the results in a spreadsheet. I can use the VBA code:

Open "COM1: 9600,N,8,1" for Input As #1
Input #1, A$
Close 1

but only if I first use "HyperTerminal" to initiate the connection to the meter. Why?

If I start HyperTerminal, connect to the meter, and then exit HyperTerminal, the Excel macro works fine (well, almost). If I just start Excel and run the macro, Excel never suceeds in connecting to the meter.

Also, if I put a For-Next loop around the "Input #1, A$" command to keep reading data from the meter, the connection fails after about 25 minutes. Restarting the macro reestablishes the connection just fine. If I put the For-Next loop around the Open/Close portion, then port doesn't time out - but I get garbage data every once in a while

I read KB article 148857 - but I don't see how to read from the COM port, only write to it. The WriteFile function is created in a Declare Function statement, but there isn't a corresponding ReadFile function

Can you offer any help? Thanks, Ron
 
J

jaf

Hi Ron,
What you need is a Control. ActiveX Control to be more precise.
See this. http://www.yes-tele.com/mscomm.html



--
John
johnf 202 at hotmail dot com


| I'm running Excel 2000 on a Windows 2000 PC. I want to read data from a
meter through a serial com port, and store the results in a spreadsheet. I
can use the VBA code:
|
| Open "COM1: 9600,N,8,1" for Input As #1
| Input #1, A$
| Close 1
|
| but only if I first use "HyperTerminal" to initiate the connection to the
meter. Why?
|
| If I start HyperTerminal, connect to the meter, and then exit
HyperTerminal, the Excel macro works fine (well, almost). If I just start
Excel and run the macro, Excel never suceeds in connecting to the meter.
|
| Also, if I put a For-Next loop around the "Input #1, A$" command to keep
reading data from the meter, the connection fails after about 25 minutes.
Restarting the macro reestablishes the connection just fine. If I put the
For-Next loop around the Open/Close portion, then port doesn't time out -
but I get garbage data every once in a while.
|
| I read KB article 148857 - but I don't see how to read from the COM port,
only write to it. The WriteFile function is created in a Declare Function
statement, but there isn't a corresponding ReadFile function.
|
| Can you offer any help? Thanks, Ron
 

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