JMI Telescopes MAX Computer ユーザーズマニュアル

ページ / 16
 
Page 15 
 
Appendix D — Sample BASIC Program Listing 
 
The following program listing has been tested on numerous MS-DOS compatible computers using both GW-BASIC and Q-
BASIC.  While all efforts have been made to ensure error-free code, the user is solely responsible for the accurate entry  
and operation of this program. 
 
100 '*************************************************************************** 
110 '**  This BASIC program reads and displays encoder positions directly     ** 
120 '**  from the RS-232C serial port of the JMI NGC-MAX v3.50 or later       ** 
130 '**  Copyright 1996-2005 by Jim's Mobile Inc.                             ** 
140 '*************************************************************************** 
150 ENC(1)=4096: 'Defines telescope Azm/RA encoder resolution 
160 ENC(0)=4000: 'Defines telescope Alt/DEC encoder resolution 
170 PORT$="COM1": 'Defines which serial port is connected to the NGC-MAX 
180 CLS:PRINT "Make sure the NGC-MAX is on - then press the SPACE bar." 
190 K$=INKEY$:IF K$="" THEN GOTO 190: 'Waits for user to press a key 
200 IF K$=CHR$(27) THEN GOTO 370: 'If ESC is pressed, jumps to line 370 
210 OPEN PORT$+":9600,N,8,1,RS,CS,DS" AS #3: 'Opens serial port 
220 DEFP$="+00000"+CHR$(9)+"+00000": 'Defines the default position response 
230 P$="":PRINT #3,"Q";: 'Asks NGC-MAX for encoder positions 
240 K$=INKEY$:INPUT #3,P$: 'Reads keyboard/serial port 
250 IF K$ = CHR$(27) THEN GOTO 370: 'If ESC is pressed, jumps to line 370 
260 IF P$="" THEN GOTO 230: 'Waits for input from keyboard or serial port 
270 IF LEN(P$)<8 THEN P$=DEFP$: 'If input not complete, sets to default 
280 AZM$=LEFT$(P$,6): 'Extracts the Azimuth/R.A. encoder position 
290 ALT$=MID$(P$,8,6): 'Extracts the Altitude/Dec. encoder position 
300 A=-VAL(AZM$):GOSUB 400: 'Jumps to line 400 to interpret Azimuth angle 
310 RA$=A$: 'Sets variable RA$ equal to the Azimuth angle 
320 A=VAL(ALT$):GOSUB 400: 'Jumps to line 400 to interpret Altitude angle 
330 DEC$=A$: 'Sets variable DEC$ equal to the Altitude angle 
340 LOCATE 10,19:PRINT "Azm/R.A.= ";RA$: 'Displays the Azimuth/R.A. angle 
350 LOCATE 10,46:PRINT "Alt/DEC.= ";DEC$: 'Displays the Altitude/Dec. angle 
360 GOTO 230: 'Goes back to line 230 to check positions again 
370 CLOSE #3:LOCATE 20:PRINT "Exiting program.": 'Closes the serial port 
380 SYSTEM: 'and EXITS the program 
390 '*** This subroutine changes the raw encoder data into angular form. *** 
400 AX=(AX=0): 'Toggles variable AX to indicate which axis 
410 A=A*360/ENC(-AX): 'Changes raw encoder tic value to an angle 
420 IF A>359 THEN A=A-360:GOTO 420: 'Makes sure angle is less than 360 
430 IF A<-359 THEN A=A+360:GOTO 430: 'Makes sure angle is greater than -360 
440 IF NOT AX AND A>180 THEN A=A-360: 'Makes sure Altitude is within -180 to 180 
450 IF A<0 AND AX THEN A=360+A: 'Makes sure Azimuth is greater than zero 
460 A=A+.0051:A=INT(A*10000)/10000: 'Puts angle in a 2 decimal place format 
470 S=SGN(A):A$="000"+MID$(STR$(A),2): 'Temporarily adds leading zeros 
480 A=0:FOR X=1 TO LEN(A$): 'Starts looking for decimal place in angle 
490 IF MID$(A$,X,1)="." THEN A=X: 'When decimal found, marks with variable A 
500 NEXT X:IF A=0 THEN A$=A$+".0":A=LEN(A$)-2: 'Adds decimal value if absent 
510 A$=MID$(A$,A-3,6): 'Extracts the angle in proper format 
520 IF LEN(A$)<6 THEN A$=A$+"0": 'Makes sure second decimal place is present 
530 S$="+":IF S<0 THEN S$="-": 'Sets the sign as plus or minus for angle 
540 IF NOT AX THEN A$ = S$ + A$: 'Adds sign to the Altitude angle only 
550 RETURN: 'Returns the program to line 310 or 330