user manual 1
SoMachine HVAC - Application
Contents1. Introduction 3
1.1 Purpose of this document 3
2. Modbus RTU master run-time 5
2.1 Features 5
2.2 Modbus RTU master enable status 6
3. Configurationwizard 7
3.1 How to enable Modbus master 7
3.2 Seriallineconfiguration 7
3.3 Howtoaddconfigurationelements 8
3.4 GenericModbus 83.4.1 Modbusmessages 9
3.5 Modbus custom 113.5.1 LaunchingModbusCustomEditor 11
3.5.2 WorkingwithModbusCustomEditor 11
3.6 Buildingconfiguration 113.6.1 Configurationerrors 12
3.6.2 Generated project elements 12
3.6.3 Executableelements 13
4. Manualcoding 15
4.1 WorkingwithModbusPLCtask 15
4.2 Examples 154.2.1 Howtosendamessagejustonce 15
4.2.2 Howtoputdiagnosticscountersinamenu 17
4.2.3 HowtodisabletheModbusRTUmaster 18
4.2.4 Howtodisableaslavenode 18
2 user manual
SoMachine HVAC - Application
user manual 3
SoMachine HVAC - Application
1. INTRODUCTION
AmongtheModiconM171programmablecontrollersfamily,ModiconM171OptfeaturesaModbusRTUmasterrun-timetosupportthedevelopmentofPLCapplicationrelyingonremote devices (Modbus slave nodes).WithSoMachineHVAC-Application,youcanaccomplishthetaskeitherbywritingcodethatmakesdirectuseofavailabletargetblocksorbyexploitingapowerfulconfigurationwizardwithanice-to-useGraphicalUserInterface(GUI).Mixingbothapproachesisalsosupported,inordertoletthewizardtakecareofalltasksitcanaccomplishandstillhavetheflexibilitytoaddmorecomplexconfigurationelementsbyhand.
1.1 PURPOSE OF THIS DOCUMENTThisdocumentisauserguideforworkingwithModiconM171Optuniquefeatures.InChapter2youmayfindageneraldescriptiononhowtheModbusRTUmasterrun-timeworks,includingitscharacteristicsandprogrammingmodel.Chapter3focusesontheconfigurationwizardincludedinSoMachineHVAC-Application,whileChapter4supportstheuserthatiswillingtomanuallycode(partof)theModbusRTUmasterconfiguration.
4 user manual
SoMachine HVAC - Application
user manual 5
SoMachine HVAC - Application
2. MODBUS RTU MASTER RUN-TIME
This chapter lists the main features of Modicon M171’s Modbus RTU master and introduces itsprogrammingmodel.
2.1 FEATURESThe list of the main features of Modicon M171’s Modbus RTU master follows. - Support of the followingModbusmessages, including broadcast for supportedwritefunctions(thatis,Function05,06,15,and16):
- ReadCoils–Function01(0x01):readsoneormore1-bitread-writeobjects; - ReadDiscreteInputs–Function02(0x02):readsoneormore1-bit read-onlyobjects;
- ReadHoldingRegisters–Function03(0x03):readsoneormore16-bitread-writeobjects;
- ReadInputRegisters–Function04(0x04):readsoneormore16-bitread-onlyobjects;
- WriteSingleCoil–Function05(0x05):writesasingle1-bitread-writeobject; - WriteSingleRegister–Function06(0x06):writesasingle16-bitread-writeob-ject;
- WriteMultipleCoils–Function15 (0x0F):writesoneormore1-bit read-writeobjects;
- WriteMultipleRegisters–Function16(0x10):writesoneormore16-bitread-write objects.
- Upto8Modbus16-bitobjectsor16Modbus1-bitobjectspermessage;readingofnon-contiguousModbusobjectswithasinglemessageallowed.
- TheamountofmemoryuseddependsonthenumberofconfiguredslavenodesandModbusmessages.Thus,anapplicationwithasingleModbusRTUslavenodeandfewmessagesaddressedtoitstillhavemuchdatamemoryavailableforthePLC.
- DedicatedPLCtask(Modbustask):operationsonthebusdonotaffectthePLCTimedtaskandhavelimitedimpactonlower-prioritytasks,sincetheyarecarriedonasyn-chronously.
- Diagnosticscountersavailableatthesinglemessagelevel,inadditiontotheslavenodelevel(allmessagesaddressedtothesameslave),andtothegloballevel(allmessages).
- ModbusRTUmastercanbedynamicallydisabledandenabled,toallowSoMachineHVAC-Application’sdebuggertoattachtothetargetdevice(seeparagraph2.2,fordetails).
- SameBIOSparametersforbothModbusmasterandslave(forprogramming):CF30,CF31,CF32.
- NofullapplicationcompatibilitybetweenModiconM171Opt.ModBusSlaveOnlyandModiconM171Opt:additionalworkistypicallyrequiredtoportanapplicationwrittenfor one device to the other one.
6 user manual
SoMachine HVAC - Application
2.2 MODBUS RTU MASTER ENABLE STATUSSincethecommunicationportusedbytheModbusRTUmasteristhesameusedbySoMa-chineHVACtoconnecttoaModiconM171programmablecontroller,youcannotconnecttothedeviceiftheModbusRTUmasterisrunning.Tosolvethisissue,thefollowingmechanismshavebeenputinplace: - delayedstart:afterthecontrollerispoweredon,itwaitsforapproximately5secondsforaconnectionwiththedevelopmentenvironmenttobeestablished,beforeloadingthePLCapplicationandenablingtheModbusRTUmaster;iftheconnectionisestab-lished,thePLCapplicationisloadedbuttheModbusRTUmasterisnotenabled;
- run-timedisable:ModbusRTUmastercanbedynamicallydisabledandenabledagainbythePLCapplication(throughacalltothetargetFUNCTIONsysMbMRTU_Enable),toallowSoMachineHVAC-Application’sdebuggerstoattachtothetargetdeviceevenifthePLCapplicationhasalreadybeenstarted.
ThefollowingdiagramsummarizesthemanagementofModbusRTUmasterenablestatus.
user manual 7
SoMachine HVAC - Application
3. CONFIGURATION WIZARD
SoMachineHVAC-Applicationincludesaconfigurationwizardtoquicklydevelopandde-ployModbusRTUmaster-enabledPLCapplicationforModiconM171(ModiconM171Optonly).Thischapterisawalk-throughguideforthisfeature.
3.1 HOW TO ENABLE MODBUS MASTERToopentheModbusmasterconfigurationwizard,firstselectMaster Modbus RTU element in the Resources tabofSoMachineHVAC-Application’sProject window.
Select Modbus Mastertostarttheconfigurationprocess.
3.2 SERIAL LINE CONFIGURATIONThewizardfirstdisplaysserial lineconfigurationoptions:select thedesiredserial linebaudrateandparity.
8 usermanual
SoMachine HVAC - Application
Pleasenote that serial lineconfiguration impactsBIOSParametersconfiguration,as itupdatesthedefaultvalueofBIOSparametersCF31andCF32.
3.3 HOW TO ADD CONFIGURATION ELEMENTSAfterright-clickingontheMaster Modbus RTUelement,SoMachineHVAC-Applicationdisplaysapop-upmenu:selectAddtoopenthecatalogofthedevicesyoucanattachtoModiconM171OptasModbusRTUslavenodes.
Ingeneral,anydeviceiseitheraGenericModbusRTUnodeoraCustomModbusRTUnode.
3.4 GENERIC MODBUSTheGenericModbusobject is agenericModbus slave that canbe insertedunder theRS485portoftheModiconM171Opt,whenModbusmasterisenabled.YoucanusetheGenericModbuswhenyouwanttomanuallyconfigureandhavefullcon-troloverthesingleModbusmessagestosendtotheslave.Anothertypicalusage is for third-partydevicesthatyouplantouse justonce inyourprojects,andyoudonotwanttoputinthecatalogforfuturereuse.
usermanual 9
SoMachine HVAC - Application
InthemainpageoftheGenericModbusyoumayfillinthefollowing: - Name:theslavenodename; - Modbus address:theslaveModbusaddress,intherange0..247;if0issetasitsad-dress,theslavenodeactsasavirtualslavetogathertogetherallbroadcastmessages(thatis,allmessagesconfiguredforsuchaslaveareintendedtobebroadcastmes-sages;thereisnophysicalnodeonthebuswithModbusaddress0);
- Turnaround:onlyincaseofavirtualslavewithaddress0,itisusedastheturnaroundtimeforconfiguredbroadcastmessages(turnaroundtimeisthetimetheModbusmas-terhastowait,afterabroadcastmessagehasbeensentoutonthebus,beforesendingthenextmessage).
3.4.1 MODBUS MESSAGES
TheGenericModbusobjectalonewilldonothing;youhavetoaddunderitoneormoreModbusmessages,thatarespecificModbusfunctionrequeststhatwillbesentonthebus.Thefollowingmessagesaresupported: - ReadCoils–Function01(0x01):readsoneormore1-bitread-writeobjects; - ReadDiscreteInputs–Function02(0x02):readsoneormore1-bitread-onlyobjects; - ReadHoldingRegisters–Function03(0x03):readsoneormore16-bitread-writeob-jects;
- ReadInputRegisters–Function04(0x04):readsoneormore16-bitread-onlyobjects; - WriteSingleCoil–Function05(0x05):writesasingle1-bitread-writeobject; - WriteSingleRegister–Function06(0x06):writesasingle16-bitread-writeobject; - WriteMultipleCoils–Function15(0x0F):writesoneormore1-bitread-writeobjects; - WriteMultipleRegisters–Function16(0x10):writesoneormore16-bit read-writeobjects.
Messageswillbeprocessedintheordertheyareinsertedinthetree.
10 user manual
SoMachine HVAC - Application
3.4.1.1 GENERAL TAB
Foreachmessage,initsGeneraltabyoucanconfigure:
- Start address:theaddressofthefirstModbusobjecttoreadorwrite,intherange1..65536;bewarethatmanymanufacturersusetherange0..65535intheirmanuals:ifthisiscase,youhavetoadd1totheStartaddress;
- Polling time:themessagewillbeprocessedwiththisperiod[ms];forwritingopera-tions,0meanstowriteitonlyonvariationofthevalue,forreadingoperations0meansmaximumspeed;
- Time out:theoperationwillfailwhenthistimeoutexpires[ms]; - Wait before send:Modbusmasterwillwaitforthistime[ms]beforesendingthemes-sage;thisisusefulforslavenodesthatneedsometimeofsilenceonthebusinordertobeabletoprocessanewmessage.
3.4.1.2 MODBUS OBJECT TAB
Beside the Generaltab,eachdifferentmessagehasasecondtabwhereyoucanconfig-ure the list of objects to read or write.UsingtheAddbutton,insertonerowforeachModbusobjecttoreadorwrite,upto: - 8registers(16-bitModbusobjects) - 16Coils/DiscreteInputs(1-bitModbusobjects)thefirstrowhastheaddressconfiguredintheStart addressboxintheGeneraltab,and the other rows increment and follow.Foreachrow,presstheAssignbuttontochooseamongallsuitableStatus variables thePLCvariabletolinkandtobereadorwrittenwiththisModbusmessage.
user manual 11
SoMachine HVAC - Application
Pleasenotethatyoucanleaveunassignedrowsinthemessage:ifthisisthecase,cor-respondingModbusobjectswillstillberead/written,buttheirvaluesisnotassignedto/fromaPLCvariable.AsfarasModbusmessagesworkingwithmultipleobjectsareconcerned(thatis,ModbusFC01,FC02,FC03,FC04,FC15,andFC16),youcanmap32-bitvariablesonthem:inthiscase,youhavetoleavethefollowingrowempty,toavoidoverlappingofPLCvariables.
3.5 MODBUS CUSTOMModbuscustomdevicescanbecreatedandediteddirectlybytheuser.Inthiswayyoucanuseinyourprojectandaddinthecatalogforfuturereuseanythird-partyModbusslave, characterizing itsModbusmaponly thefirst timeandsimplifyingitsfurtheruse,becauseyoudonothavetocareaboutModbusmessagesandfunctionsanymore.
3.5.1 LAUNCHING MODBUS CUSTOM EDITOR
TocreateanewModbuscustomdevice,chooseRun ModbusCustomEditor from the De-veloper menu.
TheexternalModbusCustomEditortoolwillbelaunched,withanewemptydocument.
3.5.2 WORKING WITH MODBUS CUSTOM EDITOR
PleaserefertoSoMachineHVAC-ConnectionUserManualforinformationon: - how to use ModbusCustomEditortocreate/edit/deleteModbuscustomdevices; - how to use a Modbus custom device as a Modbus RTU slave node.
3.6 BUILDING CONFIGURATIONConfigurationoftheModbusRTUmaster isautomaticallybuiltwhenevertheproject issaved.YoumayalsoforceSoMachineHVAC-ApplicationtobuildtheconfigurationbyselectingBuild configuration item from the Developer menu.
12 user manual
SoMachine HVAC - Application
3.6.1 CONFIGURATION ERRORS
If thecompilerfindsanyconfigurationerror,build isabortedandanerrormessage isshown in the Outputwindow,intheResources tab.
Ifyoudouble-clickontheerrormessage,SoMachineHVAC-Applicationwillopentheproperpageoftheconfigurationwizard,toletyouquicklyfixtheconfiguration.
3.6.2 GENERATED PROJECT ELEMENTS
Aftersuccessfulbuildoftheconfiguration,youmayfindintheprojecttreeaModbus_cfg folder,containingprojectelementsgeneratedbytheModbusRTUmasterconfigurationwizard.
user manual 13
SoMachine HVAC - Application
Inparticular,youwillalwaysfindanIEC 61131-3 STRUCTinstanceforeachconfiguredslave node and a FUNCTION_BLOCKinstanceforeachconfiguredModbusmessage.TheseelementscanbeusefulforPLCapplicationdevelopmentanddebugging,sinceyoucanaccesstheirdata(forexample,diagnosticscounters)either inthePLCapplicationitselforinthedebugwindows.SeeChapter4,fordetails.
3.6.3 EXECUTABLE ELEMENTS
Inadditiontotheelementsshownintheprojecttree,theModbusRTUmasterconfigura-tionwizardalsooutputs: - anIEC61131-3PROGRAMtoberunbytheInitPLCtask,afteranyotherPROGRAMassignedtothetask.Thisprogramtakescareofinitializingslavesandmessages,ac-cordingtotheconfiguration,withvaluesthatdonotchangeintime(forexample,theslaveaddressorthemessagebaseaddress);
- anotherPROGRAMtoberunbytheModbusPLCtask,afteranyotherPROGRAMas-signedtothetask.ThisprogramactuallyimplementtheModbusmaster,byperiodicallycallingappropriatetargetblockstosendModbusmessagesoutonthebusandcopyvaluesbetweenPLCvariablesandModbusobjects.
PleasenotethatthesePROGRAMsarehidden,sincetheyareofnousetothedeveloper.YoumayalsoavoidtomakeanyassumptionsonhowthePROGRAMsareimplemented,sincetheymaynotholdanymoreinnewerversionsofSoMachineHVAC.
14 user manual
SoMachine HVAC - Application
user manual 15
SoMachine HVAC - Application
4. MANUAL CODING
Youmaywanttomanuallycode(partof)theconfigurationoftheModbusRTUmasterforaModiconM171Opt.Forexample,consideryouwanttosendaparticularmessagetoaslavejustonceor,asasecondexample,afteraveryspecificPLCapplication-relatedeventoccurred:inbothcases,theconfigurationwizardmaynotsuityourneeds,sinceyoucannotforcethecon-figurationitgeneratestofollowthiskindofrules.HoweveryoucanalwayswritecustomIEC61131-3codetomeetyourrequirements:thiscodewill,ofcourse,makesdirectuseofavailabletargetblocks.
4.1 WORKING WITH MODBUS PLC TASKThe ModbusPLCtaskisapreciousresourceforthedevelopercodingpartoftheModbusRTUmasterconfigurationbyhand:itisadedicatedentry-pointyoushoulduseforeveryoperationcausingamessagetobesentonthebus.Ifyoufollowthisrule,ModbusmessageswillnotaffectthePLCTimed task and will have limitedimpactonlower-prioritytasks,sincetheyarecarriedonasynchronously.Ontheotherhand,customcodewilladdtothecodegeneratedbytheconfigurationwizard,sothattheoverallperformanceoftheModbusRTUmasterisaffected(thatis,moretimeisrequiredforthemastertocompleteafullcycle).
4.2 EXAMPLESSinceyoucanwritecustomcode,youarefreetoaugmenttheconfigurationgeneratedbythewizardinwaysthismanualcannotcoverinfulldepth.However,thisparagraphincludesfewverycommonworkingexamples.
4.2.1 HOW TO SEND A MESSAGE JUST ONCE
Consideryouwanttosendamessagetoaslavejustonce,immediatelyafterthepower-on.Themessage is aModbus Function05and the addressee is alreadymanagedby theconfigurationwizard(thisimpliesthatanexistingSTRUCT instance for the slave node is alreadyavailableintheprojecttree,intheModbus_cfgfolder:inthefollowingcodesnip-pet,thatSTRUCT instance is the variable Slave2).
16 user manual
SoMachine HVAC - Application
YoucanaddaPROGRAMtotheModbusPLCtaskwiththefollowinginstructions:(* If Modbus master is not enable, skip custom messages *)
IF NOT sysMbMRTUStatus.enabled THEN
(* When Modbus master is enabled again, send the message again *)
sent := FALSE;
RETURN;
END_IF;
(* Una tantum message to Slave #2 *)
IF NOT sent THEN
(* Prepare the message by setting input variables to proper values *)
Slave2_WriteCoil12.node := ADR( Slave2 );
Slave2_WriteCoil12.address := 12;
Slave2_WriteCoil12.timeout := 1000;
Slave2_WriteCoil12.object := TRUE;
(* Send the message by invoking the FUNCTION_BLOCK *)
Slave2_WriteCoil12();
(*
* Check if correctly received by the slave:
* in this case never send it again.
*)
sent := NOT Slave2_WriteCoil12.error;
END_IF;
user manual 17
SoMachine HVAC - Application
Pleasenote that youhave to create theSlave2_WriteCoil12 variable as an instance of thetargetblocksysMbMRTU_FC05. Since that instance has a state which affects the behavioroftheblock,youshouldavoidtoreusethesamevariableforanotherModbusmessage.
4.2.2 HOW TO PUT DIAGNOSTICS COUNTERS IN A MENU
CustomcodecanbeusedalsoforpublishingModbusRTUmasterdiagnosticsinformationin a Modicon M171 application menu.Consideryouwanttopublishdiagnosticscountersforaspecificslavenode:theyhavetoappearinasub-menutheusercanaccessonthelocaldisplayfromtheSet menu.Youfirsthavetosetupallrequiredstatusvariablesandassembletheminamenu:
18 user manual
SoMachine HVAC - Application
Then,youcanaddthefollowingcodetoaPROGRAMexecutedbytheModbusPLCtask:(* Publish Slave #2 diagnostics counters *)
Slave2_MessageCount := Slave2.diagnostics.messageCount;
Slave2_ErrorCount := Slave2.diagnostics.errorCount;
Slave2_LastError := Slave2.diagnostics.lastError;
Slave2_LastException := Slave2.diagnostics.lastException;
4.2.3 HOW TO DISABLE THE MODBUS RTU MASTER
SupposeyouwanttodynamicallydisabletheModbusRTUmasteronalongpressoftheESCkey(localdisplay),toallowSoMachineHVAC-Application’sdebuggerstoattachtothetargetdeviceevenifthePLCapplicationhasalreadybeenstarted;symmetrically,youwanttoenableitagainonalongpressoftheSETkey.Thefollowingcodedoesthejob:(* On ESC key long-press, disable Modbus RTU master *)
IF sysKeyFunctions[ 1 ] THEN
(* Reset long-press event *)
sysKeyFunctions[ 1 ] := FALSE;
(* Disable Modbus RTU master *)
boolWarningsKiller := sysMbMRTU_Enable( FALSE );
END_IF;
(* On SET key long-press, enable Modbus RTU master *)
IF sysKeyFunctions[ 3 ] THEN
(* Reset long-press event *)
sysKeyFunctions[ 3 ] := FALSE;
(* Enable Modbus RTU master *)
boolWarningsKiller := sysMbMRTU_Enable( TRUE );
END_IF;
4.2.4 HOW TO DISABLE A SLAVE NODE
Youmaywanttoaddcodetocheckifaslavenodeisnotresponding(anymore)and,inthiscase,tostoptheModbusRTUmastertosendmessagesto it.Thiscanbeuseful,especiallyduetothefactthattimespentwaitingforaresponsefromthatslave(tillthetimeoutoccurs–canbeseconds)affectstheoverallmasterperformance.
usermanual 19
SoMachine HVAC - Application
Thefollowingcodemonitorsthenumberoferrorsoccurredanddisablestheslavenodeifthisnumberisaboveathreshold:(*
* Test if the user issued a command to enable Slave #2 again.
*
* (Slave2_Enable is a status variable this example application
* makes available in FREE Smart’s menu, as an explicit command
* to enable again Slave #2.)
*)
IF Slave2_Enable THEN
(* Reset the command *)
Slave2_Enable := FALSE;
(* Reset the counters, so that the test below works again *)
Slave2.messageCount := 0;
Slave2.errorCount := 0;
Slave2.lastError := ErrNone;
Slave2.lastException := ExcNone;
(* Re-enable Slave #2 *)
Slave2.enabled := TRUE;
END_IF;
(* Is the error count above the configured threshold? *)
IF Slave2.diagnostics.errorCount > MAX_ERRS THEN
(* Disable Slave #2 *)
Slave2.enabled := FALSE;
END_IF;