Sie sind auf Seite 1von 20

5/10/2016

CommunicationsModbusFunctionality

CommunicationsModbusFunctionality

Topic:P198

5/10/2016 CommunicationsModbusFunctionality CommunicationsModbusFunctionality Topic:P198
5/10/2016 CommunicationsModbusFunctionality CommunicationsModbusFunctionality Topic:P198

Master/Client

Function

Codeand

DataType

Support

ThefollowingtableliststheModbusdatatype,thefunctioncodeandtheCPUsourcedatatypethatis

supportedwhentheCPUistheClientorMasteronaModbusTCPorserialconnection.

ModbusClient/MasterSupport(UsingMRXandMWXInstructions)

   

Modbus

   

Function

Code

Function

Name

984

Addressing

(Zero

Based)

Modbus

984

Addressing

ProductivitySuite

TagTypes

(Datadesignation

orsource)

       

DiscreteOutput

(DO)

01 ReadCoil

Status

000000­

000001­

Boolean(C)

065535

065536

   
     

BooleanSystem

(SBRW)

       

DiscreteInput(DI)

02 ReadCoil

Status

100000­

100001­

Boolean(C)

165535

165536

BooleanSystem

   

(SBRW)

       

Integer8bit

Unsigned(U8)

Integer16bit(S16)

Integer16bit

Unsigned(U16)

Read

03 Holding

Integer16bitBCD

400000­

400001­

(B16)

465535

465536

Integer32bit(S32)

 

Registers

     
 

Integer32bitBCD

(B32)

Integer32bitFloat

(F32)

Integer16bit

System(SWRW)

       

Integer8bit

Unsigned(U8)

Integer16bit(S16)

Integer16bit

Unsigned(U16)

Read

04 Input

Integer16bitBCD

300000­

300001

(B16)

365535

­365536

Integer32bit(S32)

 

Registers

     
 

Integer32bitBCD

(B32)

Integer32bitFloat

(F32)

Integer16bit

System(SWRW)

       

DiscreteInput(DI)

DiscreteOutput

(DO)

Write

000000­

000001­

Boolean(C)

05 Single

065535

065536

 
 

Coil

BooleanSystem

   

(SBRW)

BooleanSystem

ReadOnly(SBR)

       

Integer8bit

Unsigned(U8)

Integer16bit(S16)

Integer16bit

Unsigned(U16)

Integer16bitBCD

(B16)

Write

06 Single

Register

Integer32bit(S32)

400000­

400001­

Integer32bitBCD

(B32)

465535

465536

   

Integer32bitFloat

(F32)

Integer16bit

System(SWRW)

5/10/2016

CommunicationsModbusFunctionality

       

Integer16bit

SystemReadOnly

(SWR)

       

DiscreteInput(DI)

DiscreteOutput

(DO)

Write

000000­

000001­

Boolean(C)

15

Multiple

065535

065536

 
 

Coils

BooleanSystem

   

(SBRW)

BooleanSystem

ReadOnly(SBR)

5/10/2016

CommunicationsModbusFunctionality

ModbusClient/MasterSupport(UsingMRXandMWXInstructions)

 

Continued

 
       

Productivity

Function

Code

Function

Name

Modbus984

Addressing

(Zero

Based)

Modbus984

Addressing

SuiteTagTypes

(Data

designationor

source)

       

Integer8bit

Unsigned(U8)

Integer16bit(S16)

Integer16bit

Unsigned(U16)

Integer16bitBCD

(B16)

Write

400000­

465535

400001­

465536

Integer32bit(S32)

16

Multiple

Integer32bitBCD

(B32)

Registers

   

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

     

DiscreteOutput(DO)

01

ReadCoil

000001­

Boolean(C)

Status

065536

 

BooleanSystem(SBRW)

 

ReadCoil

 

DiscreteInput(DI)

02

100001­

 

Status

165536

BooleanSystemReadOnly

 

(SBR)

     

Integer8bitUnsigned(U8)

Integer16bit(S16)

Integer16bitUnsigned

(U16)

Read

Integer16bitBCD(B16)

03

Holding

400001­

Integer32bit(S32)

465536

 

Registers

Integer32bitBCD(B32)

 

Integer32bitFloat(F32)

Integer16bitSystem

(SWRW)

String

     

AnalogInput,Integer32bit

(AIS32)

04

ReadInput

300001

AnalogInput,Float32bit

Registers

­365536

(AIF32)

Integer16bitSystemRead

Only(SWR)

     

DiscreteOutput(DO)

05

WriteSingle

000001­

Boolean(C)

Coil

065536

 
 

BooleanSystem(SBRW)

     

Integer8bitUnsigned(U8)

Integer16bit(S16)

Integer16bitUnsigned

(U16)

Integer16bitBCD(B16)

WriteSingle

400001­

Integer32bit(S32)

06

Integer32bitBCD(B32)

Register

465536

 

Integer32bitFloat(F32)

 

Integer16bitSystem

(SWRW)

Integer16bitSystemRead

Only(SWR)

String

 

Write

000001­

DiscreteOutput(DO)

5/10/2016

CommunicationsModbusFunctionality

15

Multiple

Coils

065536

Boolean(C)

BooleanSystem(SBRW)

5/10/2016

CommunicationsModbusFunctionality

 

ModbusServer/SlaveSupport(Continued)

Function

Function

Modbus984

ProductivitySuiteTag

Code

Name

Addressing

Types

     

Integer8bitUnsigned(U8)

Integer16bit(S16)

Integer16bitUnsigned

(U16)

Integer16bitBCD(B16)

Write

400001­

Integer32bit(S32)

16

Multiple

 

465536

Integer32bitBCD(B32)

 

Registers

Integer32bitFloat(F32)

Integer16bitSystem

(SWRW)

Integer16bitSystemRead

Only(SWR)

String

Assigning

TherearemanydifferentdatatypesintheCPU.Becauseofthis,theModbusaddressesneedtobemapped

Modbus

tothevarioustagdatatypesintheCPU.

Addresses

toTags

TherearetwowaystomapModbusaddressestoTagsintheProgrammingsoftware:

Modbusmappingin TagDatabase window. mappinginTagDatabasewindow.

Modbusmappingwhencreating Tags . mappingwhencreatingTags.

1.ModbusmappinginTagDatabasewindow:

ThereareonlytwodatasizesintheModbusprotocol:bitsandwords.IntheCPU,therearemultiple

sizetypes,soitissometimesnecessarytomapmultipleModbusaddressestoasingleTagentity.

TherearealsoarraydatastructuresintheCPU.WhenModbusaddressesaremappedtoarrays,they

willbemappedasacontiguousblockofaddresses.Thisis,infact,themostefficientmethodtohandle

Modbuscommunications.

IntheTagDatabasewindow,therearetwocolumnsnamedModStartandModEnd.Tomapa

ModbusaddresstoatagintheTagDatabasewindow,simplydouble­clickintheModStartfieldfor

theTag.

window,simplydouble­clickinthe ModStart fieldfor the Tag .

Whenyoudothis,youwillseetwovaluesappearinthefield.TheleftmostvalueistheModbusdata type.Thisisfixedbaseduponthetagdatatype.ThechartbelowindicatesthefourdifferentModbus

datatypesinthe984addressingscheme.

5/10/2016

CommunicationsModbusFunctionality

5/10/2016 CommunicationsModbusFunctionality Address Identifier 0xxxxx 1xxxxx 3xxxxx 4xxxxx

Address

Identifier

0xxxxx

1xxxxx

3xxxxx

4xxxxx

Address Identifier 0xxxxx 1xxxxx 3xxxxx 4xxxxx Modbus984AddressType Coil(Read/Writebit) Input(ReadOnlybit)

Modbus984AddressType

Coil(Read/Writebit)

Input(ReadOnlybit)

InputRegister(ReadOnly16bitword)

HoldingRegister(Read/Write16bit

word)

TherightmostvaluethatyouseeintheModStartfieldistheaddressoffset(rangeisfrom1­65535).

Youcanacceptthevaluethatispre­filledforyouorthevaluecanbechanged.Thesoftware

automaticallypre­fillstheaddressoffsetwiththenextavailableaddress.

2. ModbusmappingwhencreatingTags: Modbus

2.ModbusmappingwhencreatingTags:

ModbusaddressescanbeassignedtoTagsastheyarecreatedintheTagDatabase.

5/10/2016

CommunicationsModbusFunctionality

5/10/2016 CommunicationsModbusFunctionality Typeinthe Modbus offsetvaluewhenenteringthe TagName and DataType

TypeintheModbusoffsetvaluewhenenteringtheTagNameandDataType.Iftheaddressisalready

assigned,awarningmessagewillappear.

.Iftheaddressisalready assigned,awarningmessagewillappear. Modbus The Modbus

Modbus

TheModbusprotocoldoesnothaveaspecificmethodoutlinedfordatatypesoutsideofbitsand16­bitwords.

Options

Mostsystemsnowhave32­bitdatatypes.Inordertotransport32­bitdatatypesacrossModbus,theymustbe

placedintotwoModbus16­bitregisters.Unfortunately,somedevicesdonotsupportthisandthereare

sometimesincompatibilitiesintheorderofthe16­bithighwordandlowwordhandlingbetweenthedevices.

5/10/2016

CommunicationsModbusFunctionality

Inordertohelpalleviatethissituation,therearesomeoptionsforhandlingthisintheprogrammingsoftware.

TofindtheModbusAddressoptions,gotoFileandclickonProjectPropertiesandthenclickontheModbus

ServerSettingstab.

andthenclickonthe Modbus ServerSettings tab. a. Noexceptionresponsefornon­existingModbusaddressrequests:

a.Noexceptionresponsefornon­existingModbusaddressrequests:BecausetheModbus addressescanbemanuallyassignedtotags,itispossiblethatgapscanoccurintheModbusaddress

mapping.Forexample:Tag1hasModbusaddress400001assignedtoitandTag2hasModbus

address400003assignedtoit.

assignedtoitand Tag2 has Modbus address400003 assignedtoit.

5/10/2016

CommunicationsModbusFunctionality

MostModbusMaster/ClientdeviceswillattempttooptimizetheirdatarequeststoaModbus Slave/Serverdevicebyrequestingblocksofdatainsteadofindividualregisters.Inthecaseabove,

mostModbusmasterswouldsendonereadrequeststartingat400001andasizeofthreeinsteadof

sendingtworeadrequestsstartingat400001withsizeoneand400003withsizeoneasshownbelow.

400001 withsize one and 400003 withsize one asshownbelow. Intheexampleshownaboveonleft,a ModbusSlave/Server

Intheexampleshownaboveonleft,aModbusSlave/Serverdeviceshouldgiveanexception

responsesincethereisnoModbusAddressof400002inthedevice.Thismethodcancausesalotof

inefficiencies.ByselectingtheNoexceptionresponsefornon­existingModbusaddressrequests option,theCPUwillnotgiveanexceptionresponsetotherequest.NotethatifModbusaddress

400002byitselfwererequesteditwouldgiveanexceptionresponse.

5/10/2016

CommunicationsModbusFunctionality

b.Wordswapoption(S­32,AIS­32,AOS­32,F­32,FI­32,FO­32):

Wordswapallowsthewordorderof32­bittagstobechangedwhensendingthevaluesacross

Modbus.Thedefaultselectionison,whichreturnsthedatalowwordfirst.

.Thedefaultselectionison,whichreturnsthedatalowwordfirst. c. Mapvaluetoasingle16bitModbusregister:

c.Mapvaluetoasingle16bitModbusregister:

Thisoptionallowsforcompatibilitywithdevicesthatdonotsupport32­bitModbusfunctionality.This

optioncanbeselectedindividuallyfortheAnalogInputandOutputSigned32datatypesandthe

InternalSigned32datatypes,includingthearrayformofthesedatatypes.Thisfunctionisonlyuseful

whenthevaluecontainedina32­bittagdoesnotexceedasigned15­bitvalue(32,765).

Tag1(Integer,32­Bit)=22136(hex=0x00005678)

With"MapValuetoasingle16­Bitregister"turnedOFF=

Tag1Modbusaddress=400001,400002

ModbusreplyforTag1(WordSwapON)=01030456780000

With"MapValuetoasingle16­Bitregister"turnedON=

Tag1Modbusaddress=400001

ModbusreplyforTag1=0103025678

d.Mapvaluetotwoconsecutive16­bitModbusregisters:Allowsfor32­bitdatatypestobemappedto

twoconsecutive16­bitregisters.Thisoptionisselectedasdefault.

AlloftheoptionsintheModbusAddresstaboftheProjectPropertiesonlyapplytotheModbus

Slave/Serverfunctionality.SimilaroptionsareavailablefortheModbusMaster/Clientfunctionsas

wellandareavailableintheMRXandMWXModbusinstructions.

5/10/2016

CommunicationsModbusFunctionality

Modbus

ToreadorsetdatainotherModbusSlave/Serverdevices,therearetwoinstructionsavailableinthe

Instructions

programmingsoftware,ModbusReadandModbusWrite.

TheModbusRead(MRX)instructionisusedtoreaddatafromotherModbusdevicesintoTagsofthe

CPU.

5/10/2016

CommunicationsModbusFunctionality

5/10/2016 CommunicationsModbusFunctionality The MRX instructioncanbeusedfor ModbusTCP or ModbusRTU

TheMRXinstructioncanbeusedforModbusTCPorModbusRTU.Thereareseveralstatusbitsthat

canbeusedtodeterminewhetherthereadmessagewassuccessfulandifitwasnot,thereasonwhy.

ThereisanAutomaticPollingfeatureintheinstructiontomakeiteasiertoreadadeviceonapre­

determinedpollrate.Thereisalsoapolloffsetfieldthatcanbeusedwhensimultaneousinstructions

areenabledwiththeAutomaticPollingfeaturetohelpstaggertheflowofmessagesbeingsenttothe

network.

5/10/2016

CommunicationsModbusFunctionality

TheModbusWrite(MWX)instructionisverysimilarinlayoutandconfigurationtotheMRXinstruction.

ItisusedtowritevaluestoaModbusdevicefromthetagsintheCPU.

Itisusedtowritevaluestoa Modbus devicefromthetagsinthe CPU . The MWX operatesverysimilarlytothe MRX

TheMWXoperatesverysimilarlytotheMRXinstruction.Therearealsomanystatusbitstoindicatethe

successorreasonoffailurewhensendingamessage.

TheAutomaticPollingoptionisalsoavailabletotheMWXinstruction,althoughgreatercareshouldbe

takenwhenusingthisfeatureinthisinstruction.ThisisexplainedinbetterdetailintheMessage

Queuesection.

5/10/2016

CommunicationsModbusFunctionality

Network

TheNetworkRead(RX)andNetworkWrite(WX)instructionsareusedtocommunicatetootherCPUs.They

Instructions

areverysimilarinoperationtotheMRXandMWXinstructionsbuttheytargetTagNamesinsteadofModbus

addressesintheotherCPU.ThereisalsoasignificantperformancegaininusingtheRXandWXinstructions

whencommunicatingtootherCPUsasopposedtousingtheMRXandMWXinstructions.

5/10/2016

CommunicationsModbusFunctionality

5/10/2016 CommunicationsModbusFunctionality Thesamestatusbitsareavailableinthe RX instructionasinthe MRX

ThesamestatusbitsareavailableintheRXinstructionasintheMRXinstructionandoperateinthesame

manner.ThegreatestdifferenceintheRXversustheMRXisthatwiththeRX,theTagNameinthetargetCPU

canbereferenceddirectlyanddoesnotneedacorrespondingModbusaddress.Thewaythisis

accomplishedisbymappinglocalandremotetagnamestogetherwithinthelocalCPU'sRXinstruction.Once

theinstructionissetuptoreadaremoteproject,theTagsofRemoteProjectorArrayTagsofRemote

Projectdropdownlistswillbeaccessible.MaptheTagoftheRemoteprojecttoaTagintheLocalprojectto

readthisdata.

5/10/2016

CommunicationsModbusFunctionality

5/10/2016 CommunicationsModbusFunctionality The WX instructionoperatesinthesamemannerexceptthatthedatafromthe Local

TheWXinstructionoperatesinthesamemannerexceptthatthedatafromtheLocaltagswillbewritteninto

theTagsoftheremoteproject.NoModbusmappingisrequired.

the Tags oftheremoteproject.No Modbus mappingisrequired. Note: The PC programmingsoftwareprojectforthe RemoteCPU

Note:ThePCprogrammingsoftwareprojectfortheRemoteCPUmustbeaccessiblebythePCrunningthe

programmingsoftwarefortheLocalproject.

Automatic

Inmanycaseswhenperformingmultiplecommunicationsrequeststootherdevices,themessageflowmustbe

Pollversus

explicitlycontrolledinladdercodesothatamessageisnotsentwhileanotheroneisinoperation.Thisusually

Manual

requireswritinginterlockingcodebetweentheinstructionswhichtypicallyinvolvestheuseoftimersandshift

Pollingand

registers,etc.SometimesthisisnecessarybecauseoftheapplicationbutinothercaseswheretheCPUjust

Interlocking

wantstoreadchangingvaluesfromotherdevicesandthefrequencyofthatupdateisnotcriticalitwouldbe

muchmoreefficienttoskiptheunnecessarycodecomplexityofinterlocking.

ThedesiretomakeiteasiertocommunicatetootherdevicesbroughtabouttheAutomaticPollingfeatureand

theMessageQueueintheCPU.TheAutomaticPollingfeatureallowstheusertochoosetherateatwhich

theydesiretosendmessageswithouthavingtouseaseparatetimerandenablelogic.TheMessageQueue

allowstheusertostagethemessagesfromtheladdercodetogoouttoeachphysicalcommunicationsport

5/10/2016

CommunicationsModbusFunctionality

withoutrequiringinterlockinglogic.

5/10/2016

CommunicationsModbusFunctionality

Theimplementationofhowthemessagequeueworksisslightlydifferentbasedonwhethertherequestisa

readrequestorawriterequest.

readrequestorawriterequest.
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.

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

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).

(interlockinglogic).