Model 4000D: Digital Amplifier

 

 
 

The SMT 4000D gage amplifier makes a wide range of data available through the serial port. The programmability of applications like Microsoft Excel and Word make it possible to automate setup and data collection using the serial port. This document shows how to automatically gather thickness readings from a 4000D amplifier directly into an Excel spreadsheet. We have supplied the example spreadsheet and supporting system files on floppy disk.

System Requirements
To run this example you must have:

  • Microsoft Excel version 7.0 or later (e.g., from the Microsoft Office 95 or Office 97 suite),
  • A 32 bit Windows operating system (95, NT, etc.), and
  • A serial port connected to a 4000D amplifier. Typically, you will need a serial cable, a "null modem" adapter, and a female-female gender changer to make the connection.

Loading the Example
Simply copy the file SMTserial.dll from the floppy to your Windows system directory, typically \windows\system. This file is a library of serial communication functions which the spreadsheet will use to talk to the amplifier.

The example spreadsheet is called "4000D Demo.xls." You may either copy this file to your hard disk or run it directly from the floppy.

Double click on "4000D Demo.xls." Microsoft Excel should load the spreadsheet and immediately try talking to the amplifier. One of three things will happen at this point. If the amplifier is connected to COM2: and has Òcomputer modeÓ enabled, you will get a message box, "Connected to gage..." Click OK to continue. If you are using a different serial port or if the amplifier is not communicating, you will get an error message.

Your computer may be using another serial port and may not even have a port called COM2:. In that case you will get a message box, "Can't connect to gage on com2:". Click on OK, then click on the tab labeled "SMT Gage Driver" at the bottom of the "4000D Demo.xls" window. You will see the following VBA code:
'Copyright 1997, Sharpe Measurement Technology, Inc.
'Gage driver example, Mark Hill, 11/20/97
Option Explicit

'Put the COM port and baud rate for your gage connection here:
Const serial_port = "com2:"
Const baud_rate = 9600

Change "com2:" to Òcom1:" or whatever port you are using, close the workbook (or exit Excel) saving changes, and try loading it again.

If the serial port is OK but the amplifier does not respond within one second, you will get a message box, "No response from gage." The amplifier may not be in "computer mode," or it may not be connected properly. Remember that you must have a Ònull modemÓ adapter between the computer and the amplifier. To try communicating again, you must close the workbook or exit Excel and load "4000D Demo.xls" again.

Running the Example
After you get the "Connected to gage..." message, you are ready to begin collecting data. Select the tab labeled "Sheet1" at the bottom of the "4000D Demo.xls" window. Notice that there is now a menu item labeled "Online." To begin taking readings, select "Start" from the "Online" menu. Every second, the current time and the thickness reading from the amplifier will appear in a new row in columns A and B. To stop the process, select "Stop" from the "Online" menu.

Changing the Example
The example is written in Visual Basic for Applications (VBA). To inspect the code, select the "SMT Gage Driver" tab.

Here is how it works.
The procedure that takes the readings is called get_reading. Scroll down until you find:


'Puts the current time in the current cell and the result of
'the "M" command in the cell to the right of the current cell.
'It schedules itself to run again in one second if "running" is true.
Sub get_reading()
If running Then
ActiveCell.Value = Format(Now, "hh:mm:ss")
'Convert um to inches by dividing by 25400.
ActiveCell.Offset(0, 1).Value = Val(gage_IO("M")) / 25400#
ActiveCell.Offset(1, 0).Activate
Application.OnTime Now + TimeValue("00:00:01"), "get_reading"
End If
End Sub

The "Online Start" menu selection sets "running" to true and calls get_reading. Get_reading does the following:

  1. Puts the current time in the current cell,
  2. Reads the current thickness (the result of the "M" command) in the cell to the right of the current cell,
  3. Moves the active cell down one row, and
  4. Schedules get_reading to be called automatically one second from the current time using Application.OnTime.

You can increase the time between readings by editing the TimeValue("00:00:01") in the Application.OnTime line.

Other Possibilities

Using Excel macros or VBA, you can do many other things with the collected data. You could automatically graph it, compute statistics on it, etc.

It is also possible to send data to the gage using the gage_IO procedure. For example you can set the master value to 25.4 microns with gage_IO("P8,254.").

You can also use the gage_IO procedure in Visual Basic version 4 or later. Copy the code from the spreadsheet and paste it into a VB code module. Except for get_reading, which refers to the Excel ActiveCell and Application objects, the procedures will work in your VB programs.

Feel free to contact SMT for technical support. We can provide tips on using and extending this example or we can quote software development services for more extensive applications.