8230E Optical Power Meter Operation Manual
4.7.1 Program Example 1
4-23
Dim rstr As String 'Receiving buffer of the measurement data
Dim siz As Long 'Number of characters of the received data
myID = 1 'First MYID
row = 5 'Displays from the 5th row.
mcnt = 10 'Specifies the number of times the measure-
ment is performed as 10.
ret = ausb_start(10) 'USB initialization, time-out: 10 seconds
If ret <> OK Then 'If the USB initialization is performed
incorrectly
MsgBox "USB initialization error", vbExclamation
GoTo err_exit
End If
Call mSecSleep(100) 'Waits for the USB initialization (100 ms).
ret = ausb_open(OPM1, myID) 'Opens the OPM of the first MYID and
obtains the USB handle.
If ret <> OK Then 'If the device is opened incorrectly
MsgBox "device OPEN error", vbExclamation
GoTo err_exit
End If
ret = ausb_write(OPM1, "*RST,DW1,M1")
'Sending the commands: Initialization, W
display, and Hold.
If ret <> OK Then 'If the command is sent incorrectly
MsgBox "transmission error", vbExclamation
GoTo err_exit
End If
For cnt = 1 To mcnt Step 1
enterF = 0 'Sets the input flag of the 'ENTER button
to OFF.
Do While 1 'Waits for the ENTER button to be pressed.
If enterF = 1 Then Exit Do
'Exits if the ENTER button is pressed.
DoEvents
Loop
ret = ausb_write(OPM1, "*TRG")
'Sending the commands: Measurement trig-
ger.
If ret <> OK Then 'If the command is sent incorrectly
MsgBox "transmission error", vbExclamation
GoTo err_exit
End If
ret = ausb_read(OPM1, rstr, 50, siz)
'Reads the measurement data: Up to 50 char-
acters
If ret = OK Then 'If the command is received correctly
rstr = Left$(rstr, siz - 1)
'Deletes the terminator LF.
Cells(row, 1) = rstr 'Writes the measurement data into the spec-
ified cell.
row = row + 1 'Moves the cell position in which the mea-
surement data is written.
Else 'If the command is received incorrectly
MsgBox "receiving error", vbExclamation
Exit For
End If