user manual 1 SoMachine HVAC - Application Contents 1. 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. Configuration wizard 7 3.1 How to enable Modbus master 7 3.2 Serial line configuration 7 3.3 How to add configuration elements 8 3.4 Generic Modbus 8 3.4.1 Modbus messages 9 3.5 Modbus custom 11 3.5.1 Launching Modbus Custom Editor 11 3.5.2 Working with Modbus Custom Editor 11 3.6 Building configuration 11 3.6.1 Configuration errors 12 3.6.2 Generated project elements 12 3.6.3 Executable elements 13 4. Manual coding 15 4.1 Working with Modbus PLC task 15 4.2 Examples 15 4.2.1 How to send a message just once 15 4.2.2 How to put diagnostics counters in a menu 17 4.2.3 How to disable the Modbus RTU master 18 4.2.4 How to disable a slave node 18
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
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):
- NofullapplicationcompatibilitybetweenModiconM171Opt.ModBusSlaveOnlyandModiconM171Opt:additionalworkistypicallyrequiredtoportanapplicationwrittenfor one device to the other one.
3.1 HOW TO ENABLE MODBUS MASTERToopentheModbusmasterconfigurationwizard,firstselectMaster Modbus RTU element in the Resources tabofSoMachineHVAC-Application’sProject window.
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.
3.4 GENERIC MODBUSTheGenericModbusobject is agenericModbus slave that canbe insertedunder theRS485portoftheModiconM171Opt,whenModbusmasterisenabled.YoucanusetheGenericModbuswhenyouwanttomanuallyconfigureandhavefullcon-troloverthesingleModbusmessagestosendtotheslave.Anothertypicalusage is for third-partydevicesthatyouplantouse justonce inyourprojects,andyoudonotwanttoputinthecatalogforfuturereuse.
- 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.
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.
Inparticular,youwillalwaysfindanIEC 61131-3 STRUCTinstanceforeachconfiguredslave node and a FUNCTION_BLOCKinstanceforeachconfiguredModbusmessage.TheseelementscanbeusefulforPLCapplicationdevelopmentanddebugging,sinceyoucanaccesstheirdata(forexample,diagnosticscounters)either inthePLCapplicationitselforinthedebugwindows.SeeChapter4,fordetails.
4.1 WORKING WITH MODBUS PLC TASKThe ModbusPLCtaskisapreciousresourceforthedevelopercodingpartoftheModbusRTUmasterconfigurationbyhand:itisadedicatedentry-pointyoushoulduseforeveryoperationcausingamessagetobesentonthebus.Ifyoufollowthisrule,ModbusmessageswillnotaffectthePLCTimed task and will have limitedimpactonlower-prioritytasks,sincetheyarecarriedonasynchronously.Ontheotherhand,customcodewilladdtothecodegeneratedbytheconfigurationwizard,sothattheoverallperformanceoftheModbusRTUmasterisaffected(thatis,moretimeisrequiredforthemastertocompleteafullcycle).
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: