94
────────────────────────────────────────────────────
7.7 Sample Program
────────────────────────────────────────────────────
.7 Sample Program
.7.1 To be prepared in Visual Basic 5.0/6.0
These sample programs are written in Microsoft Visual Basic 5.0 and 6.0.
・The following are used for communication:
For RS-232C communication: MSComm from Visual Basic Professional
For GP-IB communication: National Instruments GP-IB Board, Driver
and Module for Visual Basic
・During communications, the terminator setting is supposed to be as
follows:
RS-232C: CR+LF
GP-IB: LF
Visual Basic is a registered trademark of Microsoft Corporation.
RS-232C Communications
(Using Microsoft Visual Basic Professional MSComm)
■Simple Resistance and Vooltage Measurement
Imports measured values 10 times, and saves measurements in a text file.
Private Sub MeasureSubRS()
Dim recvstr As String ’Receiving char string
Dim i As Integer
MSComm1.Settings = "9600,n,8,1" ’Comm port setting
MSComm1.PortOpen = True ’Open a port
Open App.Path & "\data.csv" For Output As #1 ’Open a text file for saving
MSComm1.Output = ":HEAD OFF" & vbCrLf ’If headers are OFF
MSComm1.Output = ":MODE RV" & vbCrLf ’Resistance and Voltage
Measurement Mode
MSComm1.Output = ":HOLD OFF"& vbCrLf ’Measurement Hold OFF
For i = 1 To 10
MSComm1.Output = ":MEAS:BATT?" & vbCrLf ’Send Command to import
the most recent measurement
recvstr = "" ’From here on, continue receiving
until an LF code occurs
While Right(recvstr, 1) <> Chr(10)
recvstr = recvstr + MSComm1.Input
DoEvents
Wend
recvstr = Left(recvstr, Len(recvstr) - 2) ’Delete the terminator (CR+LF)
Print #1, Str(i) & "," & recvstr ’Write to the file
Next
Close #1
MSComm1.PortOpen = False
End Sub