Project
ing time is spent here during its execution. Listing 2 is the
routine that is called when a character is received into the
serial buffer of the computer from the interface board.
After the computer tells the interface board to begin
analyzing, the interface board starts to send data samples
to the computer. Every data sample received is handled
by the routine in Listing 2.
Listing 2 is an event procedure that is associated with
a control called “CommX1.” CommX1 provides the
means for your VB program to use the serial port of the
computer for communication. CommX1 is a third party
tool that does not come with VB and must be added to the
programming environment before it can be used. VB
comes with its own Comm Control, but it is only available
with the more expensive versions of the program. The VB
“learning addition” is what most beginners start out with,
but does not have this needed tool. One of the nice fea-
F
o
r
E
l
e
c
t
r
o
n
i
c
s
NUTS & VOLTS
E
v
e
r
y
t
h
i
n
g
tures of VB though, is that it’s designed to support
programming tools from other vendors. Lucky for us
CommX1 can be downloaded for free from MCS
Electronics so that even the beginner versions of VB
can be used to develop some respectable control
applications.
After the computer starts the analyzing process by
sending the proper control word to the interface board, it
waits until a data value is received at the serial port and
then processes it. Note.1 of Listing 2 is where the serial
data is retrieved and stored at variable “volt.” Between
note.1 and note.2, the ASCII data from the interface
board must be converted into a numeric value so a voltage level can be calculated from the ADC value. Once a
voltage value is obtained, it is displayed on the computer
monitor.
Between note.2 and note. 3, the voltage data is used
to calculate where to plot the voltage measurement on the graph. The program uses
the default VB unit of screen measurement
called “twips.” Each vertical volt designation is equal to 500 twips of resolution. The
discharge graph time resolution is in the
horizontal direction or X plot position, while
the voltage measurement is in the vertical
direction or Y plot position. If the voltage
measured is five volts, the Y plot position
will be 2,500 twips up from the zero level.
Between note. 4 and note. 5, the
program will set the first X plot point at the
zero time designation and the Y plot point
will depend on the voltage value.
Between note. 5 and note. 6 is where the
graph gets drawn by calculating a Y plot
point (voltage) from each measurement,
moving the X plot point (time) a defined
number of twips to the right, and then connecting the plot points using the line
method. This will continue until it reaches
the end of the graph, is stopped by the user,
or falls below the cut-off voltage. This section of code is also responsible for filling a
table with voltage values that can be printed for record keeping (more on this later).
Code between note. 6 and note. 7 is
executed when plotting reaches the end of
the graph or the battery voltage falls below
the cut-off level. The program will then halt
testing by sending the “stop” command to
the interface board and closing the serial
connection.
Listing 2. VB Serial Communications sub-routine.
Private Sub CommX1_OnReceive(ByVal DATA As String)
Dim volt As Integer
Dim volt2 As Single
Dim volt3 As String
Dim volt4 As Single
Dim volt5 As Integer
Static x As Integer
volt = Val(DATA) ‘**NOTE 1**
volt2 = (volt * 0.004888) * (2)
volt3 = Str(volt2)
volt3 = Left$(volt3, 5)
Label28.Caption = volt3
volt4 = Val(volt3) ‘**NOTE 2**
volt5 = volt4 / 0.01 ‘convert to twips
volt5 = volt5 * 5 ‘1volt=500 twips ‘**NOTE 3**
If check = 0 Then ‘**NOTE 4**
Form1.CurrentX = 1000
Form1.CurrentY = 6000 - volt5
check = 1
Else ‘**NOTE 5**
vertical = 6000 - volt5
Line -(Form1.CurrentX + 50, vertical)
MDIForm1.frm.grdTable.Row = Tr
MDIForm1.frm.grdTable.Col = Tc
MDIForm1.frm.grdTable.Text = volt3
Tr = Tr + 1
If Tr = 13 Then
Tc = Tc + 1
Tr = 1
End If
x = x + 1
If x = 120 Then ‘**NOTE 6**
x = 0
CommX1.SEND “Stop” + Chr(13)
CommX1.Close
Command2.Enabled = False
Command3.Enabled = False
MDIForm1.mnuPrint.Enabled = True
Form1.Caption = Format$(Now, “mmmm dd yyyy h:mm a/p”)
MDIForm1.frm.Caption = Format$(Now, “mmmm dd yyyy h:mm a/p”)
MDIForm1.frm.grdTable.Enabled = False
Label36.Caption = “STOPPED”
Label36.ForeColor = &HFF&
Exit Sub
End If
End If
If (volt4 < Cutoff) Or (volt4 = Cutoff) Then ‘** NOTE 7**
Call Command3_Click
End If
End Sub
Using the Analyzer
46
Using the analyzer is pretty simple. You
first load the computer program while mak-
JULY 2005