Communications Modbus Functionality
Communications Modbus Functionality
CommunicationsModbusFunctionality
Topic:P198
CommunicationsModbusFunctionality
Master/Client
Function
Codeand
DataType
Support
ThefollowingtableliststheModbusdatatype,thefunctioncodeandtheCPUsourcedatatypethatis
supportedwhentheCPUistheClientorMasteronaModbusTCPorserialconnection.
ModbusClient/MasterSupport(UsingMRXandMWXInstructions)
Modbus
ProductivitySuite
984
Modbus
Function
Function
TagTypes
Addressing
984
Code
Name
(Datadesignation
(Zero
Addressing
orsource)
Based)
01
ReadCoil
Status
000000
065535
000001
065536
DiscreteOutput
(DO)
Boolean(C)
BooleanSystem
(SBRW)
02
ReadCoil
Status
100000
165535
100001
165536
DiscreteInput(DI)
Boolean(C)
BooleanSystem
(SBRW)
400001
465536
Integer8bit
Unsigned(U8)
Integer16bit(S16)
Integer16bit
Unsigned(U16)
Integer16bitBCD
(B16)
Integer32bit(S32)
Integer32bitBCD
(B32)
Integer32bitFloat
(F32)
Integer16bit
System(SWRW)
03
04
Read
Holding
Registers
Read
Input
Registers
Write
Single
Coil
05
06
Write
Single
Register
http://www.automationdirect.com/microsites/p2000/help/198.htm
400000
465535
300000
365535
000000
065535
400000
465535
300001
365536
000001
065536
400001
465536
Integer8bit
Unsigned(U8)
Integer16bit(S16)
Integer16bit
Unsigned(U16)
Integer16bitBCD
(B16)
Integer32bit(S32)
Integer32bitBCD
(B32)
Integer32bitFloat
(F32)
Integer16bit
System(SWRW)
DiscreteInput(DI)
DiscreteOutput
(DO)
Boolean(C)
BooleanSystem
(SBRW)
BooleanSystem
ReadOnly(SBR)
Integer8bit
Unsigned(U8)
Integer16bit(S16)
Integer16bit
Unsigned(U16)
Integer16bitBCD
(B16)
Integer32bit(S32)
Integer32bitBCD
(B32)
Integer32bitFloat
(F32)
Integer16bit
System(SWRW)
1/20
5/10/2016
CommunicationsModbusFunctionality
Integer16bit
SystemReadOnly
(SWR)
15
Write
Multiple
Coils
http://www.automationdirect.com/microsites/p2000/help/198.htm
000000
065535
000001
065536
DiscreteInput(DI)
DiscreteOutput
(DO)
Boolean(C)
BooleanSystem
(SBRW)
BooleanSystem
ReadOnly(SBR)
2/20
5/10/2016
CommunicationsModbusFunctionality
ModbusClient/MasterSupport(UsingMRXandMWXInstructions)
Continued
Productivity
Modbus984
SuiteTagTypes
Function
Function
Addressing
Modbus984
(Data
Name
(Zero
Addressing
Code
designationor
Based)
source)
16
Write
Multiple
Registers
400000
465535
400001
465536
Integer8bit
Unsigned(U8)
Integer16bit(S16)
Integer16bit
Unsigned(U16)
Integer16bitBCD
(B16)
Integer32bit(S32)
Integer32bitBCD
(B32)
Integer32bitFloat
(F32)
Integer16bit
System(SWRW)
Integer16bit
SystemReadOnly
(SWR)
Slave/Server
Function
Codeand
DataType
Support
ThefollowingtableliststheModbusdatatype,thefunctioncodeandtheCPUsourcedatatypethatis
supportedwhentheCPUistheServerorSlaveonaModbusTCPorserialconnection.
ModbusServer/SlaveSupport
Function
Function
Modbus984
ProductivitySuiteTag
Code
Name
Addressing
Types
01
ReadCoil
Status
000001
065536
DiscreteOutput(DO)
Boolean(C)
BooleanSystem(SBRW)
02
ReadCoil
Status
100001
165536
DiscreteInput(DI)
BooleanSystemReadOnly
(SBR)
400001
465536
Integer8bitUnsigned(U8)
Integer16bit(S16)
Integer16bitUnsigned
(U16)
Integer16bitBCD(B16)
Integer32bit(S32)
Integer32bitBCD(B32)
Integer32bitFloat(F32)
Integer16bitSystem
(SWRW)
String
03
Read
Holding
Registers
04
ReadInput
Registers
300001
365536
AnalogInput,Integer32bit
(AIS32)
AnalogInput,Float32bit
(AIF32)
Integer16bitSystemRead
Only(SWR)
05
WriteSingle
Coil
000001
065536
DiscreteOutput(DO)
Boolean(C)
BooleanSystem(SBRW)
WriteSingle
Register
400001
465536
Integer8bitUnsigned(U8)
Integer16bit(S16)
Integer16bitUnsigned
(U16)
Integer16bitBCD(B16)
Integer32bit(S32)
Integer32bitBCD(B32)
Integer32bitFloat(F32)
Integer16bitSystem
(SWRW)
Integer16bitSystemRead
Only(SWR)
String
Write
000001
DiscreteOutput(DO)
06
http://www.automationdirect.com/microsites/p2000/help/198.htm
3/20
5/10/2016
CommunicationsModbusFunctionality
15
http://www.automationdirect.com/microsites/p2000/help/198.htm
Multiple
Coils
065536
Boolean(C)
BooleanSystem(SBRW)
4/20
5/10/2016
CommunicationsModbusFunctionality
Function
Code
16
ModbusServer/SlaveSupport(Continued)
ProductivitySuiteTag
Function
Modbus984
Name
Addressing
Types
Write
Multiple
Registers
400001
465536
Integer8bitUnsigned(U8)
Integer16bit(S16)
Integer16bitUnsigned
(U16)
Integer16bitBCD(B16)
Integer32bit(S32)
Integer32bitBCD(B32)
Integer32bitFloat(F32)
Integer16bitSystem
(SWRW)
Integer16bitSystemRead
Only(SWR)
String
Assigning
Modbus
Addresses
toTags
TherearemanydifferentdatatypesintheCPU.Becauseofthis,theModbusaddressesneedtobemapped
tothevarioustagdatatypesintheCPU.
TherearetwowaystomapModbusaddressestoTagsintheProgrammingsoftware:
ModbusmappinginTagDatabasewindow.
ModbusmappingwhencreatingTags.
1.ModbusmappinginTagDatabasewindow:
ThereareonlytwodatasizesintheModbusprotocol:bitsandwords.IntheCPU,therearemultiple
sizetypes,soitissometimesnecessarytomapmultipleModbusaddressestoasingleTagentity.
TherearealsoarraydatastructuresintheCPU.WhenModbusaddressesaremappedtoarrays,they
willbemappedasacontiguousblockofaddresses.Thisis,infact,themostefficientmethodtohandle
Modbuscommunications.
IntheTagDatabasewindow,therearetwocolumnsnamedModStartandModEnd.Tomapa
ModbusaddresstoatagintheTagDatabasewindow,simplydoubleclickintheModStartfieldfor
theTag.
Whenyoudothis,youwillseetwovaluesappearinthefield.TheleftmostvalueistheModbusdata
type.Thisisfixedbaseduponthetagdatatype.ThechartbelowindicatesthefourdifferentModbus
datatypesinthe984addressingscheme.
http://www.automationdirect.com/microsites/p2000/help/198.htm
5/20
5/10/2016
CommunicationsModbusFunctionality
Address
Identifier
0xxxxx
1xxxxx
3xxxxx
4xxxxx
Modbus984AddressType
Coil(Read/Writebit)
Input(ReadOnlybit)
InputRegister(ReadOnly16bitword)
HoldingRegister(Read/Write16bit
word)
TherightmostvaluethatyouseeintheModStartfieldistheaddressoffset(rangeisfrom165535).
Youcanacceptthevaluethatisprefilledforyouorthevaluecanbechanged.Thesoftware
automaticallyprefillstheaddressoffsetwiththenextavailableaddress.
2.ModbusmappingwhencreatingTags:
ModbusaddressescanbeassignedtoTagsastheyarecreatedintheTagDatabase.
http://www.automationdirect.com/microsites/p2000/help/198.htm
6/20
5/10/2016
CommunicationsModbusFunctionality
TypeintheModbusoffsetvaluewhenenteringtheTagNameandDataType.Iftheaddressisalready
assigned,awarningmessagewillappear.
Modbus
Options
TheModbusprotocoldoesnothaveaspecificmethodoutlinedfordatatypesoutsideofbitsand16bitwords.
Mostsystemsnowhave32bitdatatypes.Inordertotransport32bitdatatypesacrossModbus,theymustbe
placedintotwoModbus16bitregisters.Unfortunately,somedevicesdonotsupportthisandthereare
sometimesincompatibilitiesintheorderofthe16bithighwordandlowwordhandlingbetweenthedevices.
http://www.automationdirect.com/microsites/p2000/help/198.htm
7/20
5/10/2016
CommunicationsModbusFunctionality
Inordertohelpalleviatethissituation,therearesomeoptionsforhandlingthisintheprogrammingsoftware.
TofindtheModbusAddressoptions,gotoFileandclickonProjectPropertiesandthenclickontheModbus
ServerSettingstab.
a.NoexceptionresponsefornonexistingModbusaddressrequests:BecausetheModbus
addressescanbemanuallyassignedtotags,itispossiblethatgapscanoccurintheModbusaddress
mapping.Forexample:Tag1hasModbusaddress400001assignedtoitandTag2hasModbus
address400003assignedtoit.
http://www.automationdirect.com/microsites/p2000/help/198.htm
8/20
5/10/2016
CommunicationsModbusFunctionality
MostModbusMaster/ClientdeviceswillattempttooptimizetheirdatarequeststoaModbus
Slave/Serverdevicebyrequestingblocksofdatainsteadofindividualregisters.Inthecaseabove,
mostModbusmasterswouldsendonereadrequeststartingat400001andasizeofthreeinsteadof
sendingtworeadrequestsstartingat400001withsizeoneand400003withsizeoneasshownbelow.
Intheexampleshownaboveonleft,aModbusSlave/Serverdeviceshouldgiveanexception
responsesincethereisnoModbusAddressof400002inthedevice.Thismethodcancausesalotof
inefficiencies.ByselectingtheNoexceptionresponsefornonexistingModbusaddressrequests
option,theCPUwillnotgiveanexceptionresponsetotherequest.NotethatifModbusaddress
400002byitselfwererequesteditwouldgiveanexceptionresponse.
http://www.automationdirect.com/microsites/p2000/help/198.htm
9/20
5/10/2016
CommunicationsModbusFunctionality
b.Wordswapoption(S32,AIS32,AOS32,F32,FI32,FO32):
Wordswapallowsthewordorderof32bittagstobechangedwhensendingthevaluesacross
Modbus.Thedefaultselectionison,whichreturnsthedatalowwordfirst.
c.Mapvaluetoasingle16bitModbusregister:
Thisoptionallowsforcompatibilitywithdevicesthatdonotsupport32bitModbusfunctionality.This
optioncanbeselectedindividuallyfortheAnalogInputandOutputSigned32datatypesandthe
InternalSigned32datatypes,includingthearrayformofthesedatatypes.Thisfunctionisonlyuseful
whenthevaluecontainedina32bittagdoesnotexceedasigned15bitvalue(32,765).
Tag1(Integer,32Bit)=22136(hex=0x00005678)
With"MapValuetoasingle16Bitregister"turnedOFF=
Tag1Modbusaddress=400001,400002
ModbusreplyforTag1(WordSwapON)=01030456780000
With"MapValuetoasingle16Bitregister"turnedON=
Tag1Modbusaddress=400001
ModbusreplyforTag1=0103025678
d.Mapvaluetotwoconsecutive16bitModbusregisters:Allowsfor32bitdatatypestobemappedto
twoconsecutive16bitregisters.Thisoptionisselectedasdefault.
AlloftheoptionsintheModbusAddresstaboftheProjectPropertiesonlyapplytotheModbus
Slave/Serverfunctionality.SimilaroptionsareavailablefortheModbusMaster/Clientfunctionsas
wellandareavailableintheMRXandMWXModbusinstructions.
http://www.automationdirect.com/microsites/p2000/help/198.htm
10/20
5/10/2016
CommunicationsModbusFunctionality
Modbus
Instructions
ToreadorsetdatainotherModbusSlave/Serverdevices,therearetwoinstructionsavailableinthe
programmingsoftware,ModbusReadandModbusWrite.
TheModbusRead(MRX)instructionisusedtoreaddatafromotherModbusdevicesintoTagsofthe
CPU.
http://www.automationdirect.com/microsites/p2000/help/198.htm
11/20
5/10/2016
CommunicationsModbusFunctionality
TheMRXinstructioncanbeusedforModbusTCPorModbusRTU.Thereareseveralstatusbitsthat
canbeusedtodeterminewhetherthereadmessagewassuccessfulandifitwasnot,thereasonwhy.
ThereisanAutomaticPollingfeatureintheinstructiontomakeiteasiertoreadadeviceonapre
determinedpollrate.Thereisalsoapolloffsetfieldthatcanbeusedwhensimultaneousinstructions
areenabledwiththeAutomaticPollingfeaturetohelpstaggertheflowofmessagesbeingsenttothe
network.
http://www.automationdirect.com/microsites/p2000/help/198.htm
12/20
5/10/2016
CommunicationsModbusFunctionality
TheModbusWrite(MWX)instructionisverysimilarinlayoutandconfigurationtotheMRXinstruction.
ItisusedtowritevaluestoaModbusdevicefromthetagsintheCPU.
TheMWXoperatesverysimilarlytotheMRXinstruction.Therearealsomanystatusbitstoindicatethe
successorreasonoffailurewhensendingamessage.
TheAutomaticPollingoptionisalsoavailabletotheMWXinstruction,althoughgreatercareshouldbe
takenwhenusingthisfeatureinthisinstruction.ThisisexplainedinbetterdetailintheMessage
Queuesection.
http://www.automationdirect.com/microsites/p2000/help/198.htm
13/20
5/10/2016
CommunicationsModbusFunctionality
Network
Instructions
TheNetworkRead(RX)andNetworkWrite(WX)instructionsareusedtocommunicatetootherCPUs.They
areverysimilarinoperationtotheMRXandMWXinstructionsbuttheytargetTagNamesinsteadofModbus
addressesintheotherCPU.ThereisalsoasignificantperformancegaininusingtheRXandWXinstructions
whencommunicatingtootherCPUsasopposedtousingtheMRXandMWXinstructions.
http://www.automationdirect.com/microsites/p2000/help/198.htm
14/20
5/10/2016
CommunicationsModbusFunctionality
ThesamestatusbitsareavailableintheRXinstructionasintheMRXinstructionandoperateinthesame
manner.ThegreatestdifferenceintheRXversustheMRXisthatwiththeRX,theTagNameinthetargetCPU
canbereferenceddirectlyanddoesnotneedacorrespondingModbusaddress.Thewaythisis
accomplishedisbymappinglocalandremotetagnamestogetherwithinthelocalCPU'sRXinstruction.Once
theinstructionissetuptoreadaremoteproject,theTagsofRemoteProjectorArrayTagsofRemote
Projectdropdownlistswillbeaccessible.MaptheTagoftheRemoteprojecttoaTagintheLocalprojectto
readthisdata.
http://www.automationdirect.com/microsites/p2000/help/198.htm
15/20
5/10/2016
CommunicationsModbusFunctionality
TheWXinstructionoperatesinthesamemannerexceptthatthedatafromtheLocaltagswillbewritteninto
theTagsoftheremoteproject.NoModbusmappingisrequired.
Note:ThePCprogrammingsoftwareprojectfortheRemoteCPUmustbeaccessiblebythePCrunningthe
programmingsoftwarefortheLocalproject.
Automatic
Pollversus
Manual
Pollingand
Interlocking
Inmanycaseswhenperformingmultiplecommunicationsrequeststootherdevices,themessageflowmustbe
explicitlycontrolledinladdercodesothatamessageisnotsentwhileanotheroneisinoperation.Thisusually
requireswritinginterlockingcodebetweentheinstructionswhichtypicallyinvolvestheuseoftimersandshift
registers,etc.SometimesthisisnecessarybecauseoftheapplicationbutinothercaseswheretheCPUjust
wantstoreadchangingvaluesfromotherdevicesandthefrequencyofthatupdateisnotcriticalitwouldbe
muchmoreefficienttoskiptheunnecessarycodecomplexityofinterlocking.
ThedesiretomakeiteasiertocommunicatetootherdevicesbroughtabouttheAutomaticPollingfeatureand
theMessageQueueintheCPU.TheAutomaticPollingfeatureallowstheusertochoosetherateatwhich
theydesiretosendmessageswithouthavingtouseaseparatetimerandenablelogic.TheMessageQueue
allowstheusertostagethemessagesfromtheladdercodetogoouttoeachphysicalcommunicationsport
http://www.automationdirect.com/microsites/p2000/help/198.htm
16/20
5/10/2016
CommunicationsModbusFunctionality
withoutrequiringinterlockinglogic.
http://www.automationdirect.com/microsites/p2000/help/198.htm
17/20
5/10/2016
CommunicationsModbusFunctionality
Theimplementationofhowthemessagequeueworksisslightlydifferentbasedonwhethertherequestisa
readrequestorawriterequest.
Writerequestswillfillthequeuemuchfasterthanreadrequests.That'swhyitisadvisabletocarefullychoose
whendoingwriterequestswhethertousetheAutomaticPollfeatureortomanuallysendwriterequestsonly
whenneeded(datatowritehaschanged).Whendesigningasystem,itisimportanttoknowthetotaltimeit
takestosendarequestandgetareplyforeachtargetdevice.ThePolltimeshouldbelongerthanthistime.
Thelongerthepolltimecanbe,withintoleranceoftheapplication,thebettertheoverallnetworkperformance.
Soforefficiencyinprogrammingandforthebestpossibleperformanceforthesystem,conservativepollrates
shouldbeusedwhenutilizingtheAutomaticPollfeature.
ThereisalsoaPolloffsetfieldinthecommunicationsinstructions.Thishelpspreventtheinstructionsfrom
beingqueuedallatthesametime.WhentheCPUprojectstarts,thereisamastertimerthatbegins.Theladder
scanwilllooktoseeiftheinstructionisenabled.Ifitisenabled,itwillbegintheAutomaticPolltimeratthe
specifiedpolloffsetvaluefromthemastertimeclock.
http://www.automationdirect.com/microsites/p2000/help/198.htm
18/20
5/10/2016
CommunicationsModbusFunctionality
Iftheapplicationrequiresmoreexplicit,orderlycontrolofeachmessagesenttothedevices,turnoffthe
AutomaticPollfeature.Usingtheinstruction'sstatusbits,logicallycontroleachmessageasrequired.
Alloftheaboveexplainshowmessagesgetintothequeue.Thereareseveralfactorsinvolvedwithhoweach
queue(1foreachphysicalport)isemptied.
Serialportqueues:TheserialportqueuesemptyslowerthantheEthernetportqueues,notjust
becauseofthehardwarespeeditselfbutbecauseofthenatureofserialcommunications.Eachrequest
sentmustwaitforaresponseoratimeout(whichevercomesfirst).Oncethereplyisreceivedfora
requestoratimeouthasoccurred,thenextiteminthelistcanbesent.Sotheresponsetimeofthe
slavedevicesonthenetworkwilllargelyaffectthespeedatwhichthequeuefillsandempties.
Ethernetportqueues:TheEthernetportqueuecanemptyfasterbecausewhensendingrequeststo
multipledevices,theCPUdoesnothavetowaitonaresponsefromonedevicebeforesendinga
requesttoanotherdeviceduetotheinherentnatureoftheEthernethardware.However,sending
multiplerequeststothesameEthernetdevicedoesnecessitatethattheCPUwaitsforaresponsefrom
thefirstrequestbeforesendinganotherrequesttothatsamedevice.
AnotherdifferenceintheEthernetportqueueversustheSerialportqueuespawnsfromtheTCP'connection'
basedbehaviorofModbusTCP.IfaTCPconnectionislosttoadeviceandtherearestillrequestsinthe
http://www.automationdirect.com/microsites/p2000/help/198.htm
19/20
5/10/2016
CommunicationsModbusFunctionality
queueforthatdevice,thoserequestswillbedroppedfromthequeue.Therearethreewaysthiscanhappen:
1.IfaTCPtimeoutoccurs(serverdevicefailstorespondwithinspecifiedtimeoutvalue),theTCP
connectionislost.
2.Iftheserverdeviceclosestheconnection,thenalloftherequestswillbedropped.
3.And,finally,ifallrungswithcommunicationsinstructionstoadevicearedisabledforfiveseconds,the
CPUwilldroptheTCPconnectionforthatdeviceinordertofreeupvaluableresourcesthatcouldbe
usedelsewhereinthesystem.
Thisisanotherfactorthatshouldbeconsideredwhendesigningthesystem.Ifitisimperativethatnomessage
belostwhencommunicatingtoadevice,eachinstructionshouldbeexplicitlyhandledonebyone
(interlockinglogic).
http://www.automationdirect.com/microsites/p2000/help/198.htm
20/20