Reading scale output into excel

A

Thread Starter

Anonymous

A scale has an RS232 output that transmits the weight (ascii) when a button is pressed on the scale. I want to read this value at the PC COM port and place it into a worksheet cell. Why won't this work?

handle = FreeFile(0)
Open "COM2" For Input As handle
For SampleNo = 1 To nNumSamples
Input #handle, sLine
Sheet1.Cell(SampleNo+6,3).Formula = sLine
Next

To test this I connected my COM1 port to my COM2 port. Opening hyperterminal for both ports showed that my connection was fine. With hyperterminal transmitting out COM1 and COM2 receiving, the Open statement works fine, but when the Input # statement executes I get the following as soon as I enter a single character.

Run time Error 52
Bad file name or number

Ports are configured identically.
 
W
Well, one of the things that is true is that you are in violation of Solaia's patent if you do that without negotiating a royalty payment.

Walt Boyes

---------------------
Spitzer and Boyes LLC
"consulting from the engineer
to the distribution channel"
21118 SE 278th Place
Maple Valley, WA 98038
Ph. 425-432-8262
Fx. 253-981-0285
[email protected]
www.spitzerandboyes.com
--------------------------
 
I would start at the physical layer. Com ports are DTE devices. For a DTE device to talk with another DTE device you must use a rollover cable.

Next, VB has a com tool known as MSComm. This tool is only available in the higher level versions of VB ie. VB professional etc.

Look for example of this on the web.
 
As far as I know, you cannot access directly comm ports on a Windows environment. You need to call API or use an ActiveX component (Mscomm32.ocx)to be able to read and/or write from/to your comm ports.

Hope this helps,
 
Check the value of FreeFile(0), you cannot open a file with number of 0. Also use (line input #1,z$). This way it will read to the (cr-lf)
I read my com port in a loop, because there are unexpected

open ( this that)
do
line input #1,a$
if len(a$) > 1 then print a$
(mouse or key) events
loop

Timing is not a concern within the do-loop
This holds true; especially with MODBUS
 
D

Dave Johnson

Why re-invent the wheel, I know of a great VB control that works with Excel, it is about $125 to register, and works with a few simple Open() and Close() and Put() and and Get() commands included in the control. It's called WSC Serial Comms Driver for VB. From there you just use some code to place the data into whatever cell you want (the help file's in Excel has examples on cell manipulation). You should also get Ultima Serial, it has a nice timer that you can use to set how frequent the data is read in, although you can trigger this by pushbutton in the spreadsheet as well. It works great with Excel 2000.

Regards,

Dave

Let me know if you need help in getting the Excel app up and running.
 
I'm new to doing external things programmatically; for my current & first project I'm getting familiar with controlling LED's via the Comm Port.

I, too, am looking for a (free) way to do this in MS-Office VBA as opposed to VB. Apparenly the only way is with that MSComm reference but unfortunately it (apparently) isn't compatable with VBA. I and many others get stuck at the Licensing error. :-(
 
W

Wayne Gordon

I wrote a VBA app which does what you described. The scale operator pushs a 'PRINT' button on the scale. The VBA code receives the data stream, pulls out the necessary info, and places it into a cell on the Excel spreadsheet. It also checks the cell for data already present, and if so, places it in the next available cell. If you still have a need, let me know.

Wayne
 
Top