Added ecrt_master_slave().

This commit is contained in:
Florian Pose 2009-01-26 14:39:49 +00:00
parent 8c76942245
commit ae9d759622
4 changed files with 103 additions and 18 deletions

1
NEWS
View File

@ -22,6 +22,7 @@ Changes since 1.4.0:
* Implemented the File Access over EtherCAT (FoE) mailbox protocol.
* Going to the Bootstrap state is now supported by the state machines and the
command-line tool.
* Introduced ecrt_master_slave() to get information about a certain slave.
Changes in 1.4.0:

1
TODO
View File

@ -24,6 +24,7 @@ Version 1.5.0:
* C++ implementation of the library.
* Distributed clocks.
* Bus simulator interface.
* Implement ecrt_master_slave() in kernel space.
Future issues:

View File

@ -1,27 +1,27 @@
/******************************************************************************
*
* $Id$
* $Id$
*
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
*
* This file is part of the IgH EtherCAT master userspace library.
*
* The IgH EtherCAT master userspace library is free software; you can
* redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; version 2.1 of
* the License.
* This file is part of the IgH EtherCAT master userspace library.
*
* The IgH EtherCAT master userspace library is free software; you can
* redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; version 2.1
* of the License.
*
* The IgH EtherCAT master userspace library is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* The IgH EtherCAT master userspace library is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the IgH EtherCAT master userspace library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Using the EtherCAT technology and brand is permitted in compliance with the
* industrial property and similar rights of Beckhoff Automation GmbH.
* You should have received a copy of the GNU Lesser General Public License
* along with the IgH EtherCAT master userspace library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Using the EtherCAT technology and brand is permitted in compliance with
* the industrial property and similar rights of Beckhoff Automation GmbH.
*
*****************************************************************************/
@ -40,6 +40,11 @@
*
* - Changed the meaning of the negative return values of
* ecrt_slave_config_reg_pdo_entry() and ecrt_slave_config_sdo*().
* - Imlemented the Vendor-specific over EtherCAT mailbox protocol. See
* ecrt_slave_config_create_voe_handler().
* - Renamed ec_sdo_request_state_t to ec_request_state_t, because it is also
* used by VoE handlers.
* - Added ecrt_master_slave() to get information about a certain slave.
*
* Changes in Version 1.4:
*
@ -134,6 +139,12 @@
*/
#define EC_MAX_SYNC_MANAGERS 16
/** Maximum string length.
*
* Used in ec_slave_info_t.
*/
#define EC_MAX_STRING_LENGTH 64
/******************************************************************************
* Data types
*****************************************************************************/
@ -199,6 +210,29 @@ typedef struct {
/*****************************************************************************/
/** Slave information.
*
* This is used as an output parameter of ecrt_master_slave().
*
* \see ecrt_master_slave().
*/
typedef struct {
uint16_t position; /**< Offset of the slave in the ring. */
uint32_t vendor_id; /**< Vendor-ID stored on the slave. */
uint32_t product_code; /**< Product-Code stored on the slave. */
uint32_t revision_number; /**< Revision-Number stored on the slave. */
uint32_t serial_number; /**< Serial-Number stored on the slave. */
uint16_t alias; /**< The slaves alias if not equal to 0. */
int16_t current_on_ebus;
uint8_t al_state; /**< Current state of the slave. */
uint8_t error_flag; /**< Error flag for that slave. */
uint8_t sync_count; /**< Number of sync managers. */
uint16_t sdo_count; /**< Number of SDO's. */
char name[EC_MAX_STRING_LENGTH]; /**< Name of the slave. */
} ec_slave_info_t;
/*****************************************************************************/
/** Domain working counter interpretation.
*
* This is used in ec_domain_state_t.
@ -433,6 +467,23 @@ ec_slave_config_t *ecrt_master_slave_config(
uint32_t product_code /**< Expected product code. */
);
/** 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_slave(
ec_master_t *master, /**< EtherCAT master */
uint16_t position, /**< Slave position. */
ec_slave_info_t *slave_info /**< Structure that will output the
information */
);
/** Finishes the configuration phase and prepares for cyclic operation.
*
* This function tells the master that the configuration phase is finished and

View File

@ -100,6 +100,38 @@ ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master,
/*****************************************************************************/
int ecrt_master_slave(ec_master_t *master, uint16_t position,
ec_slave_info_t *slave_info)
{
ec_ioctl_slave_t data;
int index;
data.position = position;
if (ioctl(master->fd, EC_IOCTL_SLAVE, &data) == -1) {
fprintf(stderr, "Failed to get slave info: %s\n",
strerror(errno));
return -1;
}
slave_info->position = data.position;
slave_info->vendor_id = data.vendor_id;
slave_info->product_code = data.product_code;
slave_info->revision_number = data.revision_number;
slave_info->serial_number = data.serial_number;
slave_info->alias = data.alias;
slave_info->current_on_ebus = data.current_on_ebus;
slave_info->al_state = data.al_state;
slave_info->error_flag = data.error_flag;
slave_info->sync_count = data.sync_count;
slave_info->sdo_count = data.sdo_count;
strncpy(slave_info->name, data.name, EC_IOCTL_STRING_SIZE);
return 0;
}
/*****************************************************************************/
int ecrt_master_activate(ec_master_t *master)
{
if (ioctl(master->fd, EC_IOCTL_ACTIVATE,