19

Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant
Page 2: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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.

Page 3: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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.

Page 4: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

IntroductiontoTakinganNI-DAQmxMeasurementinLabVIEWThistutorialteachesyouhowtotakeanNI-DAQmxmeasurementinLabVIEW7.xorlaterusingtheDAQAssistant.TheDAQAssistantisagraphicalinterfaceforconfiguringmeasurementtasks,channels,andscales.YoualsocanusetheDAQAssistanttogenerateNI-DAQmxcodefromthetask.Inthistutorial,youcreateavoltagemeasurementtaskusingtheDAQAssistant.Thistutorialteachesyouhowto:

LaunchtheDAQAssistantbyusingtheDAQAssistantExpressVIinLabVIEWConfigureavoltagetaskintheDAQAssistantTestthetaskusingtestpanelsEditthetaskGeneratethecodetorunthetaskNoteThistutorialassumesyouarefamiliarwithLabVIEW.IfyouareanewuserofLabVIEWorareunfamiliarwiththeLabVIEWExpressVIs,refertotheGettingStartedwithLabVIEWmanual.

Next:BeforeYouBegin

Page 5: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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

Page 6: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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

Page 7: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

1.LaunchtheDAQAssistantExpressVIYoucanlaunchtheDAQAssistantinseveralways.CompletethefollowingstepstolaunchtheDAQAssistantbyplacingtheDAQAssistantExpressVIontheblockdiagraminLabVIEW.

1. OpenablankVIinLabVIEW.2. PlacetheDAQAssistantExpressVIontheblockdiagram.

TheDAQAssistantlaunches,startingwiththeCreateNewdialogbox.

Previous:ChannelsandTasksinNI-DAQmx Next:2.CreatetheTask

Page 8: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

2.CreatetheTaskIntheCreateNewExpressTaskdialogboxoftheDAQAssistant,completethefollowingstepstocreateatasktomeasurevoltagefromtheDAQdevice.

1. SelectAcquireSignals.2. SelectAnalogInputfortheI/Otype.3. SelectVoltageforthemeasurementtoperform.4. InSupportedPhysicalChannels,selectthephysicalchannelon

theDAQdevicetowhichyouconnectedthevoltagesignal.5. ClickFinish.

TheDAQAssistanttaskconfigurationscreenlaunches.

Previous:1.LaunchtheDAQAssistant Next:3.ConfiguretheTask

Page 9: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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.

Page 10: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

Previous:2.CreatetheTask Next:4.TesttheTask

Page 11: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

4.TesttheTaskYoucanviewdataacquiredintheDAQAssistanttotestthetaskandsignalconnection.ClickRuntotestthetask.Dataacquiredappearsinthegraph.Verifythatyouareacquiringexpecteddataandthatyouconnectedthesignalproperly.Ifnecessary,modifyanysettingsandrunyourtaskagain.

ClickOKwhenyoufinishtestingyourtask.

Previous:3.ConfiguretheTask Next:5.EdittheTask

Page 12: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

5.EdittheTaskIfyouwanttomakechangestoyourtasklater,youcanopenthetaskusingtheDAQAssistantExpressVIinLabVIEW.Completethefollowingstepstoeditthevoltagetasktoacquiredatacontinuously:

1. Double-clicktheDAQAssistantExpressVIontheblockdiagraminLabVIEW.

2. WhentheDAQAssistantlaunches,selectContinuousSamplesfortheAcquisitionMode.

3. ClickOK.4. SavetheVIasMyVoltageTask.vi.

Previous:4.TesttheTask Next:6.GenerateCode

Page 13: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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

Page 14: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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

Page 15: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

What'sNextInthistutorial,youlearnedhowto

LaunchtheDAQAssistantbyusingtheDAQAssistantExpressVIinLabVIEWConfigurethetaskintheDAQAssistantTestthetaskusingtestpanelsEditthetaskGeneratethecodetorunthetask

Page 16: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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.

Page 17: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

Previous:6.GenerateCode

Page 18: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

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.

Page 19: Taking an NI-DAQmx Measurement in LabVIEWLabVIEW™ January 2008, 370689K-01 This tutorial teaches you how to take an NI-DAQmx measurement in LabVIEW 7.x or later using the DAQ Assistant

ConvertingtheDAQAssistantExpressVItoanNI-DAQmxTaskWhenyouconfigureataskusingtheDAQAssistantExpressVI,thetaskislocaltotheapplicationandcannotbeusedinotherapplications.YoucanconvertaDAQAssistantExpressVItoanNI-DAQmxtaskifyouwanttosavethetasktoMAXforuseinotherapplicationsortogeneratecode.

NoteIfyouareworkingwithinaprojectinLabVIEW8.0,convertingtheDAQAssistantExpressVItoatasksavesthetasktotheproject.

CompletethefollowingstepstoconverttheDAQAssistantExpressVItoanNI-DAQmxtask.

1. Right-clicktheDAQAssistantExpressVIandselectConverttoNI-DAQmxTaskfromtheshortcutmenu.

2. TheDAQAssistantlaunches,andyoucanmodifythetask,ifnecessary.

3. ClicktheOKbutton.4. AnNI-DAQmxtaskreplacestheDAQAssistantExpressVI.