Appendix
D
Sample
Programs
Example
Program RS232C Communication
~+**+++*++*+***+*+++++
program
Headerfffff*f*ff**ftt*tft**t**tft
'NEWPORT CORPORATION
'2832-C to RS232 Communication Program
-
an example program
'This program is designed to show you how to write a simple
'program that will write commands and read query responses to and
'from the 2832-C Dual-Channel Power Meter via the RS-232 port on the
'Rear Panel and the RS-232 port on an IBM
PC/AT or compatible. The
'Program was written in MICROSOFT GWBASIC on an IBM AT compatible.
'Written By: Darwin D. Smith
'
Date: April 28, 1993
~*f**+**++*+***+f++ttttttt
End of Header
fffff**ffffffff********tt
'Beginning of program
'Open COM port with the following specifications:
'COM port 1, 9600 baudrate, no parity, 8 data bits
&
1 stop bit
OPEN "COM2:9600,N18,1" FOR RANDOM AS #1
GOSUB 2000 'Draw header on the screen
GOSUB 3000 'Process user input
CLOSE #1 'Close the COM file
END 'End of program
'Main.Screen: Draw the main screen.
CLS
LOCATE 1, 20: PRINT
"N E W P
0
R T C
0
R P
0
R A T I0 N"
LOCATE 2, 20: PRINT "2832-C to RS-232 Communication Program"
LOCATE 3, 20: PRINT
"
q or Q to Quit"
RETURN
'Enter.User.Commands: Get and interpret the user's commands.
WHILE (1) 'Get and process user input until Q or q is input.
RS2320UTS
=
""
'Clear RS2320utS string
LINE INPUT RS2320UTS 'Get the user input
IF
RS2320UTS
=
"Q"
OR RS2320UTS
=
"q" THEN RETURN ELSE GOSUB 4000
'Assume strings ending with
"?"
are queries
IF INSTR(RS2320UT$,
"?")
=
0 THEN GOT0 3090
GOSUB 5000
'END IF
WEND
RETURN
'Write.RS232.String: Write the string RS2320UTS to the RS232 port
PRINT #I, RS2320UTS 'PRINT
#
appends <CR><LF> to the string
RETURN
'Read.RS232.String: Read a string from the 2832-C RS232 port.
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com