8250A Optical Power Meter Operation Manual
4.7.2 USB Sample Programs
4-43
mcnt = 10
' Sets the measurement count to 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, USB_ID)
' Opens the OPM whose USB_ID is set to 1 and acquires 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")
' Transmitting the commands: Initialization, W display, and Hold.
If ret <> OK Then
' If the command is transmitted 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 pressing the ENTER button.
If enterF = 1 Then Exit Do
' Exits if the ENTER button is pressed.
DoEvents
Loop
ret = ausb_write(OPM1, "*TRG")
' Transmitting the commands: Measurement trigger
If ret <> OK Then
' If the command is transmitted incorrectly,
MsgBox "transmission error", vbExclamation
GoTo err_exit
End If
ret = ausb_read(OPM1, rstr, 50, siz)
' Reads the measured data: Up to 50 characters
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 measured data into the specified cell.
row = row + 1
' Moves the cell position in which the measured data is written.
Else
' If the command is received incorrectly,
MsgBox "receiving error", vbExclamation
Exit For
End If
Next cnt
err_exit:
ret = ausb_close(OPM1)
' Closes the device.
If ret <> OK Then
' If the device is closed incorrectly,
MsgBox "device CLOSE error", vbExclamation
End If
ret = ausb_end()
' USB terminates.
If ret <> OK Then
' If the USB terminates incorrectly,