DevelopingApplicationswiththeLabVIEWStatechartModule5ratings|4.40outof5ReadinEnglish|PrintOverviewThisdocumentexplainsthedefinitionofstatechartdiagramsanddemonstratesthebasicsoftheLabVIEWStatechartModule.TableofContents1.Introduction2.UsingLabVIEWStatecharts3.BenefitsofStatecharts4.Conclusion5.RelatedLinksIntroductionThismoduleaddstheabilitytocreatestatechartsinLabVIEWfordevelopingevent-basedcontrolandtestsystems.ThestatechartprogrammingmodelcomplementstheexistingLabVIEWmodelsfordataflow,textualmath,dynamicsystemmodeling,andconfiguration-baseddevelopment.Youcanchoosetherightmodelorcombinationofmodelstodevelopyoursystembasedonyourapplicationrequirements.[+]EnlargeImageTheNationalInstrumentsgraphicalsystemdesignplatformcombinestheprogrammingmodelsinLabVIEWwithoff-the-shelfdesktopandembeddedcontrollersandmeasurementI/O.Withthiscombination,youhaveanintegrateddevelopmenttoolchainfordesigning,prototyping,anddeployingsystems.LabVIEWstatechartsofferahigh-leveldesigntoolwithpowerfulscalabilitythroughprogrammingconceptssuchashierarchy,concurrency,andevents.Becausestatechartsprovideasystem-levelview,youcanuseLabVIEWstatechartsasexecutablespecifications.Thestatechartprogrammingmodelisespeciallyusefulfordevelopingcomplexsystemsthatmustrespondtoavarietyofeventssuchasembeddedcontrolsystemsandcommunicationssystems.WiththeLabVIEWStatechartModule,youcandeploydesignstoavarietyofhardwareplatformsrangingfromdesktopPCstoFPGAs.Note:ForcompleteLabVIEWStatechartModuledocumentation,refertotheshippingdocumentation.HistoryofStatechartsThestatechartdiagramwasinventedbyDavidHareloftheWeizmannInstituteofScienceinthe1980s.AccordingtoHarel,thepurposeofthestatechartdiagramwasto“extendconventionalstate-transitiondiagramswith…thenotionsofhierarchy,concurrency,andcommunication.”Harelinventedthediagramwhilehehelpeddesignacomplexavionicssystem,presumablyfindingtheexistingtoolsforsuchasystemlacking.Inthe1990s,statechartswereadoptedasabehaviordiagramwithintheUnifiedModelingLanguage(UML)specification,whichiswidelyusedformodelingembeddedsystems.HowStatechartsWorkTobeginunderstandingstatecharts,itisbesttostartwiththeclassicstatediagramandthenaddthenotionsofhierarchy,concurrency,andevents.Theclassicstatediagramconsistsoftwomainconstructs:statesandtransitions.InFigure2,thestatediagramdescribesasimplesodavendingmachinewithfivestatesandseventransitionstoillustratehowthemachineoperates.Themachinestartsinthe“idle”stateandtransitionstothe“countcoins”statewhencoinsareinserted.Thestatediagramshowsadditionalstatesandtransitionswhenthemachinewaitsforaselection,dispensesasoda,andgiveschange.Figure3showsastatechartthatdescribesthebehaviorofthesamemachine.Noticehowthenotionofhierarchyandeventsreducesthenumberofstatesandtransitions.Inthestatechart,youcannestthe“countcoins”and“dispense”stateswithinasuperstate.Youhavetodefineonlyonetransition(T3)fromeitherofthesetwostatestothe“givechange”state.YoucanconfiguretheT3transitiontorespondtothreeevents:sodadispensed,changerequested,orcoinsrejected.Additionally,youcaneliminatethe“selectsoda”stateintheclassicstatediagrambyintroducinga“guard”conditiontotransitionT2.Guardconditionsmustevaluateto“true”forthetransitiontooccur.Iftheresultoftheguardconditionis“false”theeventisignoredandthetransitiondoesnottakeplace.[+]EnlargeImageAtthispoint,youcanexpandthestatecharttodemonstratethenotionofconcurrencybyaddingatemperaturecontrolelementtothesoftwarewithinthevendingmachine.Figure4showshowyoucanencapsulatethedispensinglogicandthetemperaturecontrolintoanand-state.And-statesdescribeasystemthatissimultaneouslyintwostatesthatareindependentofeachother.TheT7transitionshowshowstatechartscandefineanexitthatappliestobothsub-statecharts.[+]EnlargeImageInadditiontohierarchyandconcurrency,statechartshaveotherfeaturesthatmakethemvaluableforcomplexsystems.Statechartshaveaconceptofhistory,allowingasuperstateto“remember”whichsubstatewithinitwaspreviouslyactive.Forexample,considerasuperstatethatdescribesamachinethatpoursasubstanceandthenheatsit.Ahalteventmaypausetheexecutionofthemachinewhileitispouring.Whenaresumeeventoccurs,themachinerememberstoresumepouring.UsingLabVIEWStatechartsWiththeLabVIEWStatechartModule,youcandesignsoftwarecomponentswithastatechartdiagramanddefinethebehaviorofthestatesandtransitionlogicwithdataflowgraphicalprogramming.UsetheLabVIEWProjectExplorertofullyintegratestatechartsintotheLabVIEWenvironment.EachLabVIEWstatecharthasseveralcomponentsthatyoucanusetoconfigurethecontextofthedesign.Figure5showsanexamplestatechartcalledLVStatechart1.lvsc.Youcancreatetriggersthatcorrespondtotransitionsandstatereactionsaswellaseditthelistofinputandoutputdatavariablesthatthestatechartuses.TheDiagram.vifilecontainstheactualstatechartdiagram.Withinthisdiagram,youcreatethestatesofthesystemandthetransitionsbetweenthem.Oneofthemainbenefitsofstatechartsishowtheyvisuallyrepresentthebehaviorofthesystemand,therefore,self-documentthesoftware.Figure6showsastatechartthatdescribesapackagingmachine.Youcaneasilyseethedifferentstatesofamachineandthetransitionsbe