8.8 Sample Programs
169
8
Chapter 8 RS-232C/GP-IB/LAN Interfaces
(4) External Trigger Measurement 2
Measure and import according to external triggering of the instrument (TRIG key or EXT I/O TRIG terminal
input), and save measurements in a text file.
(The instrument imports the most recent measurement by trigger input timing with the continuous measure-
ment state)
Private Sub MeasureTrig2SubRS()
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 = ":TRIG:SOUR IMM" & vbCrLf 'Select internal triggering
MSComm1.Output = ":INIT:CONT ON" & vbCrLf 'Continuous measurement ON
'Clear confirmation of External I/O TRIG input
MSComm1.Output = ":IO:IN?" & vbCrLf
recvstr = ""
While Right(recvstr, 1) <> Chr(10)
recvstr = recvstr + MSComm1.Input
DoEvents
Wend
For i = 1 To 10
'Wait for External I/O TRIG input
Do While 1
MSComm1.Output = ":IO:IN?" & vbCrLf
recvstr = ""
While Right(recvstr, 1) <> Chr(10)
recvstr = recvstr + MSComm1.Input
DoEvents
Wend
If Left(recvstr, 1) = "1" Then Exit Do
DoEvents
Loop
MSComm1.Output = ":FETCH?" & vbCrLf 'Send ":FETCH?" to import the most recent mea-
surement
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