Why Use the Standard Driver Software?
Compatible Hardware and Software
Overview of the F
Software Considerations
Installing the Standard Driver Software
Chapter Objectives
What the P
What's on the Diskette
Installing the Standard Driver Hardware and Software
Planning Y
Chapter Objectives
Include Files
Overview of the F
P
rogramming Considerations
Using the F
Chapter Objectives
Using Open_StdDrv()
Communicating on DH485 with the 6001F2E Standard Driver
Using Appl_StdDrv()
Using Send_StdDrv()
Using Get_ErrMsg()
Using Close_StdDrv()
Compiling, Linking, and Configuring Your Application Program51 . . .
Chapter
Compiling and Linking Y
Configuring Y
Application P
Sample P
PLC2 Unprotected R
PLC2 Unprotected W
Diagnostic L
Diagnostic Counter R
Diagnostic Status
Diagnostic Counter R
Specifying Message P
Chapter Objectives
F
Message P
Supported Command Set
Diagnostic Counters R
Diagnostic L
Diagnostic R
Diagnostic Status
Unprotected R
Install the 6001-F2E Standard Driver software
Communicate with DH-485 stations via the 6001-F2E Standard Driver
software
Use this manual and the 6001-F2E Standard Driver software if any of
your application programs require information from devices such as the
SLC-500 programmable controller. We assume you are familiar with the
DOS operating system and C programming language.
See the following publications for information about communicating on
the DH-485 network.
Refer
to this manual
PC DH-485 Interface Module Installation
Data (publication 1784-2.23)
Data Highway/Data Highway Plus
Protocol and Command Set User
Manual (publication 1770-6.5.16)
The Standard Driver Software (cat. no. 6001-F2E) for the 1784-KR
Interface Module lets you communicate directly to SLC-500
programmable controllers and other devices on the DH-485 network. You
use a standard set of function calls to communicate with DH-485 stations.
These function calls let you define your own message packets or request
pre-defined message packets included in the software. See page 4-2 for
more information about the message packets.
You can use the following hardware devices with the 6001-F2E Standard
Driver software:
1784-T35 Plant Floor Terminal
1784-T50 Industrial Terminal
6120, 6121, and 6122 Industrial Support Computers
IBM PC/XT and PC/AT
Compaq Deskpro 286
Compaq Portable II and III
If your computer is not listed above, consult your local Allen-Bradley
sales office for compatibility information.
You can use the following with the 6001-F2E Standard Driver software:
If
you use this programming deviceUse this operating system
1784-T50 programming terminal
IBM PC/XT
programming terminal
1
If you are using a 1784-T50 that has DOS version 2.1
current version of Allen-Bradley DOS
, PC/AT, or IBM-compatible
1
Allen-Bradley DOS version 3.21
DOS version 3.0 or later (Use the DOS version
included with the programming terminal)
1 or earlier
, you need to purchase the
1-1
Chapter 1
Product Overview
Overview of the Function Calls
The 6001-F2E Standard Driver Software consists of a library of C
programming language function calls that let your computer communicate
with nodes on the DH-485 network. Table 1.A lists these commands:
T
able 1.A
6001-F2E
If you want to
perform initialization functions (required
before any communication can take
place)
transmit data over the DH-485 network
to a DH-485 station
release all resources and services
before the application program
terminates
Standard Driver Software Commands
Use this function call
Open_StdDrv
Send_StdDrv
Close_StdDrv
See chapter 4 for more information on the function calls.
1-2
Chapter 1
Product Overview
Software Considerations
Important information about the 6001-F2E Standard Driver software for
the 1784-KR Interface Module is listed below:
the 6001-F2E driver does not support unsolicited messages
the 6001-F2E does not support multiple outstanding commands (you
must receive the reply from your command before sending another
command)
the 6001-F2E supports the large memory model version of Microsoft C
and Borland Turbo C only
the 6001-F2E driver does not respond to a diagnostic status command
sent to itself, but responds to diagnostic status commands sent from
another computer
the 6001-F2E driver does not return a local error code if the KR detects
a node address on the network the same as its own. The station that had
the address first stays on-line; the other station goes off-line, so check
for duplicate addresses in this situation,
if you incorrectly format messages to be sent by the Standard Driver
software, a timeout condition occurs in the application. Since there is
no error code indicating an incorrect message format, check the
message format first when the application software times out with a
timeout error code
the 6001-F2E does not support off-link messages (messages sent across
a bridge to another network)
the 6001-F2E supports applications that communicate with a single
1784-KR only
1-3
Chapter
2
Installing the Standard Driver Software
Chapter Objectives
What the Package Includes
In this chapter, you learn about:
what the Standard Driver package includes
the contents of the Standard Driver diskette
how to install the Standard Driver Software
You have one of these two packages:
Cat.
No.
6001–F2E
1747-F2E
Each package contains:
one User’s Manual (publication 6001-6.5.5)
one 5-1/4” diskette and one 3-1/2” diskette (use the appropriate diskette
for your system)
software license
Product Description
Stand-alone Standard Driver software for the
1784-KR
Standard Driver software bundled with the 1784-KR
hardware
If you ordered the 1747-F2E, you received a 1784-KR board in addition
to the items listed above.
2-1
Chapter 2
Installing the Standard Driver Software
What’s on the Diskette
The Standard Driver diskette contains the following types of files:
linkable large memory model standard driver library files
application library files
example application files
Standard Driver Library Files
Use the following files to build a linkable large memory model
application using the Standard Driver.
This
file
L_MSKR.LIB
L_TCKR.LIB
STDDRV.H
KRDEFS.H
START485.EXE
Contains
a large memory model Microsoft v5.1 compatible 6001-F2E
Standard Driver library module
a large memory model Borland v2.01 compatible 6001-F2E
Standard Driver library module
definitions and declarations required to compile a 6001-F2E
Standard Driver application
the 6001-F2E Standard Driver start-up and initialization program.
Run the START485.EXE to initialize the 1784-KR before you run
your application
Application Library Files
The following files contain application functions libraries that let you use
pre-defined support routines (Application Libraries). Use these in
applications using the basic command set in table 4.B on page 4-2.
This
file
L_MSAPP.LIB
L_TCAPP.LIB
Contains
a large memory model Microsoft v5.1 compatible application library
module
a large memory model Borland v2.0 compatible application library
module
2-2
Chapter 2
Installing the Standard Driver Software
Example Files
The following files contain working 6001-F2E Standard Driver
application examples:
This
file
Contains
Installing the Standard Driver
Hardware and Software
F2EDIAG.C
F2ESLC.C
SCREEN.H
diagnostic routines
unprotected read and unprotected write routines
definitions and declarations required to compile F2EDIAG.C or
F2ESLC.C
This section tells you how to install the Standard Driver hardware and
software.
Installing the Hardware
To install the Standard Driver hardware:
1.Set the 1784-KR memory address switches and jumper settings that
are compatible with your computer system (See the 1784-KR
Installation Data, publication 1784-2.23, for instructions on setting
these switches.)
2.Record these addresses on a piece of paper. You will need them
when you configure the software.
2-3
Chapter 2
Installing the Standard Driver Software
Installing the Software
To install the Standard Driver software:
1.Create a working directory in your computer’s hard disk (C:\F2E, for
2.Put the disk containing the Standard Driver files in disk drive A:>
3.Copy all the files from the disk to that directory
This completes the installation procedure. The next chapter helps you
plan your application program.
example). Use this directory to build your application program(s).
(We use drive A:> as a default.)
Copy A:*.* C:\F2E).
(
2-4
Chapter
3
Planning Your Application Program
Chapter Objectives
Include Files
This section guides you through the process of planning an application
program. It contains the following:
include files you need to put in your program
function calls
programming considerations
The include files contain declarations for the driver type you are using.
Define them at the top of your application program. The 6001-F2E
Standard Driver uses the following include files:
KRDEFS.H
STDDRV.H
Important: In addition to including header files in your application, you
need to link with an appropriate Standard Driver and Application Library
file (whether you are using the Application Library or not).
If you use multiple files, place KRDEFS.H and STDDRV.H in the main
file. Only one source per executable can reference each include file. If
additional source files within an executable reference the Standard Driver
software, you must do the following:
duplicate KRDEFS.H and STDDRV.H under different names
delete the following lines from the duplicate KRDEFS.H:
int max_umsg = Max_Umsg;
int max__smsg = 16;
delete from the duplicate STDDRV.H all lines beginning from the first
occurance of /* ..... */ under the “Prototype” heading to the
end of the file
Use these edited versions in all remaining source files that reference the
6001-F2E Standard Driver software.
3-1
Chapter 3
Planning an Application Program
Overview of the Function Calls
Function calls let your application program communicate with devices on
the DH-485 network:
This
Function Call
Open_StdDrv()
Appl_StdDrv()
Send_StdDrv()
Get_ErrMsg()
Close_StdDrv()
Lets Y
ou
initialize the 6001-F2E Standard Driver. Use this function call in
every
program you write.
use predefined support routines (Application Library) in
applications that use the basic command set. See page 4-2 for a
list of these commands.
format commands not provided in the Application Library
you format message packets when communicating with
token-passing or slave-only devices.
retrieve an ASCII string that describes a network message error
end communication. Use this function call in
write.
every
. It lets
.
program you
Important: When you write your program, you must always start with
Open_StdDrv() and end with Close_StdDrv(). The middle of your
program will consist of Appl_StdDrv() or Send_StdDrv() or a
combination of both. Use the Send_StdDrv() function call to format
commands not supported by the Application Library routines. (See table
4.B on page 4-2 for a list of these commands.)
Programming Considerations
Your disk contains example programs (F2EDIAG.C and F2ESLC.C) you
can use to test communication on the DH-485 network. (See appendix A
for additional program examples.)
The next chapter for the format and parameters for each function call.
Keep the following considerations in mind when you write your
application program:
Use Borland Turbo C (v2.01 or later) or Microsoft C (v5.0 or later)
Whether you use only Appl_StdDrv() routines or Send_StdDrv()
routines, you must always link the following:
If
you are using this
Borland Turbo C (v2.01)
Microsoft C (v5.0)
Link these files
L_TCKR.LIB
L_TCAPP.LIB
L_MSKR.LIB
L_MSAPP.LIB
3-2
Using the Function Calls
Chapter
4
Chapter Objectives
Using Open_StdDrv()
This chapter shows you how to use each of the function calls. It includes
the format and parameters for each function call.
The Open_StdDrv() function call initializes the 6001-F2E Standard
Driver. To open the Standard Driver, use the following format and
parameters:
Format for Open_StdDrv()
The Open function call is shown below:
status = Open_StdDrv(device,0,0,0,
(unsol_msg *)NULL,
0,0,0);
Parameters for Open_StdDrv()
Assign the parameters in Table 4.A:
T
able 4.A
Assigning
ParameterTypeDescription
device[ ] = “KR:0”
(unsol_msg *)NULL,
0N/A
When the Open_StdDrv() function is called, a status value is returned
indicating whether the operation was successful or unsuccessful. Normal
completion is 1. A value other than 1 indicates that an error occurred.
See Appendix D for a list of error codes.
Parameters to Open Communication
char
struct
Assigns a driver type “KR:” and communication channel “0”. The 6001-F2E
Standard Driver supports one 1784-KR communication channel.
This is a null pointer for this release.
These parameters are ignored, but you still need to include them in the
function call. Type in a zero for each ignored parameter
.
4-1
Chapter 4
Writing Your Own Application Program
Communicating on DH-485 with
the 6001-F2E Standard Driver
Using Appl_StdDrv()
After you have initialized the Standard Driver with the Open_StdDrv()
function call, you are ready to communicate. You can use the
Appl_StdDrv() function call (Application Library) or the Send_StdDrv()
function call or a combination of both. Use the SendStdDrv() function
call to format commands not supported by the Application Library. See
table 4.B for a list of commands supported by the Application Library.
The Appl_StdDrv() function formats DH-485 messages for the basic
command set and transmits them over the DH-485 network. Use the
Appl_StdDrv() with the selected PLC application symbol and
Appl_StdDrv() message block data structure. The application symbols
and the message block data structure are defined in the STDDRV.H header
files. Use the following format and parameters:
Format for Appl_StdDrv()
The Appl_StdDrv() function call is shown below:
status = Appl_StdDrv(SYMBOL, SD_FB *);
Parameter
TypeDescription
SYMBOLintidentifies
SD_FBstruct
initializes the DH+ function block (see table 4.C)
the support routine symbol (see table 4.B)
See appendix D for return status values for the Appl_StdDrv()
function.
Parameters for Appl_StdDrv()
Table 4.B below shows the available functions (in the Application
Library) you can use with Appl_StdDrv(). Table 4.C shows the
Appl_StdDrv() message block data structure:
T
able 4.B
6001-F2E
T
Diagnostic loop back testing
Read diagnostic counters
Read diagnostic status
Reset diagnostic counters
Basic command set unprotected read
Basic command set unprotected write
Support Routines
o do this
Specify this
PLC_DLB
PLC_DCR
PLC_DS
PLC_RC
PLC_UPR
PLC_UWR
4-2
Refer to Appendix B for each of the available Application Library
routines.
T
able 4.C
Appl_StdDrv()
VariableTypeDescription
Message Block Data Structure
Chapter 4
Writing Your Own Application Program
DHP_MSG.dev = device;
DHP_MSG.stat = &io_stat[0];unsigned int
DHP_MSG.L_R = Loc_Rem;
DHP_MSG.dst = &destination; unsigned char The DH-485 destination address. The destination variable is the DH-485
DHP_MSG.dta = &dt_addrunsigned intThe data table address. Depending on the routine, the dt_addr variable is a
char
int
The device variable indicates to the Standard Driver the communication
interface and its channel. Set this variable to KR:0.
The io_stat variable serves two purposes. When Application Library routines
are called, they return status before any type of reply is received from the
remote device.
When the Appl_StdDrv() successfully initiates a request to send a message
(status = 1), io_stat[0] is reset to 0. When a reply message is received or a
reply timeout occurs that matches the original request, io_stat[0] is set to a
value greater than 0. Normal completion is 1. If io_stat[0] is normal,
io_stat[1] will contain the length of the reply data buf
If io_stat does not equal 1, an error occurred. The format is as follows:
The low byte (EXT STS) of io_stat[0] contains local errors, such as timeout.
The High byte (STS) of io_stat[0] contains DH-485 errors. If the high byte of
io_stat[0] equals F0 Hex (indicating the extended DH-485 status), the low
byte if io_stat[0] will contain the extended DH-485 status value. See
appendix D for more information on error messages. See table 4.F for
examples of STS and EXT STS bytes in io_stat[0].
Set this variable to 0.
address where you want your message to be sent on the DH-485 network.
two byte value or string describing the data table address where data is to be
read from or written to.
fer.
DHP_MSG.len = size;
DHP_MSG.buf = &d_buf
DHP_MSG.T
O = timeout;unsigned intThe timeout variable is the number of seconds that you want to wait for a
f[0];
int
unsigned char
or
int
When reading data, the size variable indicates how many data bytes are to
be read. When writing data, the size variable indicates how many bytes
should be copied from the data buf
The application data buf
formats. If you are using byte values, d_buff may be defined as a char array
the size variable is defined as a one-to-one relationship. If you are using
signed integers, data is automatically stored in byte swapped format, the size
value is defined as a two-to-one relationship.
reply.
fer
fer and written to the remote station.
. The application data may take on several
Important: If you are communicating to an SLC-500 using the
unprotected read or unprotected write commands, create Data File 9 in the
SLC-500. The SLC-500 uses this file for DH-485 communication. The
data table address (defined as dt_addr in the Appl_StdDrv() function) will
4-3
,
Chapter 4
Writing Your Own Application Program
be interpretted by the SLC-500 as a logical offset (in words) into Data
File 9. See the SLC-500 Advanced Programming Software Manual,
chapter A3, for more information on the SLC-500 memory organization.
Using Send_StdDrv()
If you do not wish to use the commands supported by the Application
Library, use the Send_StdDrv() function to send user-formatted messages.
The Send_StdDrv() function call transmits data over the DH-485 network
to a DH-485 station. Depending on your application, you can use the
Send_StdDrv() function call two ways. You can:
communicate with token-passing DH-485 devices (such as the
SLC-500)
communicate with slave-only DH-485 devices
(See appendix B for more information on message packet formats for the
Send_StdDrv() function call.)
Any transmission that does not complete normally is aborted by a timeout
or local error code indicating the problem. See appendix D for a list of
error codes. Use the following format and parameters:
Use the Send_StdDrv() function call to send user-formatted messages.
Parameters for Send_StdDrv()
Assign the parameters in Table 4.D:
T
able 4.D
Assigning
ParameterTypeDescription
Parameters to Send Data
Chapter 4
Writing Your Own Application Program
device[] = “KR:0”
io_stat[2];
cmd_buff[...]
char
unsigned int
unsigned char The cmd_buff parameter is the buffer containing your message to be sent to the remote
The device parameter should coincide with the same device used in the Open_StdDrv()
function (Set this value to KR:0.)
The io_stat variable serves two purposes. When standard driver routines are called, they
return status before any type of reply is received from the remote device.
When the Standard Driver successfully initiates a request to send a message (status = 1),
io_stat[0] is reset to 0. When a reply message is received or a reply timeout occurs that
matches the original request, io_stat[0] is set to a value greater than 0. Normal completion is
1.
If io_stat does not equal 1, an error occurred. The format is as follows:
The low byte (EXT STS) of io_stat[0] contains local errors, such as timeout. The high byte
(STS) of io_stat[0] contains DH-485 errors. If the high byte of io_stat[0] equals F0 Hex
(indicating the extended DH-485 status), the low byte if io_stat [0] will contain the extended
DH-485 status value. See appendix D for more information on error messages. See table
4.F for examples of STS and EXT STS bytes in io_stat[0].
station. Use the following format:
LEN TYP DST SRC CMD STS TNS TNS DA
The LEN field contains the entire packet length, including LEN. The TYP field is the
message type. Set this value to 0 or 5, depending on the message type. The DST field is the
DH-485 destination where your message is sent. The SRC field is the local 1784-KR DH-485
address. This field can be set to 0. See appendix B for definitions of each field.
TA
pass_thru = 1;
pass_thru = 0;
reply_buf
timeout = 5;unsigned int
0, 0
f[...];
int
unsigned char The reply_buff parameter tells the driver where to put a reply message to your application.The
N/A
The pass_thru parameter is a reply option for the Standard Driver. When pass_thru is set to
1, the entire reply message (the header and the data you requested) is placed in your buf
When the pass_thru parameter is set to 0, only the data you requested (not the header) is
fer
placed in your buf
reply message is copied into your buf
LEN TYP DST SRC CMD STS TNS TNS DA
The timeout parameter is the number of seconds your application waits for a reply message.
Parameters 7 and 8 are not used, but you still need to include them in the function call. T
in a zero for both parameters.
. The length is returned in io_stat[1].
fer using the following format:
TA
See Appendix D for return status values for the Send_StdDrv()
function.
fer.
ype
4-5
Chapter 4
Writing Your Own Application Program
Preventing Reply Messages from Being Lost
To prevent reply messages from being lost, we provide a Get_tns()
function. Use the following format:
x = Get_tns()
The Get_tns() function returns an unsigned integer value. Place this value
in the two-byte TNS field of your DH-485 message prior to calling the
Send_StdDrv() function. See page B-5 for more information on
Get_tns().
Using Get_ErrMsg()
ParameterTypeDescription
The Get_ErrMsg() function call supplies a message string for errors in
data transmission. If an error occurs, call Get_ErrMsg() with the error
code to get a message indicating the problem. Use the following format
and parameters:
Format for Get_ErrMsg()
The Get_ErrMsg() function call is shown below:
Get_ErrMsg(err, ret_msg);
Parameters for Get_ErrMsg()
Table 4.E explains the parameters:
T
able 4.E
Get_ErrMsg()
Parameters
4-6
err
ret_msgchar
unsigned int
is a copy of the error value returned in io_stat[0].
is a pointer to a character buffer at least 80 characters long. It contains
the error message string that corresponds to the code in the err
parameter
. The error message is returned in this buf
fer.
Table 4.F explains how to read io_stat[0] to get the STS and EXT STS
bytes.
Chapter 4
Writing Your Own Application Program
T
able 4.F
Reading
If the STS and EXT STS bytes of io_stat[0] look like this It is a
io_stat[0]
Using Close_StdDrv()
STS EXT STS
00
STS EXT STS
F00B
STS EXT STS
XY
Command message. No error. The values in the
EXT
STS byte can be any values.
Reply message with extended status information.
Match the code in the low byte (EXT STS) to
the code for the appropriate command in appendix D.
Reply message. X = status field of the DH-485
packet (this field contains remote errors returned
by devices on the DH-485 network. See appendix
D for a list of error codes. Y = user interface local error
codes listed in appendix D.
The CloseStdDrv() function call releases all resources and services and
must be called before the application terminates. Use the following
format and parameters:
Format for Closing Communication
The Close_StdDrv() function call is shown below:
status = Close_StdDrv(device);
Parameters for Closing Communication
Assign the parameters in Table 4.G:
T
able 4.G
Assigning
ParameterTypeDescription
device[ ] = “KR:0”;
Parameters to Close Communication
char
The device parameter should coincide with the device used in the
Open_StdDrv() function
When the Close function is called, a status value is returned indicating
whether the operation was successful or unsuccessful. Normal
completion is 1. A value other than 1 indicates that an error occurred
(See appendix D for a list of error codes.)
4-7
Chapter
5
Compiling, Linking, and Configuring Your
Application Program
Chapter Objectives
Compiling and Linking Your
Application Program
This chapter tells you what you need to do before your application
program can communicate with other devices on the network. First, you
compile and link the software, then configure it. See the instructions
below.
To compile and link the linkable driver application software, do the
following:
1.Create your application program and “include” the KRDEFS.H and
STDDRV.H files.
2.Compile your application program with the large memory model
option.
3.Link your driver with an appropriate standard driver and application
library module.
Important: In addition to including header files in your application, you
need to link with an appropriate Standard Driver and Application Library
file (whether you are using the Application Library or not).
4.Copy your application.EXE and START485.EXE programs to the
directory you wish to use.
5.If the 1784-KR card switch settings are configured for other than
default settings, enter an environment string. See the PC DH-485
Interface Module Installation Data (publication 1784-2.23) for more
information.
5-1
Chapter 5
Compiling, Linking, and Configuring Your
Application Program
The following are compile line examples of Microsoft C and Borland
Turbo C:
Microsoft C
Borland Turbo C
C>CL /AL /Gs <PROGRAM.C> L_MSAPP.LIB L_MSKT.LIB
C>TCC -ml <PROGRAM> L_TCAPP.LIB L_TCKT.LIB
Configuring Your Application
Program
To configure your application program:
1.Type
START485 followed by the communication option settings. For
example, type:
START485 a0 m31 cM b9600
where:
This VariableIs
a
m
c
b
the DH-485 address of the 1784-KR (valid addresses are 0-31)
the maximum node address on the Dh-485 link (valid addresses
are 0-31)
the category of operation (this is always m)
the DH-485 baud rate (valid entries are 300, 1200, 2400, 4800,
9600, or 19,200 baud only)
Important: SLC-500 processors operate at 9600 or 19,200 baud only.
2.Press [ENTER].
5-2
This operation initializes the 1784-KR. Now that the 1784-KR board and
driver are installed and configured, you can run your application program.
Appendix
Application Program Examples
A
Sample Program
The following program is an application that shows how to write
information to Data File 9 of an SLC-500 processor using the Application
Library and the PLC-2 (Unprotected Write) function symbol. If you are
communicating to an SLC-500 using the unprotected read or unprotected
write commands, you must first create Data File 9 in the SLC-500. The
SLC-500 uses this file for DH-485 communication. The data table
address (defined as dt_addr in the Appl_StdDrv() function) will be
interpretted by the SLC-500 as a logical offset (in words) into Data File 9.
See the SLC-500 Advanced Programming Software Manual, chapter A3,
for more information on the SLC-500 memory organization
/* ––––––––––––––––––––––––––––––––––––––––––––––––––– */
/* A typical 6001-F2E Application */
/* Calling the Application Library via the APPL function dispatcher */
/* Write 2 integers to a remote SLC-500 */
PLC_FCT = PLC2_UWR;
/* Initialize a PLC function */
/* Write 2 integer values to a SLC-500 file at remote station DST */
fct_stat = Appl_StdDrv( PLC_FCT,&DHP_MSG); */
A-2
Appendix A
Application Program Examples
/* Fct_stat returns 1 if F2E snet the command successfully */
if (fct_stat != NORMAL){
Get_ErrMsg(fct_stat, err_msg);
printf(“%s/n”,err_msg);
fct_stat = close_StdDrv(device);
exit(1);
}
/* When a reply has been received or a timeout io_stat[0] will be set*/
while(!io_stat[0]);
printf(“status reply received\n”);
/* If io_stat[0] does not = 1 then an error occurred
if (io_stat[0] != NORMAL){
Get_ErrMsg(io_stat[0],err_msg);
printf(“%s/n”,err_msg);
}
/* Initialize the DH-485 function block */
DHP_MSG.dev = device; /* Communication device */
DHP_MSG.stat = &io_stat[0]; /* I/O status */
DHP_MSG.L_R = 0;
DHP_MSG.dst = &destination; /* DH-485 address */
DHP_MSG.dta = (unsigned char *)NULL;
DHP_MSG.len = 0; /* Size not applicable */
DHP_MSG.buf = (unsigned char *)NULL;
DHP_MSG.TO = timeout; /* Reply timeout in sec */
A-14
Appendix A
Application Program Examples
PLC_FCT = PLCx_RC; /* Initialize a PLC function */
/* Call the Standard Driver Appl() function */
status = Appl_StdDrv( PLC_FCT, &DHP_MSG);
/*
status = See 6001–F2E User’s manual appendix D
io_stat[0]: Local & remote I/O status
Hi_byte = DH-485 status
Lo_byte = Local & extended DH-485 status
io_stat[1]: Reply length in bytes (if applicable)
*/
A-15
Appendix
B
Specifying Message Packet Commands with
Send_StdDrv()
Chapter Objectives
Formatting the Message Packet
Use the information in this appendix to format the Send_StdDrv()
function call. Your message packet format depends on whether you are
sending data to:
token-passing devices (such as the SLC-500)
slave-only DH-485 devices
This appendix contains:
the message packet format you need (and an explanation of the fields
each packet contains)
supported commands for the Send function call
The figures on the following pages show all possible fields in the Send
function call message packet. The unshaded blocks indicate fields that are
always included in your message packet. The shaded blocks indicate
fields that may be included in your message packet, depending on the
command. Use the appropriate message packet format for your particular
application.
B-1
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Communicating with a Token-passing Device (SLC-500 Processor)
Figure B.1 shows the message packet format you use to communicate
with token-passing devices (such as an SLC-500 processor).
Important: Shaded blocks indicate packet fields that may or may not be
included in your message packet, depending on the command.
Figure B.1
Message
LENTYPDSTSRCCMDSTSTNS
Packet Format for Communicating with an SLC-500 Processor
Data
FNCADDRSIZETNSTNS
DA T A
(from Application Layer)
Table B.A explains the message packet fields in Figure B.1.
T
able B.A
Communicating
This Packet Field
LEN
TYP
DST
SRC
CMD
STS
TNS
FNC
ADDR
SIZE
DATA
with an SLC-500 Processor
Is the
length of the message packet (including LEN)
type code identifying this message packet format
(this is always a 0)
DH-485 destination address for this packet
DH-485 address of the device sending the packet
command byte
message packet status
transaction number (2 bytes)
byte used with CMD. If used, it defines the specific function
under the command type
two-byte field that contains the address of a memory
location in the command executor where the command is to
begin executing.
byte that specifies the number of data bytes to be
transferred by a message
data sent as part of themessage command
B-2
Communicating with a Slave-only Device
Figure B.2 shows the message packet format you use to communicate
with a slave-only DH-485 device.
Important: Shaded blocks indicate packet fields that may or may not be
included in your message packet, depending on the command.
Figure B.2
Message
LENTYPDSTSRCCMDSTSTNSFNCADDRSIZEIMMED.1DATATNS
Packet Format for Communicating with a Slave-only Device
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Table B.B shows the message packet fields in Figure B.2.
T
able B.B
Communicating
This Packet Field
LEN
TYP
IMMEDIA
1
DST
SRC
CMD
STS
TNS
FNC
ADDR
SIZE
DATA
with a Slave-only Device
Is the
length of the message packet (including LEN)
type code identifying this format
(this is always a 5)
TE BLOCK
immediate block in the destination device
local link message
(this is always a 1)
DH-485 destination address for this packet
DH-485 address of the device sending the packet
command byte
message packet status
transaction number (2 bytes)
byte used with CMD. If used, it defines the specific function
under the command type
two-byte field that contains the address of a memory
location in the command executor where the command is to
begin executing.
byte that specifies the number of data bytes to be
transferred by a message
data sent as part of a message command
The next section describes the packet fields for both applications.
B-3
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Message Packet Fields
The message packet fields for the previous applications are described in
more detail in the table below.
T
able B.C
Message
FieldDescription
LEN
TYP
IMMEDIA
DST and SRC
CMD and FNC
STS and EXT STSThe STS (status) and EXT STS (extended status) bytes indicate the
Packet Field Description
This field identifies the length of the message packet (including LEN). The
allowed range is 0-255.
This is the code that identifies the type of communication. Use 0 to
communicate to an SLC-500 processor and 5 to communicate to a
slave-only device.
TE BLOCK
The allowed range is 0 and 128-255 (depending on the device.)
The DST (destination) byte contains the DH-485 node number of the
node that is the ultimate destination of the message. The SRC (source)
byte contains the DH-485 node number of the node that originated the
message.
The application layer supplies the DST value; the data link layer supplies
the SRC value. Allowed values for these bytes are 0 to 31 (decimal).
The CMD (command) and FNC (functions) bytes (1 byte each) together
define the activity to be performed by the command message at the
destination node. Command defines the command type and FNC, if
used, defines the specific function under that command type.
status of the message transmission. In command messages, the
application program should always set the STS value to 0. In reply
messages, the STS byte may contain one of the status codes listed in
appendix D . If the high byte = F0 Hex, there is extended status
information in the EXT STS byte. Otherwise, there is no EXT STS byte.
An STS value of 0 in a reply message means the command has been
executed with no error
In a reply message, the STS byte is divided between application layer
and link layer
report local errors (those errors that occur when the link layer attempts to
transmit a message across the link).
The application layer uses bits 4 through 7 of the STS byte (and in some
cases, the EXT STS byte) to report remote errors (those errors that occur
when the command executor at the destination node tries to execute the
command message). Refer to appendix D for more information.
.
. The link layer uses bits 0 through 3 of the STS byte to
B-4
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Field
TNSThe
ADDR
SIZE
DATA
Description
identifier.
For each command message transmitted by your computer node, your
application level software must assign a unique 16-bit transaction
number
function and store the value in the two TNS bytes of the new message.
See page 4-6 for more information on Get_tns().
When the command initiator receives a reply to one of its command
messages, it can use the TNS value to associate the reply message with
its corresponding command. If the TNS value of a reply message
matches the TNS value of a command message, then that reply is the
appropriate one for that command.
Note that the low byte (least significant bits) of your TNS value will be
transmitted across the link before the high byte (most significant bits).
At any instant, the combination of SRC, CMD, and TNS are sufficient to
uniquely identify every message packet in transit. At least one of these
fields in the current message must be dif
field in the last message received by a command executor
these fields is different, the message is ignored. The process is called
duplicate message detection.
The ADDR (address) field (2 bytes) contains the address of a memory
location in the command executor where the command is to begin
executing. For example, if the command is to read data from the
command executor
to be read.
The first byte of the ADDR field contains the low (least significant) byte of
the address, and the second byte contains the high byte of the address.
The ADDR field specifies a byte address, not a word address, as in SLC
programming.
The SIZE byte specifies the number of data bytes to be transferred by a
message. This field appears in read commands, where it specifies the
number of data bytes that the responding node must return in its reply
message. The allowed value for SIZE varies with the type of command.
The DATA field contains binary data from the application program. The
number of data bytes in a message depends on the command or function
being executed.
TNS (transaction) bytes (2 bytes) contain a unique 16-bit transaction
. A simple way to generate this number is to use the Get_tns()
ferent than the corresponding
. If none of
, ADDR specifies the address of the first byte of data
B-5
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Supported Command Set
CommandCMD
SLC-500
Protected Typed Logical Read with 3 address
fields
Protected Typed Logical W
fields
Basic
Diagnostic Counters reset
Diagnostic Loop
Diagnostic Read
Unprotected Read
Unprotected W
Diagnostic Status
The supported command set includes commands that can generally be
executed by any SLC processor. Use these commands with the
Send_StdDrv() function call.
(Hex)
0FA2
rite with 3 address
rite08N/A
0FAA
0607
0600
0601
01N/A
0603
FNC (Hex)
Important: In the example formats that follow, CMD and FNC values are
expressed in hexadecimal notation; all other values are in decimal form.
The message packet fields for each of the commands are described in
more detail in the following pages. See page B-2 for more information
on formatting message packets.
B-6
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Diagnostic Counters Reset
Diagnostic Loop
This command resets to zero all the diagnostic timers and counters in the
node interface module. The diagnostic status command gives the starting
address for this block of counters and timers
Command Format
CMDSTSTNSFNC
0607
Reply Format
CMDSTSTNS
46
You can use this command to check the integrity of the transmissions over
the communication link. The command message transmits up to 243
bytes of data to a node interface module. The receiving module should
reply to this command by transmitting the same data back to the
originating node.
Command Format
CMDSTSTNSFNC
0600
Reply Format
CMDSTSTNS
46
243 bytes max.
DATA
243 bytes max.
DATA
B-7
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Diagnostic Read
Diagnostic Status
This command reads up to 244 bytes of data from the PROM or RAM of
the node interface module. You can use it to read the module’s diagnostic
timers and counters. When communicating to an SLC-500, set ADDR to
0 and SIZE to 10 (decimal). See appendix C for diagnostic read replies
for DH-485 devices.
Command Format
CMDSTSTNS
06
01
ADDRSIZEFNC
Reply Format
CMDSTSTNS
46
DATA
244 bytes max.
Your computer uses this command to read a block of status information
from a DH-485 device. The reply contains the information in its DATA
field. The status information varies with the type of device. See appendix
C for diagnostic status replies for DH-485 devices.
B-8
Command Format
CMDSTSTNS
06
Reply Format
CMDSTSTNS
46
FNC
03
DATA
244 bytes max.
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Unprotected Read
Unprotected Write
This command reads words of data from any area of PLC data table
memory. Use the SIZE field to specify the number of bytes to be read.
To specify a number of PLC words, SIZE should be an even value
because PLC words are two bytes long. Data bytes are transferred low
byte first. The address of a word should be even.
Command Format
CMDSTSTNS
01
ADDRSIZE
Reply Format
CMDSTSTNS
41
DATA
244 bytes max.
This command writes words of data into any area of PLC data table
memory.
Command Format
CMDSTSTNS
08
ADDR
DATA
244 bytes max.
Reply Format
CMDSTSTNS
48
Important: If you are communicating to an SLC-500 using the
unprotected read or unprotected write commands, create a Data File 9 in
the SLC-500. The SLC-500 uses this file for DH-485 communication.
The data table address (defined as dt_addr in the Appl_StdDrv() function)
will be defined as a logical offset (in words) into Data File 9. See the
SLC-500 Advanced Programming Software Manual, chapter A3, for more
information on the SLC-500 memory organization.
B-9
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Protected Typed Logical Read
with Three Address Fields (File,
Element, Sub-element)
Command Format
Byte No.:
123,45678910
CMD
0FA2
FNC
BYTETNSSTS
SIZE
FILE
NUMBER
FILE
TYPE
ELEMENT
Table C.A gives a description of each field.
T
able B.D
Protected Typed Logical Read with Three Address Fields
ByteDescription
CMD0F
STS
TNS
FNCA2
BYTE SIZE
FILE NUMBER (or
bytes 7a-7c)
FILE TYPE80H, 81H – Reserved
ELEMENT NUMBER
(or bytes 9a-9c)
SUB-ELEMENT
NUMBER (or bytes
10a-10c)
Indicates the status of a message transmission
A unique 16-bit transaction number
message to its corresponding command, which contains the
same number
the size of data to be read (in bytes), not including the
address fields or other overhead bytes
Byte 7 addresses files 0-254 only. For higher addresses,
byte 7a = FF expands FILE NUMBER to three bytes total.
Use bytes 7b and 7c for expanded file address (low address
byte first)
82H – Output
83H – Input
84H – Reserved
85H – Bit
86H – T
87H – Counter
88H – Control
89H – Integer
Byte 9 addresses elements 0-254. For higher addresses,
byte 9A = FF expands ELEMENT NUMBER to three bytes
total. Bytes 9b and 9c are used for expanded element
address (low address byte first)
Byte 10 only addresses sub-elements 0-254. For higher
addresses, byte 10a = FF expands SUB-ELEMENT
NUMBER to three bytes total. Bytes 10b and 10c are used
for expanded sub-element address (low byte first)
.
imer
. Use it to match a reply
SUB–ELMT.
NUMBERNUMBER
B-10
Reply Format
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
CMD
4F
STSTNSEXT
(only if error)
STS
DATA
(244 bytes max)
The following are possible STS and EXT STS responses.
T
able B.E
Possible
Responses for Typed Logical Read with Three Address Fields
This Response
STS
00success
10
50
F0
EXT STS
1A
Means
command format incorrect
address problem
extended STS
file already open
B-11
Appendix B
Specifying Message Packet Commands
with Send_StdDrv()
Protected Typed Logical Write
with Three Address fields (File,
Element, Sub-element)
Byte No.:
123,45678910
CMD
0FAA
STSTNS
Command Format
FNC
T
able B.F
Protected Typed Logical Write with Three Address Fields
ByteDescription
CMD0F
STS
TNS
FNCAA
BYTE SIZE
FILE NUMBER (or
bytes 7a-7c)
FILE TYPE
ELEMENT NUMBER
(or bytes 9a-9c)
SUB-ELEMENT
NUMBER (or bytes
10a-10c)
DATA
BYTE
SIZE
FILE
NUMBER
Indicates the status of a message transmission
A unique 16-bit transaction number
message to its corresponding command, which contains the
same number
the size of data to be written (in bytes), not including the
address fields or other overhead bytes
Byte 7 addresses files 0-254 only. For higher addresses, byte
7a = FF expands FILE NUMBER to three bytes total. Bytes 7b
and 7c are used for expanded file address (low address byte
first)
80, 81 – Reserved
82 – Output
83 – Input
84 – Status
85 – Bit
86 – T
87 – Counter
88 – Control
89 – Integer
Byte 9 addresses elements 0-254 only. For higher addresses,
byte 9a = FF expands ELEMENT NUMBER to three bytes total.
Bytes 9b and 9c are used for expanded element address (low
address byte first)
Byte 10 addresses sub-elements 0-254 only. For higher
addresses, byte 10a = FF expands SUB-ELEMENT NUMBER
to three bytes total. Bytes 10b and 10c are used for expanded
sub-element address(low address byte first)
Low byte first
imer
FILE
TYPE
.
ELEMENT
NUMBER
SUB–ELMT.
NUMBER
. Use it to match a reply
244 bytes max.
DATA
B-12
Reply Format
CMD
4F
STSTNSEXT
STS
(only if error)
Diagnostic Replies
Appendix
C
Diagnostic Status Reply
The tables below show diagnostic status replies for the following:
Processor Mode
Status/Control W
Byte)
Bit 0
Bit 2
Bit 5
Program ID(low byte)
ord
0 – Download
1 – Program
2 – Reserved
3 – Idle due to SUS instruction
4 – Reserved
5 – Reserved
6 – Run
7 – Test Continuous Scan
8 – Test Single Scan
9 – 31 Reserved
Forces Active
Forces Installed
Communication Active
ord (High
Protection Power Loss
Load Memory Module on Mem Error
Major Error – Process halted
Reply
22
23
24
Program ID
Processor RAM size (in
Kbytes)
Bit 0
Bits 2-7:
(high byte)
Directory File Corrupted
00-1F (Program Owner Node Address)
3F (No Program Owner)
C-2
Appendix C
Message Packet Formats for the
Basic Command Set
T
able C.B
Diagnostic Status Reply for APS Software (with COM1 Port DH-485 connection)
ByteDescription
1
2T
3
4
5Series/Revision:
6-16
17-24
T
able C.C
Diagnostic Status Reply for 1784-KR
ByteDescription
Mode/Status Byte
ype Extender
Extended Interface T
Extended Processor T
Bits 0-4
Bits 5-7
Bulletin Number/Name= APS
Product Specific Information
Status Reply (Hex)
00 (no modes)
EE
ype20
ype1B
0 (Release 1)
1 (Release 2). etc.
0 (Series A)
1 (Series B), etc.
(ASCII)
00
Status Reply (Hex)
1
2T
3
4
5Series/Revision
6-16
17-24
Mode/Status Byte
ype Extender
Extended Interface type
Not used
Bits 0-4:
Bits 5-7:
Bulletin Number/Name =
“1784-KR”
Product Specific Information
00 (no modes)
FE
24
00
0 (Release 1)
1 (Release 2). etc.
0 (Series A)
1 (Series B), etc.
ASCII
00
C-3
Appendix C
Message Packet Formats for the
Basic Command Set
Diagnostic Read Reply
(Diagnostic Counters)
The table below contains diagnostic read reply values for:
SLC-500
APS (COM1)
1784-KR Interface Module
T
able C.D
Diagnostic
This Byte
0T
1T
2T
3T
4Retries
5
6
7
8
9Reserved
Read Reply Values for SLC-500, APS, and 1784-KR
Means
otal packets received, low byte
otal packets received, high byte
otal messagaes sent, low byte
otal messages sent, high byte
Retry limit exceeded
NAK, no memory sent
NAK, no memory received
Bad messages received
C-4
Error Codes
Appendix
D
Error Codes
This appendix contains local and remote error codes:
T
able D.A
Local
Error Codes
Error Codes (in Hex)
1
18
19
1A
1B
1C
1D
1E
1F
23
25
27
28
29
2A
2B
Message
Successful transmission
LLC Interface not initialized; SSAP already used or invalid
SSAP
LLC Interface not initialized; KTLLC driver not installed
Unsuccessful send request; SSAP not active or illegal
Unsuccessful send request; Invalid packet size
Unsuccessful send request; Host cannot access dual port
Reply timeout; No reply data received
Unsuccessful send request; Buffer not available
DH-485 Interface not initialized
Bad function parameter
Invalid Channel
KR transmit timeout
Fatal solicited buf
Fatal timer buffer memory allocation
Fatal timer buffer memory corrupted
KR channel already open
fer memory allocation
D-1
Appendix D
Error Codes
T
able D.B
Remote
Error Codes
Error Codes (in Hex)
STS
00Success
10
50
60
F0
EXT STS
0B
1A
1B
Message
Command format incorrect
Address problem
Disallowed due to command protection
Extended status
Access denied. Improper privilege
File already open
Procesor in edit mode. Not accessible
D-2
Index
I
A
Application Library Files, 2-2
Application Program
Compiling, Linking, and Configuring, 5-1
Examples, A-1