OPTICAL TUNABLE FILTER OTF-920
9-3
9.2. RS-232C Program
The following program provides an example of the use of the Control Commands for RS-232C
communication. The program is written in Visual Basic and has an input function to set the
wavelength and an output function to read the optical power. The communications port in this
example is Com1 and requires the ActiveX MSComm component to be included in the program.
‘Set Wavelength Routine
‘Subroutine description
Private Sub Wavelength_Set()
‘Sets routine name to
Wavelength_Set
‘Define Variables
‘Comment
Dim ans As String * 30
‘Dimensions ans array as
string of length 30
‘Set Wavelength Subroutine
‘Comment
ans = InputBox(“Required Wavelength (nm)”)
‘Ask user for required
wavelength value
Form1.MSComm1.PortOpen = True
‘Open Port MSComm1 in Form1
of program
Form1.MSComm1.Output = “WA” + ans + Chr$(&HD)
‘Send value of wavelength to
Com port with CR delimiter.
Form1.MSComm1.PortOpen = False
‘Close Port MSComm1 in Form1
End Sub
‘End Subroutine
‘READ POWER (dBm) ROUTINE
‘Subroutine description
Private Sub Power_Read_dBm()
‘Sets routine name to
Power_Read_dBm
‘Define Variables
‘Comment
Dim ans As String * 30
‘Dimensions ans array as
String of length 30
‘Read Power Subroutine
‘Comment
Form1.MSComm1.PortOpen = True
‘Open port MSComm1 of Form1
Form1.MSComm1.Output = “OP” + Chr$(&HD)
‘Set output variable to output
power in dBm (CR delimiter)
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com