Sending commands to the ADR101 using a terminal or computer running a terminal emulation program is simply a matter of typing in commands and pressing return. With BASIC it can be just as simple. The ADR101 is connected to the computer via a serial cable and BASIC treats the ADR101 as a serial file. Before commands can be sent to the ADR101 this serial file must be opened and initialized. This should be done at the start of any program that is to access the ADR101.The command to open a serial file is shown below;
10 OPEN "COM1:9600,n,8,1,CS,DS,RS" AS#1
This line opens a serial file and labels it as serial file #1. This allows access to the ADR101 using PRINT#1 and INPUT#1 commands.
Sending commands in BASIC to the ADR101 can be done using PRINT#1 commands. For example, sending an RA0 command could be done as shown below;
20 PRINT#1, "RA0"
Extra spaces inside the quotes are ignored by the ADR101. Avoid sending
commands on consecutive lines because a carriage return
20 PRINT#1, "CPA00000000" 30 REM FORCES40 PRINT#1, "SETPA0"
Variable names may also be used with PRINT#1 commands. One example of this shown below. This program configures PORT A as output and the increments it from 0 to 255.
10 OPEN "COM1:9600,n,8,1,CS,DS,RS" AS#1
20 PRINT#1, "CPA00000000"
30 FOR X = 0 to 255
40 PRINT#1, "MA",X
50 NEXT X
60 END
When reading analog inputs or the digital port, data is sent from the ADR101 to the computers serial buffer. This data can be retrieved using INPUT#1 commands. The INPUT#1 command should be used following PRINT#1 commands if data is expected to be sent by the ADR101. If a single piece of data is expected then one variable name should be used with the INPUT#1 command. If eight pieces of data are to be received as with the RPA command then eight variable names must be used with the INPUT#1 command. Examples of both cases are shown below;
20 PRINT#1, "RA0"
30 INPUT#1, ANADAT
40 PRINT#1, "RPA"
50 INPUT#1, PA7,PA6,PA5,PA4,PA3,PA2,PA1,PA0
The variable names used in the INPUT#1 commands now contain the data sent by the ADR101. The data can now be scaled, printed, displayed, saved or whatever is required by the application.
A complete BASIC program which reads analog port 0 and sets PA0 if the analog port is above 50% ( 2.5 volts ) is shown below;
10 OPEN "COM1:9600,n,8,1,CS,DS,RS" AS#1 ;opens and configures serial file 20 PRINT#1, "CPA11111110" ;configures PA0 as output 30 REM FORCES40 PRINT#1, "RESPA0" ;resets PA0 50 REM FORCES 50 PRINT#1, "RA0" ;sends RA0 command 60 INPUT#1, AN0 ;receives data into variable AN0 70 IF AN0>50% then PRINT#1, "SETPA0"' ;sends SETPA0 command if 80 GOTO 50 AN0>50% and returns to line 50 90 PRINT#1, "RESPA0" : GOTO 50 ;resets PA0 and returns to 50