当前位置:   article > 正文

EtherCAT igh函数尝试_ecslavelifeinfo

ecslavelifeinfo

尝试igh函数的功能,加深对不同函数的认识,总结相关函数的用法。

1.ecrt_master_get_slave

/** Obtains slave information.
 *
 * Tries to find the slave with the given ring position. The obtained
 * information is stored in a structure. No memory is allocated on the heap in
 * this function.
 *
 * \attention The pointer to this structure must point to a valid variable.
 *
 * \return 0 in case of success, else < 0
 */
int ecrt_master_get_slave(
        ec_master_t *master, /**< EtherCAT master */
        uint16_t slave_position, /**< Slave position. */
        ec_slave_info_t *slave_info /**< Structure that will output the
                                      information */
        );
        
//example----------------------------------------------------------------------
typedef struct {
    unsigned short  position;
    unsigned int    vendor_id;
    unsigned int    product_code;
}EL_Slave_t;

int  GetSlavesInfo(EL_Slave_t* slaves, int num)
{
    ec_master_t* master = ecrt_request_master(0);
    ec_slave_info_t  tmps;
    int  i;
    for(i = 0;i< num;i++)
    {
        if(ecrt_master_get_slave(master, i, &tmps) == 0)
        {
            (slaves + i)->position = tmps.position;
            (slaves + i)->vendor_id = tmps.vendor_id;
            (slaves + i)->product_code = tmps.product_code;
            printf("slave position:%d,vendor_id:%d,product_code:%d,name:%s\n",
                   tmps.position, tmps.vendor_id, tmps.product_code, tmps.name);
        }
        else
            break;
    }
    ecrt_release_master(master);
    return i;
}

int main(int argc, char *argv[])
{
	...
    EL_Slave_t  slaves[16];
    int num = GetSlavesInfo(slaves, 16);
    printf("num = %d\n",num);
    ...
}

//测试结果、终端输出
slave position:0,vendor_id:9,product_code:37458,name:LAN9252-EVB-HBI
slave position:1,vendor_id:2,product_code:72100946,name:EK1100 EtherCAT-Koppler (2A E-Bus)
slave position:2,vendor_id:2,product_code:131608658,name:EL2008 8K. Dig. Ausgang 24V, 0.5A
slave position:3,vendor_id:2,product_code:131608658,name:EL2008 8K. Dig. Ausgang 24V, 0.5A
slave position:4,vendor_id:2,product_code:131608658,name:EL2008 8K. Dig. Ausgang 24V, 0.5A
num = 5
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
  

闽ICP备14008679号