Modbus Overview - hit.Nohome.hit.no/~hansha/documents/industrial_it/resources/resources... ·...

Preview:

Citation preview

ModbusOverview

Hans-PetterHalvorsen,M.Sc.

WhatisModbus?• Modbusisaserialcommunicationsprotocoloriginally

publishedbyModicon (nowSchneiderElectric)in1979forusewithitsprogrammablelogiccontrollers(PLCs).

• Simpleandrobust,ithassincebecomeadefactostandardcommunicationprotocol,anditisnowacommonlyavailablemeansofconnectingindustrialelectronicdevices

• ThedevelopmentandupdateofModbusprotocolshasbeenmanagedbytheModbusOrganizationsinceApril2004,whenSchneiderElectrictransferredrightstothatorganization

• Modbusbecamethefirstwidelyacceptedfieldbusstandard.

https://en.wikipedia.org/wiki/Modbus

Master/Slave• Modbusprotocolisdefinedasamaster/slaveprotocol,meaningadeviceoperatingasamasterwillpolloneormoredevicesoperatingasaslave.

• Thismeansaslavedevicecannotvolunteerinformation;itmustwaittobeaskedforit.

• Themasterwillwritedatatoaslavedevice’sregisters,andreaddatafromaslavedevice’sregisters.Aregisteraddressorregisterreferenceisalwaysinthecontextoftheslave’sregisters.

Master/Slave

MasterSlave

Master DataStoredinRegisters

WriteData

ReadData

Modbusprotocolisdefinedasamaster/slaveprotocol,meaningadeviceoperatingasamasterwillpolloneormoredevicesoperatingasaslave.Thismeansaslavedevicecannotvolunteerinformation;itmustwaittobeaskedforit.Themasterwillwritedatatoaslavedevice’sregisters,andreaddatafromaslavedevice’sregisters.Aregisteraddressorregisterreferenceisalwaysinthecontextoftheslave’sregisters.

Polling/Request

Registers

ModbusRegisterTypes• Coil(DiscreteOutput)– Coilsare1-bitregisters,usedtocontroldiscreteoutputs,ReadorWrite

• DiscreteInput– 1-bitregisters

• InputRegister• HoldingRegister

16-bit data registers

RegisterAddresses

0x=Coil,AddressRange:00001-099991x=DiscreteInput,AddressRange: 10001-199993x=InputRegister,AddressRange:30001-399994x=HoldingRegister,AddressRange: 40001-49999Whenusing theextendedreferencing,allnumber referencesmustbeexactlysixdigits.Thisavoidsconfusionbetweencoilsandotherentities.Forexample,toknowthedifferencebetweenholding register#40001andcoil#40001,ifcoil#40001isthetarget,itmustappearas#040001.

RegisterReferencing40001:7• Thisisacommonlyusednotationforreferencingindividualbitsinaregister.

• Thisparticularexamplereferencesregister40001(whichisaHoldingRegister),bit7.

• Bitsaregenerallynumberedstartingatbit0,whichistheleastsignificantorrightmostbitinthefieldof16bitsfoundinaModbusregister.

ModbusProtocols• ModbusASCII• ModbusRTU(RemoteTerminalUnit)– ModbusRTUusesRS-485orRS-232

• ModbusTCP/IP– ModbusTCPusesEthernet

ModbusASCIIandModbusRTUaresimpleserialprotocolsthatuseRS-232orRS-485totransmitdatapackets.ModbusTCP/IPfollowstheOSINetworkModelandcanbeusedinanordinaryEthernetnetwork

ModbusASCII• ASCIIcharactersforprotocolcommunication

ModbusRTU• Binaryrepresentationofthedataforprotocolcommunication.

• ModbusRTUusesRS-485orRS-232• ModbusRTUrequiresthatyouknowordefinebaudrate,characterformat(8bitsnoparity,etc.),andslaveID(akaslaveaddress,unitnumber,unitID).Amismatchinanyofthesewillresultinnocommunication.

ModbusTCP/IP• ModbusTCP/IPfollowstheOSINetworkModelandcanbeusedinanordinaryEthernetnetwork

• ModbusTCPrequiresthatyouknowordefineIPaddressesonthenetwork

• ModbusTCP/IPusesPort502• InModbusTCP/IPweusethetermServer/ClientinsteadofSlave/Master– Slave->Server– Master->Client

ModbusinLabvIEW

Hans-PetterHalvorsen,M.Sc.

ModbusinLabVIEW3waystouseModbusinLabVIEW:• Useahigh-levelOPCServer• UseModbusI/OServer• UsetheLabVIEWModbusAPI

Introduction toModbus (NationalInstruments):http://www.ni.com/white-paper/7675/en/

“LabVIEWReal-TimeModule”or“LabVIEWDSCModule” required

LabVIEWModbusAPI

LabVIEWExample

Master(Client) Slave

(Server)

Master(Client) DataStoredinRegisters

WriteData

ReadData

Polling/Request

Registers

LabVIEWApp#1LabVIEWApp#2

LabVIEWApp#3

InthisExampleweCreate3differentLabVIEWApplications

LabVIEWExample

LabVIEWApp#1(Slave)

LabVIEWApp#2(Master)

LabVIEWApp#3(Master)

Note!Youneedtostart/runtheModbus SlaveAppbeforeyoustarttheModbusMasterApps

WriteDatatoSlave

ReadDatafromSlave

ModbusSlave

ModbusMaster(Write)

ModbusMaster(Read)

References• ModbusOrganization:http://www.modbus.org• Modbus(Wikipedia):https://en.wikipedia.org/wiki/Modbus• IntroductiontoModbus(NationalInstruments):

http://www.ni.com/white-paper/7675/en/• Modbus101- IntroductiontoModbus:

http://www.csimn.com/CSI_pages/Modbus101.html• ModbusTCP/IP:

http://www.rtaautomation.com/technologies/modbus-tcpip/• ModbusRTU:

http://www.rtaautomation.com/technologies/modbus-rtu/

Hans-PetterHalvorsen,M.Sc.

UniversityCollegeofSoutheastNorwaywww.usn.no

E-mail:hans.p.halvorsen@hit.noBlog:http://home.hit.no/~hansha/

Recommended