7351 Series Digital Multimeter Operation Manual
6.3.4 Sample Program (RS-232)
6-10
UserForm1.MSComm1.Output = "*TRG" & Chr(10)
'*TRG: Triggers.
Call rx_prompt
'Receives a prompt.
Do
UserForm1.MSComm1.Output = "MSR?" & Chr(10)
'MSR?: Sends the command for reading the measurement event register.
Call rx_data(msr, 5)
'Reads the measurement event register (5 characters) and stores them in msr.
sts = Val(msr) And 256
'Converts the 5 characters, which are stored in msr, to a numerical value and stores
the value in sts.
Loop While (sts <> 256)
'Repeats until EOM is set.
UserForm1.MSComm1.Output = "MD?" & Chr(10)
'MD?: Sends the command for reading the measured data.
Call rx_data(dt, 14)
'Reads the measured data (14 characters) and stores them in dt$.
Cells(1, 1) = "'" & Left(dt, 12)
'Displays the measured data for a cell.
UserForm1.MSComm1.PortOpen = False
'Closes the port.
--------------------------------------------------------------------------------
Private Sub rx_prompt()
'Subroutine procedure for receiving a prompt
Dim prompt As String
Do
'Repeats.
If UserForm1.MSComm1.InBufferCount >= 5 Then
'If there is received data, it is read.
prompt = UserForm1.MSComm1.Input
'Reads data from the receiving buffer.
If InStr(prompt, "=>") Then
'Checks whether to have received "=>".
Exit Do
'Exits Do While Loop.
End If
'Terminates If.
End If
'Terminates If.
Loop
'Terminates Do While Loop.
End Sub
'Terminates the subroutine procedure.
--------------------------------------------------------------------------------
Private Sub rx_data(dt As String, dt_len As Integer)
'Subroutine procedure for receiving data and a prompt
Do
'Repeats.
If UserForm1.MSComm1.InBufferCount >= (5 + dt_len) Then
'If there is received data, it is read.
dt$ = UserForm1.MSComm1.Input
'Reads data from the receiving buffer.
If InStr(dt, "=>") Then
'Checks whether to receive "=>".
dt = Mid(dt, 2, dt_len)
'Separates a prompt from received data.
Exit Do
'Exits Do While Loop.
End If
'Terminates If.
End If
'Terminates If.
Loop
'Terminates Do While Loop.
End Sub