EtherCAT入门教程.docx
- 文档编号:10461160
- 上传时间:2023-02-13
- 格式:DOCX
- 页数:13
- 大小:86.07KB
EtherCAT入门教程.docx
《EtherCAT入门教程.docx》由会员分享,可在线阅读,更多相关《EtherCAT入门教程.docx(13页珍藏版)》请在冰豆网上搜索。
EtherCAT入门教程
EtherCAT入门教程
本文翻译了kithara官方文档,也加入了一些理解,暂时
做得还不够完美,后续补充修正。
2014.06.06
EtherCAT
ThistutorialdescribesthefollowingtopicsusingtheEtherCAT
API
本向导描述了使用EtherCATAPI的功能说明Creatinga
EtherCATmasterassignedtoanetworkadapterCreatingslavesassignedtothemasterReal-timeprocessdataexchangewithdatasetsandassignedPDOsReal-timeup/downloadofservicedataobjects(SDO)Real-timemailboxcommunicationStatecontrolformasterandslavesGettinginformationformaster,
slaves,dataobjects,variableobjects中文说明创建EtherCAT主
实时过程数据交互Masterrelatedfunctions主站相关功能
Openinganetworkadapter打开网卡
Beforewecancreateamaster,itisnecessarytoopenanetworkadapterfirst.Thisisdonebyusingthefunction
KS_openAdapter.Asparametersanadaptername,areceiveandasendpoolsizeisneeded.Theadapternameisusuallythenameofanetworkdevice.ThefunctionKS_enumDevicesenumerates
alldevices.Toonlygetnetworkdevicestheparameter
打开网卡,需要的参数包括网卡名称,收发数据池大小等。
可以使用KS_enumDevices枚举设备获取网卡名称,使用该函数时参数deviceType应该设置为“NET”
MindthatthefunctionKS_openAdaptermustbecalledwiththeflagKSF_REALTIME_EXEC.
使用KS_openAdapter时需要将标志位flag设置为
ksError
KSF_REALTIME_EXEC,表明网卡运行在实时模式。
=KS_enumDevices(//枚举设备
"NET",
//Searchesfornetworkdevices
zero
name
if(ksError)
handlepointer
theController
Length
if(ksError)//...ForfurtherdetailsseeHowtolookupfordevices.
Creatingamaster创建主站
TocreateamasterthefunctionKS_createEcatMastercanbeused.AsparametersanetworkadapterhandleandapathtodevicedescriptionXMLfilesareneeded.Anameofatopologyfile(*.ktp)isoptional.ThedevicedescriptionXMLfilescanbefoundwithadeveloperinstallationintheXMLdirectoryorcanbedownloadedfromtheslavemanufacturerwebsite.AtopologyfilecanbecreatedwiththeKithara?
MasterMonitor?
.
使用KS_createEcatMaster创建主站,需要传入网卡句柄参数和从站XML设备描述文件路径,也可以加入一个拓扑文件
ktp参数。
设备描述文件可以从设备制造商的网站上获取。
拓扑文件可以用MasterMonitor生成。
TheKithara?
MasterMonitor?
isatoolfore.g.configuration,diagnosticsandsavingXMLconfigurationfilesforgraphicallyviewingslaves,objectsandvariablesorcomparingagiventopologywithatargettopology.
MasterMonitor是一个用于配置、调试和保存xml配置文件的图形化工具,可以查看从站、对象、变量和对比拓扑文件。
Closingamaster关闭主站
Tocloseamasterandfreeallitsresourcesthefunction
KS_closeEcatMastermustbeused.
使用KS_closeEcatMaster关闭从站
Statechangeforamaster主站的状态切换
Toqueryandchangethemaster'sstatethefunctions
KS_queryEcatMasterStateandKS_changeEcatStatecanbeused.
用KS_queryEcatMasterState查询主站状态。
用KS_changeEcatState改变主站状态。
ThefunctionKS_queryEcatMasterStateneedsamasterhandle,apointertothestructureKSEcatMasterStateandflags.BesuretoinitializethestructurememberstructSizetotheactualsizeofthestructureKSEcatMasterStatebeforecallingthefunction.
ThefunctionKS_changeEcatStateneedsamasterhandle,therequestedstateandflagsasparameters.Thestateofallassignedslaveswhichareonlineischanged.SlavesareassignedusingthefunctionKS_createEcatSlaveorKS_createEcatSlaveIndirect.
NearlyeveryEtherCATAPIfunctionhasspecialrequirementsregardingthestate(seetheAPIdocumentationofthespecificfunction).Forfurtherinformationaboutthestatemachinesee
TheEtherCATstatemachine.
几乎每一个EtherCAT的API函数都需要主站在特定的状态才能使用。
Slaverelatedfunctions从站相关函数
Enumeratingallonlineslaves枚举所有在线从站
Afteramasterwascreated,allonlineslavescanbeenumeratedusingthefunctionKS_enumEcatSlaves.Asparametersamasterhandle,aenumerationindexandapointertothestructure
KSEcatSlaveStateareneeded.BesuretoinitializethestructurememberstructSizetotheactualsizeofthe
structureKSEcatSlaveStatebeforecallingthefunction.
站.需要的参数包括主站句柄、枚举顺序、
KSEcatSlaveState结构体的指针。
在使用前应当初始化结构体的成员变量structSize大小。
Iftheenumerationindexisgreaterthanthenumberofonlineslaves,theerrorcodeKSERROR_DEVICE_NOT_FOUNDisreturned.Otherwise,apointertothestructureKSEcatSlaveStateisreturnedwhichcontainsinformationabouttheslave'sstate.
UsingthefunctionKS_enumEcatSlavestheslavesareenumeratedbytheirabsoluteposition.
Creatingaslave创建从站
Tocreateaslave,oneofthefunctions
KS_createEcatSlaveIndirectorKS_createEcatSlavecanbeused.
ThefunctionKS_createEcatSlaveIndirectmakesuseofthestructureKSEcatSlaveStatewhichcanbeobtainedusingthefunctionKS_enumEcatSlaves.
ThefunctionKS_createEcatSlaveneedsadditionalparameterslikeslaveid,position,vendoridandrevisionnumber.Withtheparameterslaveidarelativepositioncanbeprovided,too.
Theparametersareuniquetoaslavetype.Thisinformationcanbefoundintheslave'smanual,usingthemethodabovewiththestructureKSEcatSlaveStateorcanbedisplayedwiththe
Kithara?
MasterMonitor?
.
Ifaslaveisalreadyassignedandthefunction
KS_createEcatSlaveiscalledwiththesamevendorID,product
ID,revisionnumberandposition,anerror
KSERROR_DEVICE_ALREADY_USEDisreturnedtogetherwithaslavehandletothealreadyassignedslave.
AslavecanbedeletedusingthefunctionKS_deleteEcatSlave.
Gettinginformationfromslaves获取从站信息
Toqueryinformationfromaslavethefunction
KS_queryEcatSlaveInfocanbeused.ItdeliversapointertothestructureKSEcatSlaveInfo.Ifinformationaboutprocessdataobjects(PDO),servicedataobjects(SDO)orbothareneeded,theflagsKSF_SDOandKSF_PDOcanbepassedtothefunction.Thefunctionistimeconsuming(upto30seconds)andthestatePREOPorhigherisneededforonlineslaves.
WithinthestructureKSEcatSlaveInfothereisanarrayof
KSEcatDataObjInfoandwithinthisstructurethereisanarrayof
KSEcatDataVarInfo.
IfusinglanguageslikeC#thesestructuredcannotbeaccessed.
Alternatively,thefunctionsKS_queryEcatDataObjInfo,
KS_queryEcatDataVarInfo,KS_enumEcatDataObjInfoandKS_enumEcatDataVarInfocanbeusedinstead.
Statechangesforslaves从站状态机改变,与主站类似
Toqueryandchangetheslave'sstatethefunctions
KS_queryEcatSlaveStateandKS_changeEcatStatecanbeused.
查询和改变从站状态可以用以上两个函数,改变状态的函数与改变主站的相同
ThefunctionKS_queryEcatSlaveStateneedsaslavehandle,apointertothestructureKSEcatSlaveStateandflags.BesuretoinitializethestructurememberstructSizetotheactualsizeofthestructureKSEcatSlaveStatebeforecallingthefunction.
查询从站状态函数,需要一个从站句柄、指向
KSEcatSlaveState结构体的指针和标志位。
使用前请初始化结构体内部的structSize变量。
ForfurtherinformationconcerningthestatemachineseeThe
EtherCATstatemachine.
更多的信息可以查看此章节
Otheroperationsonslaves从站的其他操作
UsingthefunctionKS_writeEcatSlaveIditispossibletowriteauniqueIDtoanyslave.TheIDiswrittentonon-volatilememoryandwillbepersistent.WithinaconnectedrealtopologytheIDsmustbeunique.MindthattheslavemustbeinINITstate.
使用KSwriteEcatSlaveld函数可以给从站写入唯一的ID°ID
必须是唯一的,注意此时从站的状态必须是INIT
DatasetrelatedfunctionsDataset相关函数
Adatasetisacollectionofsyncmanagers,asyncmanagercancontainseveralPDOs(processdataobjects)andaPDOcanbemappedtomultipleSDO(servicedataobject)variables.Asyncmanagerisaslaveinternalmechanismtokeepdataconsistent.
个PDO可以映射多个SDO。
Itisnecessarytocreateatleastonedatasettoestablishtheprocessdataexchange.Dataiscyclicallytransferredbetweenthemasterandtheslaves.
建立过程数据通信至少需要一个dataset数据是在主站和从
站之间循环传送的。
Creatingandassigningadataset创建和分配一个dataset
TopreparetheprocessdataexchangeadatasetcanbecreatedwiththefunctionKS_createEcatDataSet.Asparametersamasterhandleisneeded.Optionalparametersareanapplicationandasystempointertoaccesssharedmemoryofthedatasetdirectly.Iftheprogramwascalledfromring3thentheapplicationpointercanbeusedandonring0thesystempointer.
Beforetheprocessdataexchangestarts,aPDOshouldbeassignedusingthefunctionKS_assignEcatDataSet.Asparametersadatasethandle,aslavehandle,anindexofasyncmanagerandaplacementisneeded.
在数据交互之前,应该分配PDO给sync管理器,使用
KS_assignEcatDataSet。
需要输入dataset句柄,从站句柄,sync
管理器序号
Aslavecanhaveseveralsyncmanagers.Thereare
readable/writeablesyncmanagersandsyncmanagersforthemailbox(ifexisting).Asyncmanagercontainsoneoremore
PDOs.Itispossibletoselectaspecificsyncmanagerwiththeindexparameterorselectgroupsofsyncmanagers(e.g.with
KS_ECAT_SYNC_ALL,KS_ECAT_SYNC_INPUT).
个从站可以有多个sync管理器。
有可读写sync和邮箱式
sync。
个sync拥有一个或多个PDO。
通过index参数,可以选择一个或一组特定的sync管理器
Severalobjectscanbeassignedtoadatasetwhileno
KSERROR_NOT_ENOUGH_MEMORYisreturned.Perdefaultadatasethasasizeof4KBandcanhaveupto64KB.
MindthattheassignedslavemustbeinstatePREOP.Withtheparameterplacementanoffsetcanbespecifiedwhileassigningseveralobjects.
个dataset可以被分配多个对象,默认的dataset大小为4kb,
最大为64kb。
操作时的从站必须位于PREOP状态。
Placement
参数可以指定一个对象在pdo中的位置。
Itisfurtherpossibletocreatemorethanonedataset.WithmultipledatasetseachonecanbeupdatedwithdifferentfrequenciesorgroupPDOswithmultipledatasetstologicalunits.
也可以创建多个dataset多个dataset中,每一个dataset可以被更新不同频率和不同组PDO更新。
Deletingadataset删除dataset
Todeleteadatasetandfreeallitsresourcesthefunction
KS_deleteEcatDataSetmustbeused.
Postingandreadingprocessdata发送和读取pdo数据
TopostandreadprocessdatathefunctionsKS_postEcatDataSetandKS_readEcatDataSetcanbeused.
Theprocessdataexchangediscontrolledbytheuser.Sothesefunctionsshouldbeplacedinsideofatimercallbackoradatasethandlertoensureanupdateoftheprocessdataexchangeinreal-time.Bothfunctionsneedadatasethandleasparameter.
ThefunctionKS_postEcatDataSethastobecalledbeforethefunctionKS_readEcatDataSe
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- EtherCAT 入门教程