User Guide

485SDD16-1005 Manual 21
B&B Electronics -- 707 Dayton Road -- Ottawa, IL 61350
PH (815) 433-5100 -- FAX (815) 433-5104
Chapter 5 - Software
This chapter will be divided into two sections. The first section
covers programming techniques for constructing a command string,
receiving data and manipulating data in QuickBASIC. The second
section discusses how to install and run the demonstration program
on an IBM PC or compatible.
Programming Techniques
This section shows steps and examples of programming the
485SDD16 in QuickBasic. If you are programming in another
language, this section can be helpful as a guideline for programming
the 485SDD16.
Read I/O Lines Command
The Read I/O Lines command returns two data bytes that
represents the states of the module's I/O lines. Refer to this
command in Chapter 3 for more information.
Step 1 - Constructing the command string:
Cmnd$ = "!" + CHR$(Maddr) + "RD"
Where Maddr is the address of the module that is to return its I/O
states.
Step 2 - Transmitting the command string:
PRINT #1, Cmnd$;
Step 3 - Receiving the data:
MSIO$ = INPUT$(1,#1)
LSIO$ = INPUT$(1,#1)
Step 4 - Manipulating the data:
MSIO = ASC(MSIO$)
LSIO = ASC(LSIO$)
Step 5 - Determining an I/O's status:
MSstatus = MSIO AND mask
LSstatus = LSIO AND mask
By "ANDing" the value of MSIO or LSIO with the appropriate
mask of an I/O line, the status of the I/O line can be determined.
If the status is equal to zero the I/O line is LOW. If the status is not
equal to zero the I/O line is HIGH. Table 5.1 shows the mask
values for each I/O line.
Step 6 - Repeat Step 5 until the status of each I/O line has been
determined.
22 485SDD16-1005 Manual
B&B Electronics -- 707 Dayton Road -- Ottawa, IL 61350
PH (815) 433-5100 -- FAX (815) 433-5104
Example 5.1 - Determining the status of I/O lines #2 & #10 of
module #5.
Maddr = 5
mask = &H4
Cmnd$ = "!" + CHR$(Maddr) + "RD"
PRINT #1, Cmnd$;
MSIO$ = INPUT$(1,#1)
LSIO$ = INPUT$(1,#1)
MSIO = ASC(MSIO$)
LSIO = ASC(LSIO$)
MSstatus = MSIO AND mask
LSstatus = LSIO AND mask
If LSstatus equals zero then I/O line #2 is LOW. If LSstatus is not
equal to zero then I/O line #2 is HIGH. If MSstatus equals zero then
I/O line #10 is LOW. If MSstatus is not equal to zero then I/O line
#10 is HIGH.
Read Configuration Command
The Read Configuration command reads the module's I/O
definitions, Power-up states, Address, and Turn-around delay
respectively. Refer to this command in Chapter 3 for more
information.
Step 1 - Constructing the command string:
Cmnd$ = "!" + CHR$(Maddr) + "RC"
Where Maddr is the address of the module that is to return its
configuration.
Step 2 - Transmitting the command string:
PRINT #1, Cmnd$;
Table 5.1 - Digital I/O Mask Values
Mask Values
I/O Line # Hexadecimal Decimal
0 & 8 1H 1
1 & 9 2H 2
2 & 10 4H 4
3 & 11 8H 8
4 & 12 10H 16
5 & 13 20H 32
6 & 14 40H 64
7 & 15 80H 128