关键词不能为空

当前您在: 主页 > 英语 >

EtherCAT入门教程

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-06 07:04
tags:

-

2021年2月6日发(作者:宝剑锋)


EtherCAT


入门教程








本文翻译了


kithara


官方文档,


也加入了一些理解,


暂时

< p>
做得还不够完美,后续补充修正。


2014.06.06


EtherCAT


This tutorial describes the following topics using the EtherCAT


API


本向导描述了使用


EtherCAT API


的功能说明


Creating a


EtherCAT master assigned to a network adapterCreating slaves


assigned to the masterReal-time process data exchange with


datasets and assigned PDOsReal-time up/download of service


data objects (SDO)Real-time mailbox communicationState


control for master and slavesGetting information for master,


slaves, data objects, variable objects


中文说明创建

< br>EtherCAT



站使用的网卡创建连接主站的从站使 用


dataset



PDO

< p>
进行


实时过程数据交互


Master related functions----


主站相关功能



Opening a network adapter----


打开网卡



Before we can create a master, it is necessary to open a network


adapter first. This is done by using the function


KS_openAdapter. As parameters an adapter name, a receive and


a send pool size is needed. The adapter name is usually the name


of a network device. The function KS_enumDevices enumerates


all devices. To only get network devices the parameter


deviceType is set to “NET”.



在创建主站之前,


必须打开网卡。


使用


KS_openAdapter


函数


打 开网卡,需要的参数包括网卡名称,收发数据池大小等。


可以使用


KS_enumDevices


枚举设备获取网卡名称,使用该


函数时参数


deviceType


应该设置为“


NET




Mind that the function KS_openAdapter must be called with the


flag KSF_REALTIME_EXEC.


使用


KS_openAdapter


时需要将标志位


flag


设置为


KSF_REALTI ME_EXEC



表明网卡运行在实时模式。

< br>ksError


= KS_enumDevices(



//


枚举设备





















// Searches for network devices














deviceIndex,













// Count, starting with


zero














pDeviceName,













// Buffer for device


name














0);






















// Flags


if (ksError)



// ...ksError = KS_openAdapter(



//


打开网卡















&hAdapter,















// Adapter


handle pointer














pDeviceName,













// Hardware ID of


the Controller














256,





















// Receive Pool


Length














256,





















// Send Pool Length














KSF_REALTIME_EXEC);






// Flags


if (ksError)



// ...For further details see How to look up for devices.


Creating a master----


创建主站



To create a master the function KS_createEcatMaster can be


used. As parameters a network adapter handle and a path to


device description XML files are needed. A name of a topology


file (*.ktp) is optional. The device description XML files can be


found with a developer installation in the XML directory or can


be downloaded from the slave manufacturer website. A topology


file can be created with the Kithara ?Master Monitor?.


使用


KS_creat eEcatMaster


创建主站,


需要传入网卡句柄参数


和从站


XML


设备描述文件路径,也可以加 入一个拓扑文件


ktp


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


拓扑文件可以用


Master Monitor


生成。



The Kithara ?Master Monitor? is a tool for e.g. configuration,


diagnostics and saving XML configuration files for graphically


viewing slaves, objects and variables or comparing a given


topology with a target topology.


Master Monitor

< br>是一个用于配置、调试和保存


xml


配置文件

< p>
的图形化工具,


可以查看从站、


对象、

< p>
变量和对比拓扑文件。



Closing a master----


关闭主站



To close a master and free all its resources the function


KS_closeEcatMaster must be used.


使用


KS_closeEcatMaster


关闭从站



State change for a master----


主站的状态切换



To query and change the master's state the functions


KS_queryEcatMasterState and KS_changeEcatStatecan be used.



KS_queryEcatMasterState


查询主站状态。< /p>




KS_changeEcatSta te


改变主站状态。



The function KS_queryEcatMasterState needs a master handle,


a pointer to the structureKSEcatMasterState and flags. Be sure


to initialize the structure member structSize to the actual size of


the structure KSEcatMasterState before calling the function.




The function KS_changeEcatState needs a master handle, the


requested state and flags as parameters. The state of all assigned


slaves which are online is changed. Slaves are assigned using


the functionKS_createEcatSlave or KS_createEcatSlaveIndirect.




Nearly every EtherCAT API function has special requirements


regarding the state (see the APIdocumentation of the specific


function). For further information about the state machine see


The EtherCAT state machine.


几乎每一个


EtherCAT



API


函数都需 要主站在特定的状态


才能使用。



Slave related functions----


从站相关函数



Enumerating all online slaves----


枚举所有在线从站



After a master was created, all online slaves can be enumerated


using the function KS_enumEcatSlaves. As parameters a master


handle, a enumeration index and a pointer to the structure


KSEcatSlaveState are needed. Be sure to initialize the structure


member structSize to the actual size of the


structureKSEcatSlaveState before calling the function.


主站创建之后,则可以使用

< p>
KS_enumEcatSlaves


枚举所有从



.


需要的参数包括主站句柄、枚举顺序、一个


KSEcatSlaveState


结构体的指针。在使用前应当初始化结构< /p>


体的成员变量


structSize


大小 。



If the enumeration index is greater than the number of online


slaves, the error codeKSERROR_DEVICE_NOT_FOUND is


returned. Otherwise, a pointer to the structure KSEcatSlaveState


is returned which contains information about the slave's state.




Using the function KS_enumEcatSlaves the slaves are


enumerated by their absolute position.


Creating a slave----


创建从站



To create a slave, one of the functions


KS_createEcatSlaveIndirect or KS_createEcatSlave can be used.


The function KS_createEcatSlaveIndirect makes use of the


structure KSEcatSlaveState which can be obtained using the


function KS_enumEcatSlaves.


The function KS_createEcatSlave needs additional parameters


like slave id, position, vendor id and revision number. With the


parameter slave id a relative position can be provided, too.


The parameters are unique to a slave type. This information can


be found in the slave's manual, using the method above with the


structure KSEcatSlaveState or can be displayed with the


Kithara ?Master Monitor?.


If a slave is already assigned and the function


KS_createEcatSlave is called with the same vendor ID, product


ID, revision number and position, an error


KSERROR_DEVICE_ALREADY_USED is returned together


with a slave handle to the already assigned slave.


Deleting a slave----


删除从站



A slave can be deleted using the function KS_deleteEcatSlave.


Getting information from slaves----


获取从站信息



To query information from a slave the function


KS_queryEcatSlaveInfo can be used. It delivers a pointer to the


structure KSEcatSlaveInfo. If information about process data


objects (PDO), service data objects (SDO) or both are needed,


the flags KSF_SDO and KSF_PDO can be passed to the


function. The function is time consuming (up to 30 seconds) and


the state PREOP or higher is needed for online slaves.


Within the structure KSEcatSlaveInfo there is an array of


KSEcatDataObjInfo and within this structure there is an array of


KSEcatDataVarInfo.


If using languages like C# these structured cannot be accessed.


Alternatively, the functionsKS_queryEcatDataObjInfo,


KS_queryEcatDataVarInfo, KS_enumEcatDataObjInfo


andKS_enumEcatDataVarInfo can be used instead.


State changes for slaves----


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



To query and change the slave's state the functions


KS_queryEcatSlaveState and KS_changeEcatState can be used.


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


与改变主站的相同

< br>


The function KS_queryEcatSlaveState needs a slave handle, a


pointer to the structure KSEcatSlaveStateand flags. Be sure to


initialize the structure member structSize to the actual size of the


structureKSEcatSlaveState before calling the function.


查询从站状态函数,需要一个从站句柄 、指向


KSEcatSlaveState


结构体的指针和标志 位。使用前请初始化


结构体内部的


structSize


变量。



For further information concerning the state machine see The


EtherCAT state machine.


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



Other operations on slaves----


从站的其他操作



Using the function KS_writeEcatSlaveId it is possible to write a


unique ID to any slave. The ID is written to non-volatile


memory and will be persistent. Within a connected real topology


the IDs must be unique. Mind that the slave must be in INIT


state.


使用


KS_write EcatSlaveId


函数可以给从站写入唯一的


ID



ID


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


INIT


Dataset related functions----Dataset


相关函数



A dataset is a collection of sync managers, a sync manager can


contain several PDOs (process data objects) and a PDO can be


mapped to multiple SDO (service data object) variables. A sync


manager is a slave internal mechanism to keep data consistent.

-


-


-


-


-


-


-


-



本文更新与2021-02-06 07:04,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/606256.html

EtherCAT入门教程的相关文章