EtherCAT主站SOEM函数详解---- ecx_readstate、ecx_writestate

EtherCAT主站SOEM函数详解----状态读取函数

  • ecx_readstate
  • ecx_writestate

在控制驱动器等从站中,经常需要只知道从站的状态,在SOEM开发的主站中,如何读取从站的工作状态是非常重要的,本文将重点讲解SOEM中读取从站工作状态的函数。

ecx_readstate

该函数在ethercatmain.h文件中,用于读取从站的状态

/** Read all slave states in ec_slave.
 * @param[in] context = context struct
 * @return lowest state found
 */
int ecx_readstate(ecx_contextt *context);

实现代码如下所示:

/** Read all slave states in ec_slave.
 * @param[in] context = context struct
 * @return lowest state found
 */
int ecx_readstate(ecx_contextt *context)
{
   
   uint16 slave, fslave, lslave, configadr, lowest, rval, bitwisestate;
   ec_alstatust sl[MAX_FPRD_MULTI];
   uint16 slca[MAX_FPRD_MULTI];
   boolean noerrorflag, allslavessamestate;
   boolean allslavespresent = FALSE;
   int wkc;

   /* Try to establish the state of all slaves sending only one broadcast datagram.
    * This way a number of datagrams equal to the number of slaves will be sent only if needed.*/
   rval = 0;
   wkc = ecx_BRD(context->port, 0, ECT_REG_ALSTAT, sizeof(rval), &rval, EC_TIMEOUTRET);

   if(wkc >= *(context->slavecount))
   {
   
      allslavespresent = TRUE;
   }

   rval = etohs(rval);
   bitwisestate = (rval & 0x0f);

   if (

你可能感兴趣的:(EtherCAT主站SOEM函数详解---- ecx_readstate、ecx_writestate)