modbus - halvorsen.blog · modbus •the nice thing of the modbus standard is the flexibility, but...
TRANSCRIPT
WhatisModbus?• Modbusisaserialcommunicationsprotocoloriginally
publishedbyModicon (nowSchneiderElectric)in1979forusewithitsprogrammablelogiccontrollers(PLCs).
• Simpleandrobust,ithassincebecomeadefactostandardcommunicationprotocol,anditisnowacommonlyavailablemeansofconnectingindustrialelectronicdevices
• ThedevelopmentandupdateofModbusprotocolshasbeenmanagedbytheModbusOrganizationsinceApril2004,whenSchneiderElectrictransferredrightstothatorganization
• Modbusbecamethefirstwidelyacceptedfieldbusstandard.
https://en.wikipedia.org/wiki/Modbus
Modbus• ThenicethingoftheModbusstandardistheflexibility,butatthesametimetheeasyimplementationofit.
• Notonlyintelligentdeviceslikemicrocontrollers,PLCsetc.areabletocommunicatewithModbus,alsomanyintelligentsensorsareequippedwithaModbusinterfacetosendtheirdatatohostsystems.
• WhileModbuswaspreviouslymainlyusedonwiredserialcommunicationlines,therearealsoextensionstothestandardforwirelesscommunicationsandTCP/IPnetworks.
http://www.lammertbies.nl/comm/info/modbus.html
Modbus• Modbusisa“master-slave”system,wherethe“master”
communicateswithoneormultiple“slaves.”• ThemastertypicallyisaPLC(ProgrammableLogicController),
PC,DCS(DistributedControlSystem)orRTU(RemoteTerminalUnit)
• ModbusRTUslavesareoftenfielddevices,allofwhichconnecttothenetworkinamulti- dropconfiguration
• WhenaMODBUSRTUmasterwantsinformationfromadevice,themastersendsamessagethatcontainsthedevice’saddress,dataitwants,andachecksumforerrordetection.Everyotherdeviceonthenetworkseesthemessage,butonlythedevicethatisaddressedresponds.
UsingModbusforProcessControlandAutomation(PDF):http://www.miinet.com/Portals/0/articles/Using_MODBUS_for_Process_Control_and_Automation.pdf
Modbus
Master
Slave
Slave
Slave
RTUPLC
PC
ProcessMeasurements
ThemastertypicallyisaPLC(ProgrammableLogicController),PCorDCS(DistributedControlSystem)
ModbusRTUslavesareoftenfielddevices,allofwhichconnecttothenetworkinamulti- dropconfiguration
Aremoteterminalunit(RTU)isamicroprocessor-controlledelectronicdevicethatinterfacesobjectsinthephysicalworldtoaDCSorSCADASystem
SCADA DSC
RTU
SensorsandActuators
Master/Slave• Modbusprotocolisdefinedasamaster/slaveprotocol,meaningadeviceoperatingasamasterwillpolloneormoredevicesoperatingasaslave.
• Thismeansaslavedevicecannotvolunteerinformation;itmustwaittobeaskedforit.
• Themasterwillwritedatatoaslavedevice’sregisters,andreaddatafromaslavedevice’sregisters.Aregisteraddressorregisterreferenceisalwaysinthecontextoftheslave’sregisters.
Master/Slave
Master SlaveRequest
Response
TheModbusprotocolfollowsamasterandslavearchitecturewhereamastertransmitsarequesttoaslaveandwaitsfortheresponse.
Master/Slave
MasterSlave
Master DataStoredinRegisters
WriteData
ReadData
Modbusprotocolisdefinedasamaster/slaveprotocol,meaningadeviceoperatingasamasterwillpolloneormoredevicesoperatingasaslave.Thismeansaslavedevicecannotvolunteerinformation;itmustwaittobeaskedforit.Themasterwillwritedatatoaslavedevice’sregisters,andreaddatafromaslavedevice’sregisters.Aregisteraddressorregisterreferenceisalwaysinthecontextoftheslave’sregisters.
Polling/Request
Registers
ModbusRegisterTypes1. Coil(DiscreteOutput)– Coilsare1-bitregisters,usedtocontroldiscreteoutputs,ReadorWrite
2. DiscreteInput– 1-bitregisters
3. InputRegister(ReadOnly)4. HoldingRegister(Read/Write)
16-bit data registers
RegisterAddresses
0x=Coil,AddressRange:00001-099991x=DiscreteInput,AddressRange: 10001-199993x=InputRegister,AddressRange:30001-399994x=HoldingRegister,AddressRange: 40001-49999Whenusingtheextendedreferencing,allnumber referencesmustbeexactlysixdigits.Thisavoidsconfusionbetweencoilsandotherentities.Forexample,toknowthedifferencebetweenholdingregister#40001andcoil#40001,ifcoil#40001isthetarget,itmustappearas#040001.
AccessLevels
• InSCADAsystems,itiscommonforembeddeddevicestohavecertainvaluesdefinedasinputs,suchasgainsorproportionalintegralderivative(PID)settings,whileothervaluesareoutputs,likethecurrenttemperatureorvalveposition.Tomeetthisneed,Modbusdatavaluesaredividedintofourranges
• Inmanycases,sensorsandotherdevicesgeneratedataintypesotherthansimplyBooleansandunsignedintegers.Itiscommonforslavedevicestoconverttheselargerdatatypesintoregisters.Forexample,apressuresensormaysplita32-bitfloatingpointvalueacrosstwo16-bitregisters.
IntroductiontoModbus(NationalInstruments):http://www.ni.com/white-paper/7675/en/
MemoryType DataType MasterAccess SlaveAccess
Coils Bit(Boolean) Read/Write Read/Write
DiscreteInput Bit(Boolean) Read-only Read/Write
InputRegister UnsignedWord Read-only Read/Write
HoldingRegister UnsignedWord Read/Write Read/Write
RegisterReferencing40001:7• Thisisacommonlyusednotationforreferencingindividualbitsinaregister.
• Thisparticularexamplereferencesregister40001(whichisaHoldingRegister),bit7.
• Bitsaregenerallynumberedstartingatbit0,whichistheleastsignificantorrightmostbitinthefieldof16bitsfoundinaModbusregister.
ModbusProtocols• ModbusASCII• ModbusRTU(RemoteTerminalUnit)–ModbusRTUusesRS-485orRS-232
• ModbusTCP/IP–ModbusTCPusesEthernet
ModbusASCIIandModbusRTUaresimpleserialprotocolsthatuseRS-232orRS-485totransmitdatapackets.ModbusTCP/IPfollowstheOSINetworkModelandcanbeusedinanordinaryEthernetnetwork
ModbusCommunication
RS-232 RS-485 TCP/IP
Master Slave Master Slave Master Slave
Slave
Slave
...
128 Master Slave
SlaveMaster
... ...
Multi-drop network
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
ModbusRTUvs.ModbusTCP/IP
ThemostbasicdifferencebetweenModbusRTUandModbusTCP/IPisthatModbusTCP/IPrunsonanEthernetphysicallayerandModbusRTUisaserialprotocol
ModbusinLabVIEW3waystouseModbusinLabVIEW:• Useahigh-levelOPCServer• UseModbusI/OServer• UsetheLabVIEWModbusAPI
IntroductiontoModbus(NationalInstruments):http://www.ni.com/white-paper/7675/en/
“LabVIEWReal-TimeModule”or“LabVIEWDSCModule”required
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/runtheModbusSlaveAppbeforeyoustarttheModbusMasterApps
WriteDatatoSlave
ReadDatafromSlave
ModbusSlave
ThispartisjustforreadingtheinternalCoilData.Itcanberemoved.ItisjusttoseewhennewdatafromtheMastershasbeenreceived
LabVIEWModbusSimulator
TheLabVIEWModbusSimulatorisintegratedwith“LabVIEWReal-TimeModule”or“LabVIEWDSCModule”
Itcanbeusedfortestpurpose,etc.
TheLabVIEWModbusSimulatorisaModbusSlave(Server)
References• ModbusOrganization:http://www.modbus.org• Modbus(Wikipedia):https://en.wikipedia.org/wiki/Modbus• IntroductiontoModbus(NationalInstruments):
http://www.ni.com/white-paper/7675/en/• ConnectLabVIEWtoAnyPLCWithModbus(NationalInstruments):
http://www.ni.com/tutorial/13911/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/• UsingModbusforProcessControlandAutomation(PDF):
http://www.miinet.com/Portals/0/articles/Using_MODBUS_for_Process_Control_and_Automation.pdf
Hans-PetterHalvorsen
UniversityofSoutheastNorwaywww.usn.no
E-mail:[email protected]:https://www.halvorsen.blog