8230 Optical Power Meter Operation Manual
4.7.2 Program Example 2
4-25
    Dim OPM1 As Long 'USB handle
    Dim OPM2 As Long 'USB handle
    Dim myID1 As Long 'MYID which is set in OPM
    Dim myID2 As Long 'MYID which is set in OPM
    Dim ret As Long 'Driver return value
    Dim siz As Long 'Number of the received data characters 
    Dim rstr As String 'Receiving buffer of the measurement data
 
    myID1 = 1 'First MYID
    myID2 = 2 'Second MYID
 
    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, myID1) 'Opens  the  OPM  of  the  first  MYID  and
obtains the USB handle.
    If ret <> OK Then 'If the device is opened incorrectly
        MsgBox "MYID 1 OPEN error", vbExclamation
        GoTo err_exit
    End If
    Call mSecSleep(100) 'Waits until the OPM of the first MYID
opens (100 ms).
    ret = ausb_open(OPM2, myID2) 'Opens  the  OPM  of  the  second  MYID  and
obtains the USB handle.
    If ret <> OK Then 'If the device is opened incorrectly
        MsgBox "MYID 2 OPEN error", vbExclamation
        GoTo err_exit
    End If
 
    ret = ausb_write(OPM1, "*RST,DW1,R11")
'Sending the commands: Initialization, W
display, and Trigger hold.
    If ret <> OK Then 'If the command is sent incorrectly
        MsgBox "MYID 1 transmission error", vbExclamation
        GoTo err_exit
    End If
    ret = ausb_write(OPM2, "*RST,DW1,R6")
'Sending the commands: Initialization, W
display, and Trigger hold.
    If ret <> OK Then 'If the command is sent incorrectly
        MsgBox "MYID 2 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(5, 1) = "OPM1"
        Cells(5, 2) = rstr 'Writes the measurement data into the spec-
ified cell.
    Else 'If the command is received incorrectly
        MsgBox "MYID 1 receiving error", vbExclamation
    End If
    ret = ausb_read(OPM2, rstr, 50, siz)