8250A Optical Power Meter Operation Manual
4.7.2 USB Sample Programs
4-45
If ret <> OK Then
' If the device is opened incorrectly,
MsgBox "USB_ID 1 OPEN error", vbExclamation
GoTo err_exit
End If
Call mSecSleep(100)
' Waits until the OPM whose USB_ID is set to 1 opens (100 ms).
ret = ausb_open(OPM2, USB_ID2)
' Opens the OPM whose USB_ID is set to 2 and acquires the USB
' handle.
If ret <> OK Then
' If the device is opened incorrectly,
MsgBox "USB_ID 2 OPEN error", vbExclamation
GoTo err_exit
End If
ret = ausb_write(OPM1, "*RST,DW1,R11")
' Transmitting the commands: Initialization, W display, and Trigger
' HOLD
If ret <> OK Then
' If the command is transmitted incorrectly,
MsgBox "USB_ID 1 transmission error", vbExclamation
GoTo err_exit
End If
ret = ausb_write(OPM2, "*RST,DW1,R6")
' Transmitting the commands: Initialization, W display, and Trigger
' HOLD
If ret <> OK Then
' If the command is transmitted incorrectly,
MsgBox "USB_ID 2 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(6, 1) = "OPM1"
Cells(6, 2) = rstr
' Writes the measured data into the specified cell.
Else
' If the command is received incorrectly,
MsgBox "USB_ID 1 receiving error", vbExclamation
End If
ret = ausb_read(OPM2, 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(7, 1) = "OPM2"
Cells(7, 2) = rstr
' Writes the measured data into the specified cell.
Else
' If the command is received incorrectly,
MsgBox "USB_ID 2 receiving error", vbExclamation
End If
err_exit:
ret = ausb_close(OPM1)
' Closes the device.
If ret <> OK Then
' If the device is closed incorrectly,
MsgBox "USB_ID 1 CLOSE error", vbExclamation
End If
ret = ausb_close(OPM2)
' Closes the device.
If ret <> OK Then
' If the device is closed incorrectly,
MsgBox "USB_ID 2 CLOSE error", vbExclamation
End If
ret = ausb_end()
' USB terminates.