Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
TakinganNI-DAQ™mxMeasurementinLabVIEW™January2008,370689K-01ThistutorialteachesyouhowtotakeanNI-DAQmxmeasurementinLabVIEW7.xorlaterusingtheDAQAssistant.TheDAQAssistantisagraphicalinterfaceforconfiguringmeasurementtasks,channels,andscales.YoualsocanusetheDAQAssistanttogenerateNI-DAQmxcodefromthetask.Inthistutorial,youcreateavoltagemeasurementtaskusingtheDAQAssistant.YouthenlearnhowtoeditthetaskandgeneratecodefromthetaskinLabVIEW.
NoteThistutorialassumesyouarefamiliarwithLabVIEW.IfyouareanewuserofLabVIEWorareunfamiliarwiththeLabVIEWExpressVIs,refertotheGettingStartedwithLabVIEWmanual.
ThisdocumentdescribesNI-DAQmx.ForinformationonTraditionalNI-DAQ(Legacy),refertotheMeasurementandAutomationExplorerHelpforTraditionalNI-DAQ(Legacy).Tonavigatethishelpfile,usetheContents,Index,andSearchtabstotheleftofthiswindow.TocommentonNationalInstrumentsdocumentation,refertotheNationalInstrumentsWebsite.©2003–2008NationalInstrumentsCorporation.Allrightsreserved.
ConventionsThishelpfileusesthefollowingconventions:
» The»symbolleadsyouthroughnestedmenuitemsanddialogboxoptionstoafinalaction.ThesequenceFile»PageSetup»OptionsdirectsyoutopulldowntheFilemenu,selectthePageSetupitem,andselectOptionsfromthelastdialogbox.Thisicondenotesatip,whichalertsyoutoadvisoryinformation.Thisicondenotesanote,whichalertsyoutoimportantinformation.Thisicondenotesacaution,whichadvisesyouofprecautionstotaketoavoidinjury,dataloss,orasystemcrash.
bold Boldtextdenotesitemsthatyoumustselectorclickoninthesoftware,suchasmenuitemsanddialogboxoptions.Boldtextalsodenotesparameternames,emphasis,oranintroductiontoakeyconcept.
darkred Textinthiscolordenotesacaution.green Underlinedtextinthiscolordenotesalinktoahelptopic,
helpfile,orWebaddress.italic Italictextdenotesvariablesorcrossreferences.Thisfont
alsodenotestextthatisaplaceholderforawordorvaluethatyoumustsupply.
monospace Textinthisfontdenotestextorcharactersthatyoushouldenterfromthekeyboard,sectionsofcode,programmingexamples,andsyntaxexamples.Thisfontisalsousedforthepropernamesofdiskdrives,paths,directories,programs,subprograms,subroutines,devicenames,functions,operations,variables,filenames,andextensions.
IntroductiontoTakinganNI-DAQmxMeasurementinLabVIEWThistutorialteachesyouhowtotakeanNI-DAQmxmeasurementinLabVIEW7.xorlaterusingtheDAQAssistant.TheDAQAssistantisagraphicalinterfaceforconfiguringmeasurementtasks,channels,andscales.YoualsocanusetheDAQAssistanttogenerateNI-DAQmxcodefromthetask.Inthistutorial,youcreateavoltagemeasurementtaskusingtheDAQAssistant.Thistutorialteachesyouhowto:
LaunchtheDAQAssistantbyusingtheDAQAssistantExpressVIinLabVIEWConfigureavoltagetaskintheDAQAssistantTestthetaskusingtestpanelsEditthetaskGeneratethecodetorunthetaskNoteThistutorialassumesyouarefamiliarwithLabVIEW.IfyouareanewuserofLabVIEWorareunfamiliarwiththeLabVIEWExpressVIs,refertotheGettingStartedwithLabVIEWmanual.
Next:BeforeYouBegin
BeforeYouBeginTousethistutorial,youmusthavethefollowingsoftwareandhardwareinstalledinyoursystem:
LabVIEW8.xorlaterNI-DAQmxfromNI-DAQ8.xorlater,includingLabVIEW7.xorlatersupportfilesAdataacquisition(DAQ)device,physicalorsimulated,thatissupportedbyNI-DAQmxandisconnectedtoavoltagesignal.RefertotheMeasurement&AutomationExplorerHelpforNI-DAQmxforinstructionsoncreatinganNI-DAQmxsimulateddevice.RefertotheNI-DAQReadmefiletoseeifNI-DAQmxsupportsyourdevice.
RefertotheDAQGettingStartedGuideandthedevicedocumentationforinformationaboutinstallingandconfiguringthesoftwareandhardware.
Previous:IntroductiontoTakinganNI-DAQmxMeasurementinLabVIEW
Next:ChannelsandTasksinNI-DAQmx
ChannelsandTasksinNI-DAQmxAphysicalchannelisaterminalorpinatwhichyoucanmeasureorgenerateananalogordigitalsignal.Avirtualchannelisacollectionofpropertysettingssuchasaname,aphysicalchannel,inputterminalconnections,thetypeofmeasurementorgeneration,andcanincludescalinginformation.InNI-DAQmx,virtualchannelsareintegraltoeverymeasurement.InTraditionalNI-DAQ(Legacy)andearlierversions,configuringvirtualchannelsisanoptionalwaytorecordwhichchannelsarebeingusedfordifferentmeasurements.InNI-DAQmx,youcanconfigurevirtualchannelswiththeDAQAssistant,whichyoucanopenfromMAXoryourapplicationsoftware.YoualsocanconfigurevirtualchannelswiththeNI-DAQmxAPIinyourapplicationprogram.InTraditionalNI-DAQ(Legacy),youconfigurevirtualchannelsusingMAX.Atask,animportantconceptforNI-DAQmx,isacollectionofoneormorevirtualchannelswithtiming,triggering,andotherproperties.Conceptually,ataskrepresentsameasurementorgenerationyouwanttoperform.Youcansetupandsavealloftheconfigurationinformationinataskandusethetaskinanapplication.InNI-DAQmx,youcanconfigurevirtualchannelsaspartofataskorseparatefromatask.Virtualchannelscreatedinsideataskarelocalvirtualchannels.Virtualchannelsdefinedoutsideataskareglobalvirtualchannels.YoucancreateglobalvirtualchannelsinMAXorinyourapplicationsoftwareandthensavetheminMAX.Youcanuseglobalvirtualchannelsinanyapplicationoraddthemtoanumberofdifferenttasks.Ifyoumodifyaglobalvirtualchannel,thechangeaffectsalltasksinwhichyoureferencethatglobalvirtualchannel.
Previous:BeforeYouBegin Next:1.LaunchtheAssistant
1.LaunchtheDAQAssistantExpressVIYoucanlaunchtheDAQAssistantinseveralways.CompletethefollowingstepstolaunchtheDAQAssistantbyplacingtheDAQAssistantExpressVIontheblockdiagraminLabVIEW.
1. OpenablankVIinLabVIEW.2. PlacetheDAQAssistantExpressVIontheblockdiagram.
TheDAQAssistantlaunches,startingwiththeCreateNewdialogbox.
Previous:ChannelsandTasksinNI-DAQmx Next:2.CreatetheTask
2.CreatetheTaskIntheCreateNewExpressTaskdialogboxoftheDAQAssistant,completethefollowingstepstocreateatasktomeasurevoltagefromtheDAQdevice.
1. SelectAcquireSignals.2. SelectAnalogInputfortheI/Otype.3. SelectVoltageforthemeasurementtoperform.4. InSupportedPhysicalChannels,selectthephysicalchannelon
theDAQdevicetowhichyouconnectedthevoltagesignal.5. ClickFinish.
TheDAQAssistanttaskconfigurationscreenlaunches.
Previous:1.LaunchtheDAQAssistant Next:3.ConfiguretheTask
3.ConfiguretheTaskAfteryoucreateatask,youcanconfigurechannel-specificsettingssuchascustomscaling,inputrange,andterminalconfiguration.Youalsocanconfiguretask-specificsettingssuchastimingandtriggering.Toconfigurethevoltagemeasurementtask,completethefollowingsteps.
1. Specifytheinputrange.Youcanusethedefaultvalues.2. Selecttheterminalconfigurationyouusedtoconnectthesignal.
3. UnderTimingSettings,selectNSamplesastheAcquisitionMode.Enter100.00forSamplesToRead,andenter1000.00forRate(Hz),asshowninthefollowingfigure.
NoteThisexampledoesnotusecustomscalingortriggering.Tolearnaboutscalingandtriggering,refertotheNI-DAQmxHelp.
Previous:2.CreatetheTask Next:4.TesttheTask
4.TesttheTaskYoucanviewdataacquiredintheDAQAssistanttotestthetaskandsignalconnection.ClickRuntotestthetask.Dataacquiredappearsinthegraph.Verifythatyouareacquiringexpecteddataandthatyouconnectedthesignalproperly.Ifnecessary,modifyanysettingsandrunyourtaskagain.
ClickOKwhenyoufinishtestingyourtask.
Previous:3.ConfiguretheTask Next:5.EdittheTask
5.EdittheTaskIfyouwanttomakechangestoyourtasklater,youcanopenthetaskusingtheDAQAssistantExpressVIinLabVIEW.Completethefollowingstepstoeditthevoltagetasktoacquiredatacontinuously:
1. Double-clicktheDAQAssistantExpressVIontheblockdiagraminLabVIEW.
2. WhentheDAQAssistantlaunches,selectContinuousSamplesfortheAcquisitionMode.
3. ClickOK.4. SavetheVIasMyVoltageTask.vi.
Previous:4.TesttheTask Next:6.GenerateCode
6.GenerateCodeUsingtheDAQAssistant,youhavethreeoptionsforgeneratingcodeinLabVIEWfromataskorchannel:Example—Generatesallthecodenecessarytorunthetaskorchannel,suchasVIsneededtoreadorwritesamples,VIstostartandstopthetask,loops,andgraphs.Choosethisoptionifyouwanttorunthetaskorchannelyoucreatedtoverifythatitworksortouseyourconfigurationinasimpleapplication.InLabVIEW,thisoptionaddstotheVIyouareworkingin.ThegeneratedcodeisasimpleNI-DAQmxexamplethatyoucanthenmodifyforyourapplication.Configuration—Generatesthecodethatreplicatestheconfigurationofthetasksandchannels.LabVIEWreplacestheDAQmxtasknamecontrolwithasubVIthatcontainsVIsandpropertynodesusedforchannelcreationandconfiguration,timingconfiguration,andtriggeringconfigurationusedinthetaskorchannel.Choosethisoptionifyouwanttodeployyourapplicationtoanothersystem.RefertoDeploymentintheNI-DAQmxHelplocatedatStart»AllPrograms»NationalInstruments»NI-DAQformoreinformation.WhenyougenerateConfigurationcode,thelinkbetweentheapplicationandtheDAQAssistantislost.AnychangesyoumaketotheconfigurationcodearenotreflectedintheDAQAssistant.YoucanregenerateConfigurationcodefromtheDAQAssistant,buttheregeneratedcodedoesnotincorporatepreviouschangesthatyoumadetothecode.
CautionAlthoughgeneratedconfigurationcodeincludescodetocreatevirtualchannelsandtasks,itdoesnotincludecodetocreatescales.Ifyougenerateconfigurationcodefordeploymentofapplicationsthatincludescales,youmustensurethatthescalesareconfiguredinthetargetcomputer.RefertoDeploymentintheNI-DAQmxHelplocatedatStart»AllPrograms»NationalInstruments»NI-DAQformoreinformation.
ConfigurationandExample—GeneratesbothConfigurationcodeandExamplecodeforthetaskorchannelinonestep.
TipIfyouconfigureataskusingtheDAQAssistantExpressVI,youcanright-clicktheVIandselectGenerateNI-DAQmxCodeto
generateconfigurationandexamplecode.ThecodereplacestheDAQAssistantExpressVI.
Completethefollowingstepstogeneratecodetorunthevoltagetask.1. Right-clicktheDAQAssistantExpressVIontheblockdiagram,
andselectGenerateNI-DAQmxCodefromtheshortcutmenu.2. TheDAQAssistantgeneratesallthecodenecessarytorunthe
task,asshowninthefollowingblockdiagram.
3. SavetheVIasMyVoltageTask.vi.4. Displaythefrontpanel.ClicktheRunbuttontostartthe
application.NoteAnychangesyoumaketothegeneratedcodeapplyonlytotheVIandarenotsavedintothetaskconfigurationstoredinMAX.
Previous:5.EdittheTask Next:What'sNext
What'sNextInthistutorial,youlearnedhowto
LaunchtheDAQAssistantbyusingtheDAQAssistantExpressVIinLabVIEWConfigurethetaskintheDAQAssistantTestthetaskusingtestpanelsEditthetaskGeneratethecodetorunthetask
RelatedDocumentationThefollowingdocumentscontaininformationthatyoumightfindhelpfulasyouuseNI-DAQmxandLabVIEW:
DAQAssistantHelp—ThishelpfilecontainsinformationaboutusingtheDAQAssistanttointeractivelyconfigurecommonmeasurementtasks,channels,orscales.InLabVIEW7.xorlater,LabWindows™/CVI™7.xorlater,orMeasurementStudio7.xorlater,youalsocanusetheDAQAssistanttogenerateNI-DAQmxcodefromthetasksandchannels.DAQGettingStartedGuide—ThisguidedescribeshowtoinstallNI-DAQmxdriversoftwareanddataacquisition(DAQ)devicesandhowtoconfirmthatthedeviceisoperatingproperly.GettingStartedwithLabVIEW—ThismanualcontainsinformationyouusetofamiliarizeyourselfwiththeLabVIEWgraphicalprogrammingenvironmentandthebasicLabVIEWfeaturesyouusetobuilddataacquisitionandinstrumentcontrolapplications.SelectStart»AllPrograms»NationalInstruments»LabVIEW»SearchtheLabVIEWBookshelf.LabVIEWHelp—ThishelpfilecontainsinformationaboutLabVIEWpalettes,menus,tools,VIs,andfunctions.Thishelpfilealsoincludesstep-by-stepinstructionsforusingLabVIEWfeatures.InLabVIEW,selectHelp.Measurement&AutomationExplorerHelpforNI-DAQmx—ThishelpfilecontainsinformationonconfiguringandtestingDAQdevices,SCXIdevices,SCCdevices,andRTSIcablesusingMeasurement&AutomationExplorer(MAX)forNI-DAQmxandinformationaboutspecialconsiderationsforoperatingsystems.InMAX,selectHelp»NI-DAQmx.
Tolearnmoreabouttasks,channels,andotherNI-DAQmxconcepts,refertotheNI-DAQmxHelplocatedatStart»AllPrograms»NationalInstruments»NI-DAQmxHelp.TheLabVIEWHelpalsoincludesinformationaboutcreatingandusingtasksinLabVIEWandreferenceinformationfortheNI-DAQmxVIs.YoualsocanlookattheexamplesthatshipwithNI-DAQmx.UsetheNIExampleFinderlocatedatHelp»FindExamplestosearchforexamplesrelatedtoNI-DAQmx.
Previous:6.GenerateCode
LaunchingtheDAQAssistantWhenyouconfigureataskusingtheDAQAssistantExpressVI,thetaskislocaltotheapplicationandisnotsavedtoMAXforuseinotherapplications.TheDAQAssistantExpressVIcontainsthecodeyouneedtorunthetask,exceptanyloops.YoumustconverttheDAQAssistantExpressVItoanNI-DAQmxTasktosavethetasktoMAXforuseinotherapplications.YoucanalsogeneratecodefromtheDAQAssistantExpressVI.Right-clicktheDAQAssistantExpressVIontheblockdiagraminLabVIEWandselectGenerateNI-DAQmxCode.TolaunchtheDAQAssistantfromatasknamecontrolinLabVIEW,completethefollowingsteps:
1. OpenablankVIinLabVIEW.2. PlacetheDAQmxtasknamecontrolfromtheDAQmxName
Controlspaletteonthefrontpanel.3. Right-clickthecontrolandselectNewNI-DAQmxTask»MAX
fromtheshortcutmenu.YoucanlaunchtheDAQAssistantfromMAXinthefollowingways:
Right-clickDataNeighborhoodandselectCreateNewfromtheshortcutmenu.IntheCreateNewwindow,selectNI-DAQmxTask.Right-clickyourdeviceunderDevicesandInterfacesinMAXandselectCreateNew.
ConvertingtheDAQAssistantExpressVItoanNI-DAQmxTaskWhenyouconfigureataskusingtheDAQAssistantExpressVI,thetaskislocaltotheapplicationandcannotbeusedinotherapplications.YoucanconvertaDAQAssistantExpressVItoanNI-DAQmxtaskifyouwanttosavethetasktoMAXforuseinotherapplicationsortogeneratecode.
NoteIfyouareworkingwithinaprojectinLabVIEW8.0,convertingtheDAQAssistantExpressVItoatasksavesthetasktotheproject.
CompletethefollowingstepstoconverttheDAQAssistantExpressVItoanNI-DAQmxtask.
1. Right-clicktheDAQAssistantExpressVIandselectConverttoNI-DAQmxTaskfromtheshortcutmenu.
2. TheDAQAssistantlaunches,andyoucanmodifythetask,ifnecessary.
3. ClicktheOKbutton.4. AnNI-DAQmxtaskreplacestheDAQAssistantExpressVI.