您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 薪酬管理 > 6-xPC-Target-API
xPCTargetAPIUnderVisualStudioandLabVIEWEnvironment主讲教师姜洪洲机电学院WhatisxPCAPIThexPCTargetC-APIisdistributedasaDynamic-LinkLibrary(DLL).ThisDLLconsistsofapproximately90functionsthatareusefulforloading,monitoringandcontrollingareal-timeapplicationrunningonthexPCTargetPC.TheAPIiswrittenintheCprogramminglanguage,andthisisreflectedinthedocumentation.However,theAPIfunctionsareusablefromotherlanguages/applicationssuchasVisualBASIC,C++,Java,LabView,etc.TwoxPCAPIexamplesinthislecture,oneiswritteninclanguageandtheotherfromLabVIEW.xPCAPIsetupxpcapi1.1(matlab6.0)xpcapi1.2,xpcapi1.3(matlab6.1)xpcapi2.0(matlab6.5)Note1:CheckthexPCTargetProductNewsPageat:xPCAPIExamplefromLabVIEWcanonlybefoundinthexpcapi1.1.DirectoriesandFiles(matlab6.5)ThenecessaryxPCTargetAPIfilesareinthedirectoryC:\MATLABroot\toolbox\rtw\targets\xpc\apiThenecessarysf_car_xpcfilesareinthedirectoryC:\MATLABroot\toolbox\rtw\targets\xpc\api\VisualCAfewthingscommontoallthefunctions(1)Almosteveryfunction(exceptxPCOpenSerialPort,xPCOpenTcpIpPort,xPCGetLastError,andxPCErrorMsg)hasasoneofitsparameterstheintegervariableport.ThisvariableisreturnedfromxPCOpenSerialPortandxPCOpenTcpIpPort,andistheplaceholderforthecommunicationlinkwiththetargetmachine.Thereturnedvaluefromthesetwofunctionsshouldbeusedintheotherfunctionstomakesurethepropercommunicationschannelisused.Afewthingscommontoallthefunctions(2)Almosteveryfunction(exceptxPCGetLastErrorandxPCErrorMsg)settheaglobalerrorvalueincaseoferror.ThisvalueisobtainedbycallingthefunctionxPCGetLastError,andadescriptivestringabouttheerrorisretrievedbyusingthefunctionxPCErrorMsg.Whiletheactualvaluesoftheerrornumbersaresubjecttochange,azerovaluealwaysmeansthattheoperationcompletedwithouterrors,whileanon-zerovaluesignifiesanerrorcondition.NotealsothattheerrorvalueisreseteverytimeanAPIfunctioniscalled:therefore,theerrorstatusshouldbecheckedassoonaspossibleafterafunctioncall.xPCAPIFunctions(1)CommunicationsFunctionsxPCOpenSerialPort,xPCOpenTcpIpPort,xPCReOpenPort,xPCClosePort,xPCTargetPing,xPCReboot,xPCGetLoadTimeOut,xPCSetLoadTimeOut.TargetApplicationRelatedFunctionsxPCSetStopTime,xPCGetStopTime,xPCSetSampleTime,xPCGetSampleTime,xPCGetExecTime,xPCGetAppName,xPCStopApp,xPCStartApp,xPCIsAppRunning,xPCIsOverloaded,xPCAverageTET,xPCMinimumTET,xPCMaximumTET,xPCLoadApp,xPCUnloadApp.xPCAPIFunctions(2)DataLoggingRelatedFunctionsxPCGetNumOutputs,xPCGetNumStates,xPCNumLogSamples,xPCMaxLogSamples,xPCNumLogWraps,xPCGetStateLog,xPCGetOutputLog,xPCGetTETLog,xPCGetTimeLog.ScopeRelatedFunctionsxPCGetScopes,xPCScGetType,xPCAddScope,xPCRemScope,xPCScAddSignal,xPCScRemSignal,xPCScStart,xPCScStop,xPCIsScFinished,xPCScGetData,xPCScGetState,xPCScGetStartTime,xPCScGetSignals,xPCSetScope,xPCGetScope,xPCScSetDecimation,xPCScGetDecimation,xPCScSetNumSamples,xPCScGetNumSamples,xPCScSetTriggerLevel,xPCScSetTriggerLevel,xPCScSetTriggerMode,xPCScSetTriggerMode,xPCScSetTriggerScope,xPCScSetTriggerScope,xPCScSetTriggerSignal,xPCScSetTriggerSignal.xPCScSetNumPrePostSamples,xPCScGetNumPrePostSamples.xPCAPIFunctions(3)TargetScopeRelatedFunctionsxPCTgScSetGrid,xPCTgScGetGrid,xPCTgScSetYLimits,xPCTgScGetYLimits,xPCTgScSetMode,xPCTgScGetMode,xPCTgScSetViewMode,xPCTgScGetViewMode,Monitoring/TuningRelatedFunctionsxPCGetNumParams,xPCGetNumSignals,xPCGetParamDims,xPCGetSignalWidth,xPCGetSignalIdx,xPCGetParamIdx,xPCGetParamName,xPCGetSignalName,xPCSetParam,xPCGetParam,xPCGetSignal,xPCGetSignals.MiscellaneousFunctionsxPCGetLastError,xPCErrorMsg,xPCSetEcho,xPCGetEcho.xPCOpenSerialPortPrototype:intxPCOpenSerialPort(intcomport);Description:xPCOpenSerialPorttakesasargumentanintegerwhichservesastheindexoftheCOMporttobeused(0isCOM1,1isCOM2,etc).Itreturnsanintegerwhichservesastheplaceholderforallsubsequentcommunication.xPCOpenTcpIpPortPrototype:intxPCOpenTcpIpPort(char*address,char*port);Description:OpensaconnectiontotheTCP/IPlocationspecifiedbytheIPaddressaddress(asadotteddecimalstring,e.g.192.168.0.1,andportnumberport(asastring,e.g.22222.Returnsanonnegativeintegerifitsucceeds(theportvariableusedinvirtuallyeveryotherfunction),or-1ifitfails.Theglobalerrornumberisalsoset,whichmayberetrievedusingxPCGetLastError.xPCClosePortPrototype:voidxPCClosePort(intport);Description:xPCClosePortclosestheRS232orTCP/IPCommunicationChannelopenedbyeitherxPCOpenSerialPortorbyxPCOpenTcpIpPort.Ittakesasargumenttheintegerportreturnedbythesefunctions.xPCLoadAppPrototype:voidxPCLoadApp(intport,char*pathstr,char*filename);Description:ThisfunctionloadsthecompiledapplicationtothetargetPC.Thefunctiontakesasparametersthepathtotheapplicationpathstr,andthefilename.pathstrmaybesettoNULLortothestringnopathiftheapplicationisinthepresentdirectory.Also,pathstrmustnotcontainthetrailingbackslash.filenamemustnotcontaintheapplicationextension(compiledmodelshavefilenamesofmodelname.dlm).xPCStartAppPrototype:voidxPCStartApp(intport);Description:Startstheapplicationloadedonthetargetmachin
本文标题:6-xPC-Target-API
链接地址:https://www.777doc.com/doc-3141517 .html