EtherCAT入门教程Word下载.docx

上传人:b****6 文档编号:20698091 上传时间:2023-01-25 格式:DOCX 页数:8 大小:21.23KB
下载 相关 举报
EtherCAT入门教程Word下载.docx_第1页
第1页 / 共8页
EtherCAT入门教程Word下载.docx_第2页
第2页 / 共8页
EtherCAT入门教程Word下载.docx_第3页
第3页 / 共8页
EtherCAT入门教程Word下载.docx_第4页
第4页 / 共8页
EtherCAT入门教程Word下载.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

EtherCAT入门教程Word下载.docx

《EtherCAT入门教程Word下载.docx》由会员分享,可在线阅读,更多相关《EtherCAT入门教程Word下载.docx(8页珍藏版)》请在冰豆网上搜索。

EtherCAT入门教程Word下载.docx

MindthatthefunctionKS_openAdaptermustbecalledwiththeflagKSF_REALTIME_EXEC.

使用KS_openAdapter时需要将标志位flag设置为KSF_REALTIME_EXEC,表明网卡运行在实时模式。

ksError=KS_enumDevices(//枚举设备

"

NET"

//Searchesfornetworkdevices

deviceIndex,//Count,startingwithzero

pDeviceName,//Bufferfordevicename

0);

//Flags

if(ksError)

//...ksError=KS_openAdapter(//打开网卡

&

amp;

hAdapter,//Adapterhandlepointer

pDeviceName,//HardwareIDoftheController

256,//ReceivePoolLength

256,//SendPoolLength

KSF_REALTIME_EXEC);

//...ForfurtherdetailsseeHowtolookupfordevices.

Creatingamaster----创建主站

TocreateamasterthefunctionKS_createEcatMastercanbeused.AsparametersanetworkadapterhandleandapathtodevicedescriptionXMLfilesareneeded.Anameofatopologyfile(*.ktp)isoptional.ThedevicedescriptionXMLfilescanbefoundwithadeveloperinstallationintheXMLdirectoryorcanbedownloadedfromtheslavemanufacturerwebsite.AtopologyfilecanbecreatedwiththeKithara?

MasterMonitor?

.

使用KS_createEcatMaster创建主站,需要传入网卡句柄参数和从站XML设备描述文件路径,也可以加入一个拓扑文件ktp参数。

设备描述文件可以从设备制造商的网站上获取。

拓扑文件可以用MasterMonitor生成。

TheKithara?

isatoolfore.g.configuration,diagnosticsandsavingXMLconfigurationfilesforgraphicallyviewingslaves,objectsandvariablesorcomparingagiventopologywithatargettopology.

MasterMonitor是一个用于配置、调试和保存xml配置文件的图形化工具,可以查看从站、对象、变量和对比拓扑文件。

Closingamaster----关闭主站

TocloseamasterandfreeallitsresourcesthefunctionKS_closeEcatMastermustbeused.

使用KS_closeEcatMaster关闭从站

Statechangeforamaster----主站的状态切换

Toqueryandchangethemaster'

sstatethefunctionsKS_queryEcatMasterStateandKS_changeEcatStatecanbeused.

用KS_queryEcatMasterState查询主站状态。

用KS_changeEcatState改变主站状态。

ThefunctionKS_queryEcatMasterStateneedsamasterhandle,apointertothestructureKSEcatMasterStateandflags.BesuretoinitializethestructurememberstructSizetotheactualsizeofthestructureKSEcatMasterStatebeforecallingthefunction.

ThefunctionKS_changeEcatStateneedsamasterhandle,therequestedstateandflagsasparameters.Thestateofallassignedslaveswhichareonlineischanged.SlavesareassignedusingthefunctionKS_createEcatSlaveorKS_createEcatSlaveIndirect.

NearlyeveryEtherCATAPIfunctionhasspecialrequirementsregardingthestate(seetheAPIdocumentationofthespecificfunction).ForfurtherinformationaboutthestatemachineseeTheEtherCATstatemachine.

几乎每一个EtherCAT的API函数都需要主站在特定的状态才能使用。

Slaverelatedfunctions----从站相关函数

Enumeratingallonlineslaves----枚举所有在线从站

Afteramasterwascreated,allonlineslavescanbeenumeratedusingthefunctionKS_enumEcatSlaves.Asparametersamasterhandle,aenumerationindexandapointertothestructureKSEcatSlaveStateareneeded.BesuretoinitializethestructurememberstructSizetotheactualsizeofthestructureKSEcatSlaveStatebeforecallingthefunction.

主站创建之后,则可以使用KS_enumEcatSlaves枚举所有从站.需要的参数包括主站句柄、枚举顺序、一个KSEcatSlaveState结构体的指针。

在使用前应当初始化结构体的成员变量structSize大小。

Iftheenumerationindexisgreaterthanthenumberofonlineslaves,theerrorcodeKSERROR_DEVICE_NOT_FOUNDisreturned.Otherwise,apointertothestructureKSEcatSlaveStateisreturnedwhichcontainsinformationabouttheslave'

sstate.

UsingthefunctionKS_enumEcatSlavestheslavesareenumeratedbytheirabsoluteposition.

Creatingaslave----创建从站

Tocreateaslave,oneofthefunctionsKS_createEcatSlaveIndirectorKS_createEcatSlavecanbeused.ThefunctionKS_createEcatSlaveIndirectmakesuseofthestructureKSEcatSlaveStatewhichcanbeobtainedusingthefunctionKS_enumEcatSlaves.

ThefunctionKS_createEcatSlaveneedsadditionalparameterslikeslaveid,position,vendoridandrevisionnumber.Withtheparameterslaveidarelativepositioncanbeprovided,too.

Theparametersareuniquetoaslavetype.Thisinformationcanbefoundintheslave'

smanual,usingthemethodabovewiththestructureKSEcatSlaveStateorcanbedisplayedwiththeKithara?

IfaslaveisalreadyassignedandthefunctionKS_createEcatSlaveiscalledwiththesamevendorID,productID,revisionnumberandposition,anerrorKSERROR_DEVICE_ALREADY_USEDisreturnedtogetherwithaslavehandletothealreadyassignedslave.

Deletingaslave----删除从站

AslavecanbedeletedusingthefunctionKS_deleteEcatSlave.

Gettinginformationfromslaves----获取从站信息

ToqueryinformationfromaslavethefunctionKS_queryEcatSlaveInfocanbeused.ItdeliversapointertothestructureKSEcatSlaveInfo.Ifinformationaboutprocessdataobjects(PDO),servicedataobjects(SDO)orbothareneeded,theflagsKSF_SDOandKSF_PDOcanbepassedtothefunction.Thefunctionistimeconsuming(upto30seconds)andthestatePREOPorhigherisneededforonlineslaves.

WithinthestructureKSEcatSlaveInfothereisanarrayofKSEcatDataObjInfoandwithinthisstructurethereisanarrayofKSEcatDataVarInfo.

IfusinglanguageslikeC#thesestructuredcannotbeaccessed.Alternatively,thefunctionsKS_queryEcatDataObjInfo,KS_queryEcatDataVarInfo,KS_enumEcatDataObjInfoandKS_enumEcatDataVarInfocanbeusedinstead.

Statechangesforslaves----从站状态机改变,与主站类似

Toqueryandchangetheslave'

sstatethefunctionsKS_queryEcatSlaveStateandKS_changeEcatStatecanbeused.

查询和改变从站状态可以用以上两个函数,改变状态的函数与改变主站的相同

ThefunctionKS_queryEcatSlaveStateneedsaslavehandle,apointertothestructureKSEcatSlaveStateandflags.BesuretoinitializethestructurememberstructSizetotheactualsizeofthestructureKSEcatSlaveStatebeforecallingthefunction.

查询从站状态函数,需要一个从站句柄、指向KSEcatSlaveState结构体的指针和标志位。

使用前请初始化结构体内部的structSize变量。

ForfurtherinformationconcerningthestatemachineseeTheEtherCATstatemachine.

更多的信息可以查看此章节

Otheroperationsonslaves----从站的其他操作

UsingthefunctionKS_writeEcatSlaveIditispossibletowriteauniqueIDtoanyslave.TheIDiswrittentonon-volatilememoryandwillbepersistent.WithinaconnectedrealtopologytheIDsmustbeunique.MindthattheslavemustbeinINITstate.

使用KS_writeEcatSlaveId函数可以给从站写入唯一的ID。

ID必须是唯一的,注意此时从站的状态必须是INIT

Datasetrelatedfunctions----Dataset相关函数

Adatasetisacollectionofsyncmanagers,asyncmanagercancontainseveralPDOs(processdataobjects)andaPDOcanbemappedtomultipleSDO(servicedataobject)variables.Asyncmanagerisaslaveinternalmechanismtokeepdataconsistent.

dataset是同步管理器的一个数据收集,可以包含多个PDO,一个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.Therearereadable/writeablesyncmanagersandsyncmanagersforthemailbox(ifexisting).AsyncmanagercontainsoneoremorePDOs.Itispossibletoselectaspecificsyncmanagerwiththeindexparameterorselectgroupsofsyncmanagers(e.g.withKS_ECAT_SYNC_ALL,KS_ECAT_SYNC_INPUT).

一个从站可以有多个sync管理器。

有可读写sync和邮箱式sync。

一个sync拥有一个或多个PDO。

通过index参数,可以选择一个或一组特定的sync管理器

SeveralobjectscanbeassignedtoadatasetwhilenoKSERROR_NOT_ENOUGH_MEMORYisreturned.Perdefaultadatasethasasizeof4KBandcanhaveupto64KB.MindthattheassignedslavemustbeinstatePREOP.Withtheparameterplacementanoffsetcanbespecifiedwhileassigningseveralobjects.

一个dataset可以被分配多个对象,默认的dataset大小为4kb,最大为64kb。

操作时的从站必须位于PREOP状态。

placement参数可以指定一个对象在pdo中的位置。

Itisfurtherpossibletocreatemorethanonedataset.WithmultipledatasetseachonecanbeupdatedwithdifferentfrequenciesorgroupPDOswithmultipledatasetstologicalunits.

也可以创建多个dataset。

多个dataset中,每一个dataset可以被更新不同频率和不同组PDO更新。

Deletingadataset----删除dataset

TodeleteadatasetandfreeallitsresourcesthefunctionKS_deleteEcatDataSetmustbeused.

Postingandreadingprocessdata----发送和读取pdo数据

TopostandreadprocessdatathefunctionsKS_postEcatDataSetandKS_readEcatDataSetcanbeused.

Theprocess

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 职业教育 > 中职中专

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1