You are on page 1of 24

OPEN MODBUS/TCP SPECIFICATION

Release 1.0, 29 March 1999


Andy Swales
Schneider Electric
aswales@modicon.com
244135787.doc 1 3/29/99
Contents
Contents............................................................................................................................................................2
1. Status of this specification............................................................................................................................3
2. Overview.......................................................................................................................................................3
2.1 Connection-oriented...............................................................................................................................3
2.2 ata encodin!.........................................................................................................................................4
2.3 "nterpretation of reference nu#$ers.......................................................................................................4
2.4 "#p%ied %en!th phi%osoph&.....................................................................................................................5
3. Confor#ance c%ass su##ar&.......................................................................................................................5
3.1 C%ass '....................................................................................................................................................5
3.2 C%ass 1....................................................................................................................................................5
3.3 C%ass 2....................................................................................................................................................(
3.4 )achine/vendor/networ* specific functions..........................................................................................7
4. +rotoco% structure.........................................................................................................................................7
5. +rotoco% reference $& confor#ance c%ass.....................................................................................................8
5.1 C%ass ' co##ands detai%........................................................................................................................9
5.1.1 ,ead #u%tip%e re!isters -.C 3/........................................................................................................9
5.1.2 0rite #u%tip%e re!isters -.C 1(/.....................................................................................................9
5.2 C%ass 1 co##ands detai%......................................................................................................................1'
5.2.1 ,ead coi%s -.C 1/...........................................................................................................................1'
5.2.2 ,ead input discretes -.C 2/...........................................................................................................1'
5.2.3 ,ead input re!isters -.C 4/...........................................................................................................11
5.2.4 0rite coi% -.C 5/............................................................................................................................11
5.2.5 0rite sin!%e re!ister -.C (/...........................................................................................................12
5.2.( ,ead e1ception status -.C 7/........................................................................................................12
5.3 C%ass 2 co##ands detai%......................................................................................................................13
5.3.1 .orce #u%tip%e coi%s -.C 15/.........................................................................................................13
5.3.2 ,ead !enera% reference -.C 2'/....................................................................................................14
5.3.3 0rite !enera% reference -.C 21/....................................................................................................15
5.3.4 )as* write re!ister -.C 22/..........................................................................................................1(
5.3.5 ,ead/write re!isters -.C 23/.........................................................................................................1(
5.3.( ,ead .".O 2ueue -.C 24/.............................................................................................................17
(. 31ception codes..........................................................................................................................................17
4ppendices.....................................................................................................................................................19
4. C%ient and Server "#p%e#entation 5uidance...........................................................................................19
4.1 C%ient desi!n........................................................................................................................................19
4.2 Server desi!n.......................................................................................................................................2'
4.2.1 )u%tithreaded server....................................................................................................................2'
4.2.2 Sin!%e-threaded server..................................................................................................................21
4.3 ,e2uired and e1pected perfor#ance...................................................................................................22
6. ata 3ncodin! for non-word data.............................................................................................................23
6.1 6it nu#$ers within a word..................................................................................................................23
6.2 )u%ti-word 2uantities..........................................................................................................................24
6.2.1 984 ata 7&pes..............................................................................................................................24
6.2.2 "3C-1131 data t&pes......................................................................................................................25
244135787.doc 2 3/29/99
1. Status of this specification
"nitia% re%ease 3 Sept 1997
raft for pu$%ic review.
,e-re%ease 29 )arch 1999 at ,evision 1.'.
8o technica% chan!es9 c%arifications on%&.
4dded 4ppendices 4 and 6 in response to co##on i#p%e#entation 2uestions.
7his specification of )O6:S/7C+ is $ein! pu$%ished $& $ein! pu$%ic%& visi$%e on the 0or%d 0ide 0e$.
"t is intended for the $enefit of deve%opers wishin! to use )O6:S/7C+ as an interopera$i%it& standard
in the fie%d of industria% auto#ation.
Since )O6:S and )O6:S/7C+ are in rea%it& ;de-facto< standards9 in that #an& vendors and
products i#p%e#ent it a%read&9 this specification pri#ari%& e1p%ains the specific encodin! of )O6:S
#essa!es over the 7C+ co##unication protoco% universa%%& avai%a$%e on the "nternet.
2. Oe!ie"
)O6:S/7C+ is a variant of the )O6:S fa#i%& of si#p%e9 vendor-neutra% co##unication protoco%s
intended for supervision and contro% of auto#ation e2uip#ent. Specifica%%&9 it covers the use of )O6:S
#essa!in! in an ;"ntranet< or ;"nternet< environ#ent usin! the 7C+/"+ protoco%s. 7he #ost co##on use of
the protoco%s at this ti#e are for 3thernet attach#ent of +=C<s9 "/O #odu%es9 and ;!atewa&s< to other
si#p%e fie%d $uses or "/O networ*s.
7he )O6:S/7C+ protoco% is $ein! pu$%ished as a -;de-facto</ auto#ation standard. Since )O6:S is
a%read& wide%& *nown9 there shou%d $e %itt%e infor#ation in this docu#ent which cou%d not $e o$tained
e%sewhere. >owever9 an atte#pt has $een #ade to c%arif& which functions within )O6:S have va%ue for
interopera$i%it& of !enera% auto#ation e2uip#ent9 and which parts are ;$a!!a!e< fro# the a%ternate use of
)O6:S as a pro!ra##in! protoco% for +=C<s.
7his is done $e%ow $& !roupin! supported #essa!e t&pes into ;confor#ance c%asses< which differentiate
$etween those #essa!es which are universa%%& i#p%e#ented and those which are optiona%9 particu%ar%&
those specific to devices such as +=C<s.
2.1 Connection-oriented
"n )O6:S9 data transactions are traditiona%%& state%ess9 #a*in! the# hi!h%& resistant to disruption fro#
noise and &et re2uirin! #ini#a% recover& infor#ation to $e #aintained at either end.
+ro!ra##in! operations9 on the other hand9 e1pect a connection-oriented approach. 7his was achieved on
the si#p%er variants $& an e1c%usive ;%o!in< to*en9 and on the )od$us +%us variant $& e1p%icit ;+ro!ra#
+ath< capa$i%ities which #aintained a dup%e1 association unti% e1p%icit%& $ro*en down.
)O6:S/7C+ hand%es $oth situations. 4 connection is easi%& reco!ni?ed at the protoco% %eve%9 and a
sin!%e connection #a& carr& #u%tip%e independent transactions. "n addition9 7C+ a%%ows a ver& %ar!e
nu#$er of concurrent connections9 so in #ost cases it is the choice of the initiator whether to reconnect as
re2uired or re-use a %on!-%ived connection.
244135787.doc 3 3/29/99
eve%opers fa#i%iar with )O6:S #a& wonder wh& the connection-oriented 7C+ protoco% is used rather
than the data!ra#-oriented :+. 7he #ain reason is to *eep contro% of an individua% ;transaction< $&
enc%osin! it in a connection which can $e identified9 supervised9 and cance%ed without re2uirin! specific
action on the part of the c%ient and server app%ications. 7his !ives the #echanis# a wide to%erance to
networ* perfor#ance chan!es9 and a%%ows securit& features such as firewa%%s and pro1ies to $e easi%&
added.
Si#i%ar reasonin! was used $& the ori!ina% deve%opers of the 0or%d 0ide 0e$ when the& chose to
i#p%e#ent a #ini#a% 0e$ 2uer& as a sin!%e transaction usin! 7C+ on we%%-*nown port 8'.
2.2 Data encoding
)O6:S uses a ;$i!-endian< representation for addresses and data ite#s. 7his #eans that when a
nu#erica% 2uantit& %ar!er than a sin!%e $&te is trans#itted9 the )OS7 si!nificant $&te is sent first. So for
e1a#p%e
1( - $its '11234 wou%d $e '112 '134
32 - $its '112345(78= wou%d $e '112 '134 '15( '178
2.3 Interpretation of reference numbers
)O6:S $ases its data #ode% on a series of ta$%es which have distin!uishin! characteristics. 7he four
pri#ar& ta$%es are
input discretes sin!%e $it9 provided $& an "/O s&ste#9 read-on%&
output discretes sin!%e $it9 a%tera$%e $& an app%ication pro!ra#9 read-write
input re!isters 1(-$it 2uantit&9 provided $& an "/O s&ste#9 read-on%&
output re!isters 1(-$it 2uantit&9 a%tera$%e $& an app%ication pro!ra#9 read-write
7he distinction $etween inputs and outputs9 and $etween $it-addressa$%e and word-addressa$%e data ite#s9
do not i#p%& an& app%ication $ehavior. "t is perfect%& accepta$%e9 and ver& co##on9 to re!ard a%% four
ta$%es as over%a&in! one another9 if this is the #ost natura% interpretation on the tar!et #achine in
2uestion.
.or each of the pri#ar& ta$%es9 the protoco% a%%ows individua% se%ection of (553( data ite#s9 and the
operations of read or write of those ite#s are desi!ned to span #u%tip%e consecutive data ite#s up to a data
si?e %i#it which is dependent on the transaction function code.
7here is no assu#ption that the data ite#s represent a true conti!uous arra& of data9 a%thou!h that is the
interpretation used $& #ost si#p%e +=C<s
7he ;read and write !enera% reference< function codes are defined to carr& a 32 $it reference nu#$er9 and
cou%d $e used to a%%ow direct access to data ite#s within a @3,A %ar!e space. 7oda& there are no +=C
devices which ta*e advanta!e of that.
One potentia% source of confusion is the re%ationship $etween the reference nu#$ers used in )O6:S
functions9 and the ;re!ister nu#$ers< used in )odicon +=C<s. .or historica% reasons9 user reference
nu#$ers were e1pressed as deci#a% nu#$ers with a startin! offset of 1. >owever )O6:S uses the #ore
natura% software interpretation of an unsi!ned inte!er inde1 startin! at ?ero.
So a #od$us #essa!e re2uestin! the read of a re!ister at offset ' wou%d return the va%ue *nown to the
app%ication pro!ra##er as found in re!ister 4B''''1 -#e#or& t&pe 4 C output re!ister9 reference ''''1/
244135787.doc 4 3/29/99
2.4 Implied length philosophy
4%% )O6:S re2uests and responses are desi!ned in such a wa& that the recipient can verif& that a
#essa!e is co#p%ete. .or function codes where the re2uest and response are of fi1ed %en!th9 the function
code a%one is sufficient. .or function codes carr&in! a varia$%e a#ount of data in the re2uest or response9
the data portion wi%% $e preceded $& a $&te count.
0hen )od$us is carried over 7C+9 additiona% %en!th infor#ation is carried in the prefi1 to a%%ow the
recipient to reco!ni?e #essa!e $oundaries even if the #essa!e had to $e sp%it into #u%tip%e pac*ets for
trans#ission. 7he e1istence of e1p%icit and i#p%icit %en!th ru%es9 and use of a C,C-32 error chec* code
-on 3thernet/ resu%ts in an infinitesi#a% chance of undetected corruption to a re2uest or response #essa!e.
#. Confo!$ance c%ass su$$a!&
0hen definin! a new protoco% fro# scratch9 it is possi$%e to enforce consistenc& of nu#$erin! and
interpretation. )O6:S $& its nature is i#p%e#ented a%read& in #an& p%aces9 and disruption to e1istin!
i#p%e#entations #ust $e avoided.
7herefore the e1istin! set of transaction t&pes have $een c%assified into confor#ance c%asses where %eve% '
represents functions which are universa%%& i#p%e#ented and tota%%& consistent9 and %eve% 2 represents
usefu% functions $ut with so#e idios&ncrasies. 7hose functions of the present set which are 8O7 suita$%e
for interopera$i%it& are a%so identified.
"t #ust $e noted that future e1tensions to this standard #a& define additiona% function codes to hand%e
situations where the e1istin! de-facto standard is deficient. >owever9 it wou%d $e #is%eadin! for detai%s of
such proposed e1tensions to appear in this docu#ent. "t wi%% a%wa&s $e possi$%e to deter#ine if a particu%ar
tar!et device supports a particu%ar function code $& sendin! it ;specu%ative%&< and chec*in! for the t&pe of
e1ception response if an&9 and this approach wi%% !uarantee the continued interopera$i%it& of current
)O6:S devices with the introduction of an& such e1tensions. "ndeed9 this is the phi%osoph& which has
%ed to the current function code c%assification.
3.1 Class 0
7his is the #ini#u# usefu% set of functions9 for $oth a )4S73, and a S=4@3.
read #u%tip%e re!isters -fc 3/
write #u%tip%e re!isters -fc 1(/
3.2 Class 1
7his is the additiona% set of functions which is co##on%& i#p%e#ented and interopera$%e. 4s e1p%ained
$efore9 #an& s%aves choose to treat input9 output9 discrete and re!ister as e2uiva%ent.
read coi%s -fc 1/
read input discretes -fc 2/
read input re!isters -fc 4/
write coi% -fc 5/
write sin!%e re!ister -fc (/
244135787.doc 5 3/29/99
read e1ception status -fc 7/
7his function t&pica%%& has a different #eanin! for each s%ave fa#i%&
3.3 Class 2
7hese are the data transfer functions needed for routine operations such as >)" and supervision
force #u%tip%e coi%s -fc 15/
read !enera% reference -fc 2'/
7his function has the a$i%it& to hand%e #u%tip%e si#u%taneous re2uests9 and can accept a
reference nu#$er of 32 $its. Current 584 and 984 +=C<s on%& use this function to accept
references of t&pe ( -e1tended re!ister fi%es/.
7his function wou%d $e the #ost appropriate to e1tend to hand%e %ar!e re!ister spaces
and data ite#s which current%& %ac* reference nu#$ers such as ;un%ocated< varia$%es.
write !enera% reference -fc 21/
7his function has the a$i%it& to hand%e #u%tip%e si#u%taneous re2uests9 and can accept a
reference nu#$er of 32 $its. Current 584 and 984 +=C<s on%& use this function to accept
references of t&pe ( -e1tended re!ister fi%es/.
7his function wou%d $e the #ost appropriate to e1tend to hand%e %ar!e re!ister spaces
and data ite#s which current%& %ac* reference nu#$ers such as ;un%ocated< varia$%es.
#as* write re!ister -fc 22/
read/write re!isters -fc 23/
7his function a%%ows the input of a ran!e of re!isters and the output of a ran!e of
re!isters as a sin!%e transaction. "t is the #ost efficient wa&9 usin! )O6:S9 to perfor#
a re!u%ar e1chan!e of a state i#a!e such as with an "/O #odu%e.
7hus a hi!h perfor#ance $ut versati%e data co%%ection device #i!ht choose to i#p%e#ent
functions 39 1( and 23 to co#$ine rapid re!u%ar e1chan!e of data -23/ with the a$i%it& to
perfor# on-de#and interro!ations or updates of particu%ar data ite#s -3 and 1(/
read .".O 2ueue -fc 24/
4 so#ewhat specia%i?ed function9 intended to a%%ow the transfer of data fro# a ta$%e
structured as a .".O -for use with the ."8 and .O:7 function $%oc*s on the 584/984/ to
a host co#puter. :sefu% in certain t&pes of event %o!!in! app%ications
3.4 Machine!endornet"or# specific functions
4%% of the fo%%owin! functions9 a%thou!h #entioned in the )O6:S protoco% #anua%s9 are not appropriate
for interopera$i%it& purposes $ecause the& are too #achine-dependent.
dia!nostics -fc 8/
pro!ra# -484/ -fc 9/
244135787.doc ( 3/29/99
po%% -484/ -fc 1'/
!et co## event counters -)od$us/ -fc 11/
!et co## event %o! -)od$us/ -fc 12/
pro!ra# -584/984/ -fc 13/
po%% -584/984/ -fc 14/
report s%ave " -fc 17/
pro!ra# -884/u84/ -fc 18/
reset co## %in* -884/u84/ -fc 19/
pro!ra# -ConCept/ -fc 4'/
fir#ware rep%ace#ent -fc 125/
pro!ra# -584/984/ -fc 12(/
report %oca% address -)od$us/ -fc 127/
'. P!otoco% st!uctu!e
7his section descri$es the !enera% for# of encapsu%ation of a )O6:S re2uest or response when carried
on the )O6:S/7C+ networ*. "t is i#portant to note that the structure of the re2uest and response $od&9
fro# the function code to the end of the data portion9 have 3D4C7=A the sa#e %a&out and #eanin! as in
the other )O6:S variants9 such as
)O6:S seria% port - 4SC"" encodin!
)O6:S seria% port - ,7: -$inar&/ encodin!
)O6:S +=:S networ* - data path
7he on%& differences in these other cases are the for# of an& ;fra#in!< se2uence9 error chec* pattern9 and
address interpretation.
4%% re2uests are sent via 7C+ on re!istered port 5'2.
,e2uests are nor#a%%& sent in ha%f-dup%e1 fashion on a !iven connection. 7hat is9 there is no $enefit in
sendin! additiona% re2uests on a sin!%e connection whi%e a response is outstandin!. evices which wish to
o$tain hi!h pea* transfer rates are instead encoura!ed to esta$%ish #u%tip%e 7C+ connections to the sa#e
tar!et >owever so#e e1istin! c%ient devices are *nown to atte#pt to ;pipe%ine< re2uests. esi!n
techni2ues which a%%ow a server to acco##odate this $ehavior are descri$ed in 4ppendi1 4.
7he )O6:S ;s%ave address< fie%d is rep%aced $& a sin!%e $&te ;:nit "dentifier< which #a& $e used to
co##unicate via devices such as $rid!es and !atewa&s which use a sin!%e "+ address to support #u%tip%e
independent end units.
7he re2uest and response are prefi1ed $& si1 $&tes as fo%%ows
$&te 'B transaction identifier - copied $& server - usua%%& '
$&te 1B transaction identifier - copied $& server - usua%%& '
244135787.doc 7 3/29/99
$&te 2B protoco% identifier C '
$&te 3B protoco% identifier C '
$&te 4B %en!th fie%d -upper $&te/ C ' -since a%% #essa!es are s#a%%er than 25(/
$&te 5B %en!th fie%d -%ower $&te/ C nu#$er of $&tes fo%%owin!
$&te (B unit identifier -previous%& ;s%ave address</
$&te 7B )O6:S function code
$&te 8 onB data as needed
So an e1a#p%e transaction ;read 1 re!ister at offset 4 fro# :" 9< returnin! a va%ue of 5 wou%d $e
re2uestB '' '' '' '' '' '( '9 '3 '' '4 '' '1
responseB '' '' '' '' '' '5 '9 '3 '2 '' '5
See %ater section for e1a#p%es of the use of each of the function codes in confor#ance c%asses '-2
esi!ners fa#i%iar with )O6:S shou%d note that the ;C,C-1(< or ;=,C< chec* fie%ds are 8O7 needed
in )O6:S/7C+. 7he 7C+/"+ and %in* %a&er -e!. 3thernet/ chec*su# #echanis#s instead are used to
verif& accurate de%iver& of the pac*et.
(. P!otoco% !efe!ence )& confo!$ance c%ass
8ote that in the e1a#p%es9 the re2uest and response are %isted fro# the function code $&te onwards. 4s
said $efore9 there wi%% $e a transport - dependent prefi1 which in the case of )O6:S/7C+ co#prises the
seven $&tes
ref ref '' '' '' %en unit
7he ;ref ref< a$ove is two $&tes of ;transaction reference< nu#$er which have no va%ue at the server $ut are
copied ver$ati# fro# re2uest to response for the convenience of the c%ient. Si#p%e c%ients usua%%& choose
to %eave the va%ues at ?ero.
"n the e1a#p%es9 the for#at for a re2uest and response is !iven %i*e this -the e1a#p%e is for a ;read
re!ister< re2uest9 see detai% in %ater section/
'3 '' '' '' '1 CE '3 '2 12 34
7his represents a he1adeci#a% series of $&tes to $e appended to the prefi19 so the fu%% #essa!e on the 7C+
connection wou%d $e -assu#e unit identifier '9 a!ain/
re2uestB '' '' '' '' '' '( '9 '3 '' '' '' '1
responseB '' '' '' '' '' '5 '9 '3 '2 12 34
-4%% of these re2uests and responses were verified $& usin! an auto#atic too%9 2uer&in! a current
specification )odicon Fuantu# +=C/
$.1 Class 0 commands detail
5.1.1 Read multiple registers (FC 3)
Request
6&te 'B .C C '3
244135787.doc 8 3/29/99
6&te 1-2B ,eference nu#$er
6&te 3-4B 0ord count -1-125/
Response
6&te 'B .C C '3
6&te 1B 6&te count of response -6C2 1 word count/
6&te 2--6G1/B ,e!ister va%ues
Exceptions
6&te 'B .C C 83 -he1/
6&te 1B e1ception code C '1 or '2
Example
,ead 1 re!ister at reference ' -4'''1 in )odicon 984/ resu%tin! in va%ue 1234 he1
'3 '' '' '' '1 CE '3 '2 12 34
5.1.2 Write multiple registers (FC 16)
Request
6&te 'B .C C 1' -he1/
6&te 1-2B ,eference nu#$er
6&te 3-4B 0ord count -1-1''/
6&te 5B 6&te count -6C2 1 word count/
6&te (--6G5/B ,e!ister va%ues
Response
6&te 'B .C C 1' -he1/
6&te 1-2B ,eference nu#$er
6&te 3-4B 0ord count
Exceptions
6&te 'B .C C 9' -he1/
6&te 1B e1ception code C '1 or '2
Example
0rite 1 re!ister at reference ' -4'''1 in )odicon 984/ of va%ue 1234 he1
1' '' '' '' '1 '2 12 34 CE 1' '' '' '' '1
$.2 Class 1 commands detail
5.2.1 Read coils (FC 1)
Request
244135787.doc 9 3/29/99
6&te 'B .C C '1
6&te 1-2B ,eference nu#$er
6&te 3-4B 6it count -1-2'''/
Response
6&te 'B .C C '1
6&te 1B 6&te count of response -6C-$it countG7//8/
6&te 2--6G1/B 6it va%ues -%east si!nificant $it is first coi%H/
Exceptions
6&te 'B .C C 81 -he1/
6&te 1B e1ception code C '1 or '2
Example
,ead 1 coi% at reference ' -''''1 in )odicon 984/ resu%tin! in va%ue 1
'1 '' '' '' '1 CE '1 '1 '1
8ote that the for#at of the return data is not consistent with a $i!-endian architecture. 8ote a%so that this
re2uest can $e ver& co#putation-intensive on the s%ave if the re2uest ca%%s for #u%tip%e words and the& are
not a%i!ned on 1(-$it $oundaries.
5.2.2 Read input discretes (FC 2)
Request
6&te 'B .C C '2
6&te 1-2B ,eference nu#$er
6&te 3-4B 6it count -1-2'''/
Response
6&te 'B .C C '2
6&te 1B 6&te count of response -6C-$it countG7//8/
6&te 2--6G1/B 6it va%ues -%east si!nificant $it is first coi%H/
Exceptions
6&te 'B .C C 82 -he1/
6&te 1B e1ception code C '1 or '2
Example
,ead 1 discrete input at reference ' -1'''1 in )odicon 984/ resu%tin! in va%ue 1
'2 '' '' '' '1 CE '2 '1 '1
8ote that the for#at of the return data is not consistent with a $i!-endian architecture. 8ote a%so that this
re2uest can $e ver& co#putation-intensive on the s%ave if the re2uest ca%%s for #u%tip%e words and the& are
not a%i!ned on 1(-$it $oundaries.
244135787.doc 1' 3/29/99
5.2.3 Read input registers (FC )
Request
6&te 'B .C C '4
6&te 1-2B ,eference nu#$er
6&te 3-4B 0ord count -1-125/
Response
6&te 'B .C C '4
6&te 1B 6&te count of response -6C2 1 word count/
6&te 2--6G1/B ,e!ister va%ues
Exceptions
6&te 'B .C C 84 -he1/
6&te 1B e1ception code C '1 or '2
Example
,ead 1 input re!ister at reference ' -3'''1 in )odicon 984/ resu%tin! in va%ue 1234 he1
'4 '' '' '' '1 CE '4 '2 12 34
5.2. Write coil (FC 5)
Request
6&te 'B .C C '5
6&te 1-2B ,eference nu#$er
6&te 3B C .. to turn coi% O89 C'' to turn coi% O..
6&te 4B C ''
Response
6&te 'B .C C '5
6&te 1-2B ,eference nu#$er
6&te 3B C .. to turn coi% O89 C'' to turn coi% O.. -echoed/
6&te 4B C ''
Exceptions
6&te 'B .C C 85 -he1/
6&te 1B e1ception code C '1 or '2
Example
0rite 1 coi% at reference ' -''''1 in )odicon 984/ to the va%ue 1
'5 '' '' .. '' CE '5 '' '' .. ''
5.2.5 Write single register (FC 6)
Request
244135787.doc 11 3/29/99
6&te 'B .C C '(
6&te 1-2B ,eference nu#$er
6&te 3-4B ,e!ister va%ue
Response
6&te 'B .C C '(
6&te 1-2B ,eference nu#$er
6&te 3-4B ,e!ister va%ue
Exceptions
6&te 'B .C C 8( -he1/
6&te 1B e1ception code C '1 or '2
Example
0rite 1 re!ister at reference ' -4'''1 in )odicon 984/ of va%ue 1234 he1
'( '' '' 12 34 CE '( '' '' 12 34
5.2.6 Read exception status (FC !)
8ote that ;e1ception status< has nothin! to do with ;e1ception response<. 7he ;read e1ception status<
#essa!e was intended to a%%ow #a1i#u# responsiveness in the ear%& )O6:S po%%ed #u%tidrop
networ*s usin! s%ow $aud rates. +=C<s wou%d t&pica%%& #ap a ran!e of 8 coi%s -output discretes/ which
wou%d $e interro!ated usin! this #essa!e.
Request
6&te 'B .C C '7
Response
6&te 'B .C C '7
6&te 1B 31ception status -usua%%& a predefined ran!e of 8 coi%s/
Exceptions
6&te 'B .C C 87 -he1/
6&te 1B e1ception code C '1 or '2
Example
,ead e1ception status resu%tin! in va%ue 34 he1
'7 CE '7 34
$.3 Class 2 commands detail
5.3.1 Force multiple coils (FC 15)
244135787.doc 12 3/29/99
Request
6&te 'B .C C '. -he1/
6&te 1-2B ,eference nu#$er
6&te 3-4B 6it count -1-8''/
6&te 5B 6&te count -6 C -$it count G 7//8/
6&te (--6G5/B ata to $e written -%east si!nificant $it C first coi%/
Response
6&te 'B .C C '. -he1/
6&te 1-2B ,eference nu#$er
6&te 3-4B 6it count
Exceptions
6&te 'B .C C 8. -he1/
6&te 1B e1ception code C '1 or '2
Example
0rite 3 coi%s at reference ' -''''1 in )odicon 984/ to va%ues '9'91
'. '' '' '' '3 '1 '4 CE '. '' '' '' '3
8ote that the for#at of the input data is not consistent with a $i!-endian architecture. 8ote a%so that this
re2uest can $e ver& co#putation-intensive on the s%ave if the re2uest ca%%s for #u%tip%e words and the& are
not a%i!ned on 1(-$it $oundaries.
5.3.2 Read general re"erence (FC 2#)
Request
6&te 'B .C C 14 -he1/
6&te 1B 6&te count for re#ainder of re2uest -C7 1 nu#$er of !roups/
6&te 2B ,eference t&pe for first !roup C '( for (1111 e1tended re!ister fi%es
6&te 3-(B ,eference nu#$er for first !roup
C fi%e nu#$erBoffset for (1111 fi%es
C 32 $it reference nu#$er for 41111 re!isters
6&te 7-8B 0ord count for first !roup
6&tes 9-15B -as for $&tes 2-89 for 2nd !roup/
. . .
Response
6&te 'B .C C 14 -he1/
6&te 1B Overa%% $&te count of response
-Cnu#$er of !roups G su# of $&te counts for !roups/
6&te 2B 6&te count for first !roup -61C1 G -2 1 word count//
6&te 3B ,eference t&pe for first !roup
6&te 4--61G2/B ,e!ister va%ues for first !roup
6&te -61G3/B 6&te count for second !roup -62C1 G -2 1 word count//
6&te -61G4/B ,eference t&pe for second !roup
6&te -61G5/--61G62G2/B ,e!ister va%ues for second !roup
. . .
Exceptions
244135787.doc 13 3/29/99
6&te 'B .C C 94 -he1/
6&te 1B e1ception code C '1 or '2 or '3 or '4
Example
,ead 1 e1tended re!ister at reference 1B2 -.i%e 1 offset 2 in )odicon 984/ resu%tin! in va%ue 1234 he1
14 '7 '( '' '1 '' '2 '' '1 CE 14 '4 '3 '( 12 34
-future/
,ead 1 re!ister at reference ' returnin! 1234 he19 and 2 re!isters at reference 5 returnin! 5(78 and 9a$c
he1
14 '3 '4 '' '' '' '' '' '1 '4 '' '' '' '5 '' '2 CE 14 '4 '3 '4 12 34 '5 '4 5( 78 94 6C
8ote that the transfer si?e %i#its are difficu%t to define in a #athe#atica% for#u%a. 6road%&9 the #essa!e
si?es for re2uest and response are each %i#ited to 25( $&tes for $uffer si?e reasons9 and the a!!re!ate si?e
of the individua% re2uest and response data fra#es #ust $e considered. 31ception t&pe '4 wi%% $e
!enerated if the s%ave is unwi%%in! to process the #essa!e $ecause the response wou%d $e too %ar!e.
5.3.3 Write general re"erence (FC 21)
Request
6&te 'B .C C 15 -he1/
6&te 1B 6&te count for re#ainder of re2uest
6&te 2B ,eference t&pe for first !roup C '( for (1111 e1tended re!ister fi%es
6&te 3-(B ,eference nu#$er for first !roup
C fi%e nu#$erBoffset for (1111 fi%es
C 32 $it reference nu#$er for 41111 re!isters
6&te 7-8B 0ord count for first !roup -01/
6&te 9--8 G 2 1 01/B ,e!ister data for first !roup
-cop& !roup data fra#e fro# $&te 2 on for an& other !roups/
. . .
Response
,esponse is a direct echo of the 2uer&
6&te 'B .C C 15 -he1/
6&te 1B 6&te count for re#ainder of re2uest
6&te 2B ,eference t&pe for first !roup C '( for (1111 e1tended re!ister fi%es
6&te 3-(B ,eference nu#$er for first !roup
C fi%e nu#$erBoffset for (1111 fi%es
C 32 $it reference nu#$er for 41111 re!isters
6&te 7-8B 0ord count for first !roup -01/
6&te 9--8 G 2 1 01/B ,e!ister data for first !roup
-cop& !roup data fra#e fro# $&te 2 on for an& other !roups/
. . .
Exceptions
6&te 'B .C C 95 -he1/
244135787.doc 14 3/29/99
6&te 1B e1ception code C '1 or '2 or '3 or '4
Example
0rite 1 e1tended re!ister at reference 1B2 -.i%e 1 offset 2 in )odicon 984/ to va%ue 1234 he1
15 '9 '( '' '1 '' '2 '' '1 12 34 CE 15 '9 '( '' '1 '' '2 '' '1 12 34
-future/
0rite 1 re!ister at reference ' to va%ue 1234 he19 and 2 re!isters at reference 5 to va%ues 5(78 and 9a$c
he1
15 14 '4 '' '' '' '' '' '1 12 34 '4 '' '' '' '5 '' '2 5( 78 94 6C
15 14 '4 '' '' '' '' '' '1 12 34 '4 '' '' '' '5 '' '2 5( 78 94 6C
8ote that the transfer si?e %i#its are difficu%t to define in a #athe#atica% for#u%a. 6road%&9 the #essa!e
si?es for re2uest and response are each %i#ited to 25( $&tes for $uffer si?e reasons9 and the a!!re!ate si?e
of the individua% re2uest and response data fra#es #ust $e considered. 31ception t&pe '4 wi%% $e
!enerated if the s%ave is unwi%%in! to process the #essa!e $ecause the response wou%d $e too %ar!e.
5.3. $as% &rite register (FC 22)
Request
6&te 'B .C C 1( -he1/
6&te 1-2B ,eference nu#$er
6&te 3-4B 48 #as* to $e app%ied to re!ister
6&te 5-(B O, #as* to $e app%ied to re!ister
Response
6&te 'B .C C 1( -he1/
6&te 1-2B ,eference nu#$er
6&te 3-4B 48 #as* to $e app%ied to re!ister
6&te 5-(B O, #as* to $e app%ied to re!ister
Exceptions
6&te 'B .C C 9( -he1/
6&te 1B e1ception code C '1 or '2
Example
Chan!e the fie%d in $its '-3 of re!ister at reference ' -4'''1 in )odicon 984/ to va%ue 4 he1
-48 with '''.9 O, with '''4/
1( '' '' '' '. '' '4 CE 1( '' '' '' '. '' '4
5.3.5 Read'&rite registers (FC 23)
Request
6&te 'B .C C 17 -he1/
6&te 1-2B ,eference nu#$er for read
6&te 3-4B 0ord count for read -1-125/
244135787.doc 15 3/29/99
6&te 5-(B ,eference nu#$er for write
6&te 7-8B 0ord count for write -1-1''/
6&te 9B 6&te count -6 C 2 1 word count for write/
6&te 1'--6G9/B ,e!ister va%ues
Response
6&te 'B .C C 17 -he1/
6&te 1B 6&te count-6 C 2 1 word count for read/
6&te 2--6G1/ ,e!ister va%ues
Exceptions
6&te 'B .C C 97 -he1/
6&te 1B e1ception code C '1 or '2
Example
0rite 1 re!ister at reference 3 -4'''4 in )odicon 984/ of va%ue '123 he1 and read 2 re!isters at reference
' returnin! va%ues '''4 and 5(78 he1
17 '' '' '' '2 '' '3 '' '1 '2 '1 23 CE 17 '4 '' '4 5( 78
8ote that if the re!ister ran!es for writin! and readin! over%ap9 the resu%ts are undefined. So#e devices
i#p%e#ent the write $efore the read9 $ut others i#p%e#ent the read $efore the write.
5.3.6 Read F(F) queue (FC 2)
Request
6&te 'B .C C 18 -he1/
6&te 1-2B ,eference nu#$er
Response
6&te 'B .C C 18 -he1/
6&te 1-2B 6&te count -6 C 2 G word count/ -#a1i#u# (4/
6&te 3-4B 0ord count -nu#$er of words accu#u%ated in .".O/ -#a1i#u# 31/
6&te 5--6G2/B ,e!ister data fro# front of .".O
Exceptions
6&te 'B .C C 98 -he1/
6&te 1B e1ception code C '1 or '2 or '3
Example
,ead contents of .".O $%oc* startin! at reference '''5 -4'''( in )odicon 984/ which contains 2 words
of va%ue 1234 and 5(78 he1 outstandin!
18 '' '5 CE 18 '' '( '' '2 12 34 5( 78
8ote that this function as i#p%e#ented on the 984 is ver& %i#ited in versati%it& - the $%oc* of re!isters is
assu#ed to consist of a count which can have va%ues fro# ' to 319 fo%%owed $& up to 31 words of data.
0hen the function co#p%etes9 the count word is 8O7 reset to ?ero9 as #i!ht have $een e1pected fro# a
.".O operation.
244135787.doc 1( 3/29/99
4%% in a%%9 this shou%d $e considered a %i#ited su$set of fn 1( - read #u%tip%e re!isters9 since the %atter can
$e used to perfor# a%% of the re2uired functiona%it&.
*. E+ception co,es
7here is a defined set of e1ception codes to $e returned $& s%aves in the event of pro$%e#s. 8ote that
#asters #a& send out co##ands ;specu%ative%&<9 and use the success or e1ception codes received to
deter#ine which )O6:S co##ands the device is wi%%in! to respond to and to deter#ine the si?e of the
various data re!ions avai%a$%e on the s%ave.
4%% e1ceptions are si!na%ed $& addin! '18' to the function code of the re2uest9 and fo%%owin! this $&te $&
a sin!%e reason $&te for e1a#p%e as fo%%ows
'3 12 34 '' '1 CE 83 '2
re2uest read 1 re!ister at inde1 '11234 response e1ception t&pe 2 - ;i%%e!a% data address<
7he %ist of e1ceptions fo%%ows
'1 "==354= .:8C7%O8
7he function code received in the 2uer& is not an a%%owa$%e action for the s%ave. 7his #a& $e
$ecause the function code is on%& app%ica$%e to newer contro%%ers9 and was not i#p%e#ented in the
unit se%ected. "t cou%d a%so indicate that the s%ave is in the wron! state to process a re2uest of this
t&pe9 for e1a#p%e $ecause it is unconfi!ured and is $ein! as*ed to return re!ister va%ues.
'2 "==354= 474 4,3SS
7he data address received in the 2uer& is not an a%%owa$%e address for the s%ave. )ore
specifica%%&9 the co#$ination of reference nu#$er and transfer %en!th is inva%id. .or a contro%%er
with 1'' re!isters9 a re2uest with offset 9( and %en!th 4 wou%d succeed9 a re2uest with offset 9(
and %en!th 5 wi%% !enerate e1ception '2.
'3 "==354= 474 @4=:3
4 va%ue contained in the 2uer& data fie%d is not an a%%owa$%e va%ue for the s%ave. 7his indicates a
fau%t in the structure of the re#ainder of a co#p%e1 re2uest9 such as that the i#p%ied %en!th is
incorrect. "t specifica%%& does 8O7 #ean that a data ite# su$#itted for stora!e in a re!ister has a
va%ue outside the e1pectation of the app%ication pro!ra#9 since the )O6:S protoco% is unaware
of the si!nificance of an& particu%ar va%ue of an& particu%ar re!ister.
'4 "==354= ,3S+O8S3 =3857>
"ndicates that the re2uest as fra#ed wou%d !enerate a response whose si?e e1ceeds the avai%a$%e
)O6:S data si?e. :sed on%& $& functions !eneratin! a #u%ti-part response9 such as functions
2' and 21.
'5 4CI8O0=353
Specia%i?ed use in conJunction with pro!ra##in! co##ands
'( S=4@3 3@%C3 6:SA
Specia%i?ed use in conJunction with pro!ra##in! co##ands
'7 83547%@3 4CI8O0=353
244135787.doc 17 3/29/99
Specia%i?ed use in conJunction with pro!ra##in! co##ands
'8 )3)O,A +4,%7A 3,,O,
Specia%i?ed use in conJunction with function codes 2' and 219 to indicate that the e1tended fi%e
area fai%ed to pass a consistenc& chec*.
'4 547304A +47> :84@4"=46=3
Specia%i?ed use in conJunction with )od$us +%us !atewa&s9 indicates that the !atewa& was una$%e
to a%%ocate a )od$us +%us +47> to use to process the re2uest. :sua%%& #eans that the !atewa& is
#isconfi!ured.
'6 547304A 74,537 3@"C3 .4"=3 7O ,3S+O8
Specia%i?ed use in conJunction with )od$us +%us !atewa&s9 indicates that no response was
o$tained fro# the tar!et device. :sua%%& #eans that the device is not present on the networ*.
Appen,ices
A. C%ient an, Se!e! I$p%e$entation -ui,ance
7he co##ents in this section shou%d not $e re!arded as $indin! upon an& particu%ar i#p%e#entation of a
c%ient or server. >owever9 if fo%%owed9 these po%icies wi%% #ini#i?e inte!ration ;surprises< when
i#p%e#entin! #u%ti-vendor s&ste#s and !atewa&s to insta%%ed )O6:S e2uip#ent.
7he software structure $e%ow assu#es fa#i%iarit& with the 6S Soc*ets service interface9 as used on for
e1a#p%e :8"D and 0indows 87.
%.1 Client design
)O6:S/7C+ is desi!ned to a%%ow the desi!n of a c%ient to $e as si#p%e as possi$%e. 31a#p%es of
software are !iven e%sewhere9 $ut the $asic process of hand%in! a transaction is as fo%%ows
3sta$%ish a 7C+ connection to port 5'2 at the desired server usin! connect-/
+repare a )O6:S re2uest9 encoded as descri$ed $efore
Su$#it the )O6:S re2uest9 inc%udin! its (-$&te )O6:S/7C+ prefi19 as a sin!%e $uffer to $e
trans#itted usin! send-/
0ait for a response to appear on the sa#e 7C+ connection. Optiona%%&9 run a ti#eout on this step9
usin! se%ect-/9 if &ou wish to $e advised of co##unication pro$%e#s faster than 7C+ wou%d
nor#a%%& report.
,ead9 usin! recv-/9 the first ( $&tes of the response9 which wi%% indicate the actua% %en!th of the
response #essa!e
:se recv-/ to read the re#ainin! $&tes of the response.
"f no further co##unication is e1pected to this particu%ar tar!et in the i##ediate future9 c%ose
down the 7C+ connection so that the resources at the server can $e used in the interi# to serve
244135787.doc 18 3/29/99
other c%ients. 4 ti#e of 1 second is su!!ested as the #a1i#u# period to %eave a connection open
at the c%ient.
"n the event of a ti#eout waitin! for a response9 issue a uni%atera% c%ose of the connection9 open up a new
one9 and resu$#it the re2uest. 7his techni2ue a%%ows the c%ient contro% of retr& ti#in! which is superior to
that provided $& defau%t $& 7C+. "t a%so a%%ows for a%ternate fa%%$ac* strate!ies9 such as su$#ittin! the
re2uest to an a%ternate "+ address9 usin! a tota%%& independent co##unication networ*9 in case of fai%ure
of a networ* infrastructure co#ponent.
%.2 &er!er design
4 )O6:S/7C+ server shou%d a%wa&s $e desi!ned to support #u%tip%e concurrent c%ients9 even if in its
intended use on%& a sin!%e c%ient appears to #a*e sense. 7his a%%ows a c%ient to c%ose and reopen the
connection in rapid se2uence in order to respond 2uic*%& to non-de%iver& of a response.
"f a conventiona% 7C+ protoco% stac* is used9 si!nificant #e#or& resources can $e saved $& reducin! the
receive and trans#it $uffer si?es. 4 nor#a% 7C+ service on :8"D or 87 wou%d usua%%& a%%ocate 8I $&tes
or #ore as a per-connection receive $uffer in order to encoura!e ;strea#ed< transfer of data fro# for
e1a#p%e fi%e servers. Such $uffer space has no va%ue in )O6:S/7C+9 since the #a1i#u# si?e of a
re2uest or response is %ess than 3'' $&tes. "t is often possi$%e to trade the stora!e space for additiona%
connection resources.
3ither a #u%tithreaded or sin!%e-threaded #ode% can $e used to hand%e the #u%tip%e connections.
escriptions fo%%ow in the ne1t sections.
*.2.1 $ultit+readed ser,er
Operatin! s&ste#s or %an!ua!es which encoura!e the use of #u%tip%e threads9 such as K4@49 can use the
#u%tithreaded strate!&9 descri$ed hereB

:se %isten-/ to wait for inco#in! connections on 7C+ port 5'2
0hen a new connection re2uest is received9 use accept-/ to accept it and spawn a new thread to hand%e the
connection
0ithin the new thread9 do the fo%%owin! in an infinite %oopB
"ssue a recv-(/ re2uest for the ( $&te )O6:S/7C+ header. o not p%ace a ti#eout here9 $ut
instead $e wi%%in! to wait unti% either a re2uest co#es throu!h or the connection is c%osed. 6oth
situations wi%% wa*e up the thread auto#atica%%&.
4na%&?e the header. "f it appears corrupt9 for e1a#p%e the protoco% fie%d is non-?ero or the %en!th
of #essa!e is %ar!er than 25(9 then :8"=473,4==A C=OS3 7>3 CO883C7"O8. 7his is the
correct response as a server to a situation i#p%&in! the 7C+ encodin! is incorrect.
"ssue a recv-/ for the re#ainin! $&tes of the #essa!e9 whose %en!th is now *nown. 8ote in
particu%ar that issuin! a recv-/ with a %i#it %i*e this on the %en!th wi%% to%erate c%ients who insist
on ;pipe%inin!< re2uests. 4n& such pipe%ined re2uests wou%d re#ain in the 7C+ $uffers at either
server or c%ient9 and $e pic*ed up %ater9 when the current re2uest has co#p%eted service.
8ow process the inco#in! )O6:S #essa!e9 if necessar& suspendin! the current thread unti%
the correct response can $e ca%cu%ated. 3ventua%%& &ou wi%% have either a va%id )O6:S #essa!e
or an 3DC3+7"O8 #essa!e to use as a response
244135787.doc 19 3/29/99
5enerate the )O6:S/7C+ prefi1 for the response9 cop&in! the ;transaction identifier< fie%d
fro# $&tes ' and 1 of the re2uest9 and reca%cu%atin! the %en!th fie%d.
Su$#it the response9 inc%udin! the )O6:S/7C+ prefi19 as a sin!%e $uffer for trans#ission on
the connection9 usin! send-/
5o $ac* and wait for the ne1t ( $&te prefi1 record.
3ventua%%&9 when the c%ient e%ects to c%ose the connection9 the recv-/ of the ( L $&te prefi1 wi%% fai%. 4n
order%& c%ose wi%% usua%%& resu%t in a recv-/ with a ?ero return $&te count. 4 force c%ose #a& !enerate an
error return fro# the recv-/. "n either case9 c%ose the connection and cance% the current thread.
*.2.2 -ingle.t+readed ser,er
So#e e#$edded s&ste#s and o%der operatin! s&ste#s such as :8"D and )S-OS encoura!e the hand%in!
of #u%tip%e connections usin! the ;se%ect< ca%% fro# the soc*ets interface. "n such a s&ste#9 instead of
hand%in! the processin! of individua% concurrent re2uests in their own thread9 &ou can hand%e the re2uests
as #u%tip%e state #achines within a co##on hand%er. =an!ua!es such as CGG #a*e the structure of
software %i*e this convenient.
7he structure now wou%d $e as fo%%ows
"nitia%i?e #u%tip%e state #achines $& settin! their state to ;id%e<
%isten-/ for inco#in! connections on 7C+ port 5'2
8ow start an infinite %oop chec*in! the ;%isten< port and the state #achines as fo%%owsB
On the %isten port9 if a new connection re2uest is received9 use accept-/ to accept it and cause one
of the state #achines to chan!e state fro# ;id%e< to ;new re2uest< to process the inco#in!
connection
.or each of the state #achines
"f state is ;new re2uest<B
:se se%ect-/ to see whether a re2uest has arrived. 8or#a%%& set the ti#eout to
?ero9 since &ou don<t wish to suspend the process $ecause of inactivit& on this
particu%ar connection.
"f se%ect-/ indicates there is a pac*et9 use recv-(/ to read the header as in the
#u%tithreaded case. "f the header is corrupt9 C=OS3 7>3 CO883C7"O8 and
set the state #achine to id%e.
"f the read succeeded and se%ect-/ indicates that #ore input is avai%a$%e9 read
the rest of the re2uest.
"f the re2uest is co#p%ete9 chan!e the state of the session to ;await response<.
"f the recv-/ returns indicatin! that the connection is no %on!er in use9 c%ose the
connection and reset the state #achine to ;id%e<.
"f state is ;await response<
244135787.doc 2' 3/29/99
See if the app%ication response infor#ation is avai%a$%e9 if it is9 $ui%d up the
response pac*et9 and send it usin! send-/9 e1act%& as for the #u%tithreaded case.
Set the state to ;new re2uest<
"t is possi$%e to opti#i?e perfor#ance $& co#$inin! the #u%tip%e se%ect-/ ca%%s into a sin!%e ca%% on a per-
c&c%e $asis9 without affectin! the functiona% structure of the app%ication.
%.3 'e(uired and e)pected performance
7here is de%i$erate%& 8O specification of re2uired response ti#e for a transaction over )O6:S or
)O6:S/7C+.
7his is $ecause )O6:S/7C+ is e1pected to $e used in the widest possi$%e variet& of co##unication
situations9 fro# "/O scanners e1pectin! su$-#i%%isecond ti#in! to %on! distance radio %in*s with de%a&s of
severa% seconds.
"n addition9 the )O6:S fa#i%& is desi!ned to encoura!e auto#atic conversion $etween networ*s $&
#eans of ;$%ind< conversion !atewa&s. Such devices inc%ude the Schneider ;3thernet to )od$us +%us
6rid!e<9 and various devices which convert fro# )O6:S/7C+ to )O6:S seria% %in*s. :se of such
devices i#p%ies that the perfor#ance of e1istin! )O6:S devices is consistent with use of
)O6:S/7C+.
"n !enera%9 devices such as +=C<s which e1hi$it a ;scan< $ehavior wi%% respond to inco#in! re2uests in
one scan ti#e9 which t&pica%%& varies $etween 2' #sec and 2'' #sec.
.ro# a c%ient perspective9 that ti#e #ust $e e1tended $& the e1pected transport de%a&s across the networ*9
to deter#ine a ;reasona$%e< response ti#e. Such transport de%a&s #i!ht $e #i%%iseconds for a switched
3thernet9 or hundreds of #i%%iseconds for a wide area networ* connection.
"n turn9 an& ;ti#eout< ti#e used at a c%ient to initiate an app%ication retr& shou%d $e %ar!er than the
e1pected #a1i#u# ;reasona$%e< response ti#e. "f this is not fo%%owed9 there is a potentia% for e1cessive
con!estion at the tar!et device or on the networ*9 which #a& in turn cause further errors. 7his is a
characteristic which shou%d a%wa&s $e avoided.
So in practice9 the c%ient ti#eouts used in hi!h perfor#ance app%ications are a%wa&s %i*e%& to $e so#ewhat
dependent on networ* topo%o!& and e1pected c%ient perfor#ance.
4 ti#eout of sa& 3' #sec #i!ht $e reasona$%e when scannin! 1' "/O devices across a %oca% 3thernet and
each device wou%d nor#a%%& respond in 1 #sec. On the other hand9 a ti#eout va%ue of 1 second #i!ht $e
#ore appropriate when supervisin! s%ow +=C<s throu!h a !atewa& across a seria% %in*9 where the nor#a%
scan se2uence co#p%eted in 3'' #sec.
4pp%ications which are not ti#e critica% can often %eave ti#eout va%ues to the nor#a% 7C+ defau%ts9 which
wi%% report co##unication fai%ure after severa% seconds on #ost p%atfor#s.
C%ients are encoura!ed to c%ose and re-esta$%ish )O6:S/7C+ connections which are used for data
access on%& -not +=C pro!ra##in!/ and where the e1pected ti#e $efore ne1t use is si!nificant9 for
e1a#p%e %on!er than one second. "f c%ients fo%%ow this princip%e9 it a%%ows a server with %i#ited connection
resources to service a %ar!er nu#$er of potentia% c%ients9 as we%% as faci%itatin! error recover& strate!ies
such as se%ection of a%ternative tar!et "+ addresses. "t shou%d $e re#e#$ered that the e1tra co##unication
and C+: %oad caused $& c%osin! and reopenin! a connection is co#para$%e to that caused $& a S"85=3
)od$us transaction.
B. Data Enco,in. fo! non/"o!, ,ata
244135787.doc 21 3/29/99
7he #ost efficient #ethod of transportin! $u%* infor#ation of an& t&pe over )O6:S us to use function
codes 3 -read re!isters/9 1( -write re!isters/9 or possi$%& 23 -read/write re!isters/.
4%thou!h these functions are defined in ter#s of their operation on 1(-$it re!isters9 the& can $e used to
#ove an& t&pe of infor#ation fro# one #achine to another9 so %on! as that infor#ation can $e represented
as a conti!uous $%oc* of 1(-$it words.
7he ori!ina% )O6:S-capa$%e +=C<s were specia%i?ed co#puters usin! a ;$i!-endian< architecture. )ost
#odern +=C<s are $ased on co##odit& #icroprocessors usin! a ;%itt%e-endian< architecture. 7he fact that
)O6:S is used to e1chan!e data potentia%%& $etween these two architectures introduces so#e su$t%eties
which can trap the unwar&.
4%#ost a%% data t&pes other than the pri#itive ;discrete $it< and <1( $it re!ister< were introduced after the
adoption of %itt%e-endian #icroprocessors. 7herefore the representation on )O6:S of these data t&pes
fo%%ows the %itt%e-endian #ode%9 #eanin!
.irst re!ister $its 15 - ' C $its 15 - ' of data ite#
Second re!ister $its 15 - ' C $its 31 - 1( of data ite#
7hird re!ister $its 15 - ' C $its 47 - 32 of data ite#
etc. etc.
*.1 *it numbers "ithin a "ord
)odicon +=C<s have predefined functions in the 984 =adder =an!ua!e which wi%% convert a series of
conti!uous re!isters into an e2uiva%ent %en!th $%oc* of 1-$it ;discretes<. 7he #ost co##on such function
is 6=I) -6%oc* )ove/.
.or consistenc& with the ori!ina% $i!-endian architecture9 such discretes were nu#$ered fro# #ost
si!nificant $it to %east si!nificant $it9 and to add #ore confusion9 a%% nu#$er se2uences started at one9 not
?ero. -6it nu#$ers within this docu#ent are a%wa&s referenced fro# ?ero as the %east si!nificant $it9 to $e
consistent with #odern software docu#entation/
So within a word -re!ister/
iscrete 1 wou%d $e $it 15 -va%ue '18'''/
iscrete 2 wou%d $e $it 14 -va%ue '14'''/
iscrete 3 wou%d $e $it 13 -va%ue '12'''/
iscrete 4 wou%d $e $it 12 -va%ue '11'''/
iscrete 5 wou%d $e $it 11 -va%ue '1'8''/
iscrete ( wou%d $e $it 1' -va%ue '1'4''/
iscrete 7 wou%d $e $it 9 -va%ue '1'2''/
iscrete 8 wou%d $e $it 8 -va%ue '1'1''/
iscrete 9 wou%d $e $it 7 -va%ue '1''8'/
iscrete 1' wou%d $e $it ( -va%ue '1''4'/
iscrete 11 wou%d $e $it 5 -va%ue '1''2'/
iscrete 12 wou%d $e $it 4 -va%ue '1''1'/
iscrete 13 wou%d $e $it 3 -va%ue '1'''8/
iscrete 14 wou%d $e $it 2 -va%ue '1'''4/
iscrete 15 wou%d $e $it 1 -va%ue '1'''2/
iscrete 1( wou%d $e $it ' -va%ue '1'''1/
0hen there are #ore than 1( $its9 for e1a#p%e a 32 point discrete input #odu%e9 discretes 1 to 1( wou%d
$e in the first re!ister9 discretes 17 to 32 wou%d $e in the second re!ister.
7his nu#$erin! convention is particu%ar%& i#portant to understand when dea%in! with discrete input or
output devices over )O6:S/7C+9 where the nu#$erin! of the discrete points has $een arran!ed to $e
consistent with )odicon +=C<s.
244135787.doc 22 3/29/99
"n particu%ar9 note that the "3C-1131 nu#$erin! convention for $its within a word is fro# ' -%east
si!nificant/ to 15 -#ost si!nificant/9 which is the opposite of the discrete nu#$erin!.
*.2 Multi-"ord (uantities
"n princip%e9 an& data structure which can $e ;cast< to an arra& of 1(-$it words can $e transported9 and wi%%
arrive unchan!ed on a #achine with the sa#e data representation.
7he fo%%owin! +=C data t&pes shou%d $e noted
/.2.1 01 2ata 34pes
01 16.5it 6nsigned (nteger
8atura% #eanin!B $it 15 - ' of inte!er C $it 15 - ' of re!ister
01 16.5it -igned (nteger
8atura% #eanin!B $it 15 - ' of inte!er C $it 15 - ' of re!ister
01 *-C((
4%thou!h +=C<s had no te1t #anipu%ation capa$i%ities as such9 the ori!ina% %adder %an!ua!e
editors a%%owed re!isters to $e disp%a&ed as 2 4SC"" characters each. 7he first character disp%a&ed
was the :++3, $&te -$its 15 - 8/ and the second character disp%a&ed was the =O03, $&te -$its
7- '/. 8ote in particu%ar that this is the reverse of an& use of a character arra& in C or other hi!h
%eve% %an!ua!es on #odern +=C<s.
01 Floating point
"nte% sin!%e precision rea%
.irst re!ister contains $its 15 - ' of 32-$it nu#$er -$its 15 - ' of si!nificand/
Second re!ister contains $its 31 - 1( of 32-$it nu#$er -e1ponent and $its 23 - 1( of si!nificand/
01 -ingle precision unsigned decimal
4%thou!h the ran!e of va%ues is %i#ited at ' - 99999 the data representation is the sa#e as a 1(-$it
unsi!ned inte!er
01 2ou5le precision unsigned decimal
7his data for#at is now %itt%e-used9 e1cept to drive o%d-st&%e 4-di!it decade disp%a&s.
7he ran!e of va%ues is ' to 99999999. 7he first re!ister contains the )OS7 si!nificant 4 di!its9
the second re!ister contains the =34S7 si!nificant 4 di!its9 each e1pressed as $inar& va%ues in
the ran!e '-9999.
/.2.2 (EC.1131 data t4pes
4%% "3C-1131 data t&pes are represented on )odicon +=C<s in %itt%e-endian for#. 31a#p%es fo%%ow
/73E
8-$it 2uantit&.
6its 7 - ' of re!ister C 6its 7 - ' of 6A73
244135787.doc 23 3/29/99
2(83
32-$it 2uantit&.
6its 15 - ' of first re!ister C $its 15 - ' of "87
6its 15 - ' of second re!ister C $its 31 - 1( of "87
(83
6its 15 - ' of re!ister C $its 15 - ' of "87
RE*9
32-$it "nte% sin!%e precision rea%
6its 15 - ' of first re!ister C $its 15 - ' of ,34= -$its 15 - ' of si!nificand/
6its 15 - ' of second re!ister C $its 31 - 1( of ,34= -e1ponent G $its 23 - 1( of si!nificand/
62(83
32-$it 2uantit&.
6its 15 - ' of first re!ister C $its 15 - ' of :"87
6its 15 - ' of second re!ister C $its 31 - 1( of :"87
6(83
6its 15 - ' of re!ister C $its 15 - ' of "87
.or an& others9 see the appropriate "3C-1131 pro!ra##in! #anua%s
244135787.doc 24 3/29/99

You might also like