[etherlab-users] Beckhoff 6731-0010 initialization

Gavin Lambert gavinl at compacsort.com
Sun Nov 1 22:59:12 CET 2015


Your strToCharArray function is corrupting memory by looping too many times – you loop up to the number of characters in the input array, but each loop reads two characters from the array.  You’re therefore writing twice as much data as you should be, and half of it is garbage.

 

You really shouldn’t have that sort of code anyway, since it’s all constant data in the first place.  Change the global definitions from a string to a byte array.

 

From: David Jiménez Mejías [mailto:david.jimenez at gtc.iac.es] 
Sent: Friday, 30 October 2015 23:13
To: Gavin Lambert <gavin.lambert at compacsort.com>; hm at igh-essen.com; etherlab-users at etherlab.org
Subject: RE: [etherlab-users] Beckhoff 6731-0010 initialization

 

Hi Gavin,

 

thanks for your answer.

I modified the user example from the EtherCAT Master.

With the actual code I get to be on pre-operational state the Phoenix Contact Can slave (it was on error before the SDO configuration).

The problem it's on the Can Master, it get into PREOP+ERROR when it's going to OP.

 

This is the main.c code that I'm using.

 

 

 


#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sched.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/mman.h>
#include <pthread.h>

/****************************************************************************/

#include "ecrt.h"

/****************************************************************************/

// Application parameters
#define FREQUENCY 10
#define PRIORITY 1

// Optional features
#define CONFIGURE_PDOS  1
#define SDO_ACCESS      0

/****************************************************************************/

// EtherCAT
static ec_master_t *master = NULL;
static ec_master_state_t master_state = {};

static ec_domain_t *domain1 = NULL;
static ec_domain_state_t domain1_state = {};

static ec_slave_config_t *sc_EL2602_dig_out = NULL;
static ec_slave_config_state_t sc_EL2602_dig_out_state = {};

static ec_slave_config_t *sc_EL2008_dig_out = NULL;
static ec_slave_config_state_t sc_EL2008_dig_out_state = {};

static ec_slave_config_t *sc_EL3202_ana_in = NULL;
static ec_slave_config_state_t sc_EL3202_ana_in_state = {};

static ec_slave_config_t *sc_EL6751_Canopen = NULL;
static ec_slave_config_state_t sc_EL6751_Canopen_state = {};


// CanOpen Master configuration.
// Got it from the StartUp SDO from TwinCAT

const char *pb_config_master_0x1C32=
    "0300010000093D0000000000";
const char *pb_config_master_0x1C33 =
    "030022000000000000000000";

const char *pb_config_master_0xf800 =
    "0A007F0380001E00010010006400";

const char *pb_config_master_0x8000 =
    "2B000700000000000000000000000000000000009101030084"
    "00000001000001000000000000000000000000000000000000"
    "00006400030000000000010178000A00";
const char *pb_config_master_0x8001 =
    "010001000000FF018701000000000018";

const char *pb_config_master_0x8002 =
    "010000000000FF040702000000000014";

const char *pb_config_master_0x8003 =
    "10000018010400870100000018020100FF0118010400870200"
    "000118020100FF0218010400870300000218020100FF031801"
    "0400870400000318020100FF00140104000702000000140201"
    "00FF0114010400070300000114020100FF0214010400070400"
    "000214020100FF0314010400070500000314020100FF";

/*----------------------*/


// Timer
static unsigned int sig_alarms = 0;
static unsigned int user_alarms = 0;

// User Application Vars
int num;
short niTemp = 0;
short nFlag = 0;
short nInit = 0;
static short nLimitMax = 320; 
static short nLimitMin = 300;

int nPT100_1 = 0;
int nPT100_2 = 0;


/****************************************************************************/

// process data
static uint8_t *domain1_pd = NULL;

// Posición de Elementos (Igual es preferible la designación por nombre de 
// terminal EK1100_Pos por ejemplo)

#define EK1100Pos 0, 0
#define EL2602Pos 0, 1
#define EL3202Pos 0, 2
#define EL2008Pos 0, 3
#define EL6751Pos 0, 4

// Definición de info del producto, VendorID y ProductNum
#define Beckhoff_EK1100 0x00000002, 0x044c2c52
#define Beckhoff_EL2602 0x00000002, 0x0a2a3052
#define Beckhoff_EL2008 0x00000002, 0x07d83052
#define Beckhoff_EL3202 0x00000002, 0x0c823052
#define Beckhoff_EL6751 0x00000002, 0x1a5f3052


// offsets for PDO entries
static unsigned int off_ana_in_value;
static unsigned int off_ana_in_status;
static unsigned int off_ana_in_value2;
static unsigned int off_ana_in_status2;
static unsigned int off_EL2602_dig_out;
static unsigned int off_EL2008_dig_out;
static unsigned int off_in_CanMaster;
static unsigned int off_out_CanMaster;

// Se identifican los PDOs correspondientes a cada elemento. La dirección
// del Indice es 0x7000, si es Output, o 0x6000 si es Input. Si existen más E/S
// se van situando en saltos de 10: 0x6010, 0x7010 etc ... El subindice 
// se localiza con un CSTRUCT pudiendo darse en Decimal o Hexadecimal
 
const static ec_pdo_entry_reg_t domain1_regs[] = {

    {EL2602Pos, Beckhoff_EL2602, 0x7000, 0x01, &off_EL2602_dig_out},
    {EL2008Pos, Beckhoff_EL2008, 0x7000, 0x01, &off_EL2008_dig_out},
    {EL3202Pos, Beckhoff_EL3202, 0x6000, 0x11, &off_ana_in_value},
    {EL3202Pos, Beckhoff_EL3202, 0x6010, 0x11, &off_ana_in_value2},
    {EL3202Pos, Beckhoff_EL3202, 0x6000, 0x01, &off_ana_in_status},
    {EL3202Pos, Beckhoff_EL3202, 0x6000, 0x01, &off_ana_in_status2},
    {EL6751Pos, Beckhoff_EL6751, 0x7000, 0x01, &off_out_CanMaster},
    {EL6751Pos, Beckhoff_EL6751, 0x6000, 0x01, &off_in_CanMaster},
    {}
};

static unsigned int counter = 0;

/*****************************************************************************/

#if CONFIGURE_PDOS

// Analog in --------------------------
/* Master 0, Slave 2, "EL3202-0010"
 * Vendor ID:       0x00000002
 * Product code:    0x0c823052
 * Revision number: 0x0014000a
 */

ec_pdo_entry_info_t slave_2_pdo_entries[] = {
    {0x6000, 0x01, 1}, /* Underrange */
    {0x6000, 0x02, 1}, /* Overrange */
    {0x6000, 0x03, 2}, /* Limit 1 */
    {0x6000, 0x05, 2}, /* Limit 2 */
    {0x6000, 0x07, 1}, /* Error */
    {0x0000, 0x00, 7}, /* Gap */
    {0x1800, 0x07, 1}, // TxPDO State
    {0x1800, 0x09, 1}, // TxPDO Toggle
    {0x6000, 0x11, 16}, /* Value */    // PT100 Sensor 1
    {0x6010, 0x01, 1}, /* Underrange */
    {0x6010, 0x02, 1}, /* Overrange */
    {0x6010, 0x03, 2}, /* Limit 1 */
    {0x6010, 0x05, 2}, /* Limit 2 */
    {0x6010, 0x07, 1}, /* Error */
    {0x0000, 0x00, 7}, /* Gap */
    {0x1801, 0x07, 1},
    {0x1801, 0x09, 1},
    {0x6010, 0x11, 16}, /* Value */    // PT100 Sensor 2
};

ec_pdo_info_t slave_2_pdos[] = {
    {0x1a00, 9, slave_2_pdo_entries + 0}, /* RTD TxPDO-Map Ch.1 */
    {0x1a01, 9, slave_2_pdo_entries + 9}, /* RTD TxPDO-Map Ch.2 */
};

ec_sync_info_t slave_2_syncs[] = {
    {0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
    {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
    {2, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
    {3, EC_DIR_INPUT, 2, slave_2_pdos + 0, EC_WD_DISABLE},
    {0xff}
};

// Analog out -------------------------

// Digital out ------------------------

/*****/
/* Master 0, Slave 1, "EL2602"
 * Vendor ID:       0x00000002
 * Product code:    0x0a2a3052
 * Revision number: 0x00120000
 */

ec_pdo_entry_info_t slave_1_pdo_entries[] = {
    {0x7000, 0x01, 1}, /* Output Fun and Valve*/
    {0x7010, 0x01, 1}, /* Output */
};

ec_pdo_info_t slave_1_pdos[] = {
    {0x1600, 1, slave_1_pdo_entries + 0}, /* Channel 1 */
    {0x1601, 1, slave_1_pdo_entries + 1}, /* Channel 2 */
};

ec_sync_info_t slave_1_syncs[] = {
    {0, EC_DIR_OUTPUT, 2, slave_1_pdos + 0, EC_WD_ENABLE},
    {0xff}
};

/* Master 0, Slave 3, "EL2008"
 * Vendor ID:       0x00000002
 * Product code:    0x07d83052
 * Revision number: 0x00110000
 */

ec_pdo_entry_info_t slave_3_pdo_entries[] = {
    {0x7000, 0x01, 1}, /* Output */
    {0x7010, 0x01, 1}, /* Output */
    {0x7020, 0x01, 1}, /* Output */    // Relay 1
    {0x7030, 0x01, 1}, /* Output */    // Relay 2
    {0x7040, 0x01, 1}, /* Output */    // Relay 3
    {0x7050, 0x01, 1}, /* Output */    // Relay 4
    {0x7060, 0x01, 1}, /* Output */    // Relay 5
    {0x7070, 0x01, 1}, /* Output */
};

ec_pdo_info_t slave_3_pdos[] = {
    {0x1600, 1, slave_3_pdo_entries + 0}, /* Channel 1 */
    {0x1601, 1, slave_3_pdo_entries + 1}, /* Channel 2 */
    {0x1602, 1, slave_3_pdo_entries + 2}, /* Channel 3 */
    {0x1603, 1, slave_3_pdo_entries + 3}, /* Channel 4 */
    {0x1604, 1, slave_3_pdo_entries + 4}, /* Channel 5 */
    {0x1605, 1, slave_3_pdo_entries + 5}, /* Channel 6 */
    {0x1606, 1, slave_3_pdo_entries + 6}, /* Channel 7 */
    {0x1607, 1, slave_3_pdo_entries + 7}, /* Channel 8 */
};

ec_sync_info_t slave_3_syncs[] = {
    {0, EC_DIR_OUTPUT, 8, slave_3_pdos + 0, EC_WD_ENABLE},
    {0xff}
};
// Comm Modules ----------------------------
/* Master 0, Slave 4, "EL6751"
 * Vendor ID:       0x00000002
 * Product code:    0x1a5f3052
 * Revision number: 0x00130000
 */
ec_pdo_entry_info_t slave_4_pdo_entries[] = {
  { 0x6000, 1, 8 },    /* 1 */
  { 0x7000, 1, 32 },   /* 0 */
  { 0xA000, 1, 8 },    /* 2 */
  { 0xA000, 2, 1 },    /* 2 */
  { 0xF100, 1, 8 },    /* 3 */
  { 0xF100, 2, 1 },    /* 3 */
  { 0xF100, 3, 16 },   /* 4 */
  { 0xF100, 5, 8 },    /* 5 */
  { 0xF100, 4, 8 },    /* 5 */
  { 0xA000, 2, 1 },    /* 6 */
/*  { 0x0000, 0, 6 },*/
};

ec_pdo_info_t slave_4_pdos[] = {
    {0x1a00, 1, slave_4_pdo_entries + 0}, /* DPS TxPDO-Map Slave     */
    {0x1600, 1, slave_4_pdo_entries + 1}, /* DPS RxPDO-Map Slave     */
    {0x1a80, 8, slave_4_pdo_entries + 2},
};

ec_sync_info_t slave_4_syncs[] = {
    {0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
    {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
    {2, EC_DIR_OUTPUT, 1, slave_4_pdos + 0, EC_WD_DISABLE},
    {3, EC_DIR_INPUT, 2, slave_4_pdos + 1, EC_WD_DISABLE},
    {0xff}
};

#endif

/*****************************************************************************/
/* Helper funktion, buffer has be allocated and big enough */
unsigned int strToCharArray(const char *str,unsigned char *buffer)
    {
        unsigned int i;
        unsigned char byteVal;
        //        const char *str = pb_config;
        //        unsigned char cf_data[256];
        size_t size = strlen(str);

        for (i = 0; i < size; i++) {
            sscanf(str, "%2X", &byteVal);
            str += 2;
            buffer[i] = (uint8_t) byteVal;
        }
        return (size / 2);
    }

/*****************************************************************************/
/*****************************************************************************/

#if SDO_ACCESS
static ec_sdo_request_t *sdo;
#endif

/*****************************************************************************/

void check_domain1_state(void)
{
    ec_domain_state_t ds;

    ecrt_domain_state(domain1, &ds);

    if (ds.working_counter != domain1_state.working_counter)
        printf("Domain1: WC %u.\n", ds.working_counter);
    if (ds.wc_state != domain1_state.wc_state)
        printf("Domain1: State %u.\n", ds.wc_state);

    domain1_state = ds;
}

/*****************************************************************************/

void check_master_state(void)
{
    ec_master_state_t ms;

    ecrt_master_state(master, &ms);

    if (ms.slaves_responding != master_state.slaves_responding)
        printf("%u slave(s).\n", ms.slaves_responding);
    if (ms.al_states != master_state.al_states)
        printf("AL states: 0x%02X.\n", ms.al_states);
    if (ms.link_up != master_state.link_up)
        printf("Link is %s.\n", ms.link_up ? "up" : "down");

    master_state = ms;
}

/*****************************************************************************/

void check_slave_config_states(void)
{
    ec_slave_config_state_t s;

    ecrt_slave_config_state(sc_EL3202_ana_in, &s);

    if (s.al_state != sc_EL3202_ana_in_state.al_state)
        printf("EL3202: State 0x%02X.\n", s.al_state);
    if (s.online != sc_EL3202_ana_in_state.online)
        printf("EL3202: %s.\n", s.online ? "online" : "offline");
    if (s.operational != sc_EL3202_ana_in_state.operational)
        printf("EL3202: %soperational.\n", s.operational ? "" : "Not ");

    sc_EL3202_ana_in_state = s;

    ecrt_slave_config_state(sc_EL2602_dig_out, &s);

    if (s.al_state != sc_EL2602_dig_out_state.al_state)
        printf("EL2602: State 0x%02X.\n", s.al_state);
    if (s.online != sc_EL2602_dig_out_state.online)
        printf("EL2602: %s.\n", s.online ? "online" : "offline");
    if (s.operational != sc_EL2602_dig_out_state.operational)
        printf("EL2602: %soperational.\n", s.operational ? "" : "Not ");

    sc_EL2602_dig_out_state = s;

    ecrt_slave_config_state(sc_EL2008_dig_out, &s);

    if (s.al_state != sc_EL2008_dig_out_state.al_state)
        printf("EL2008: State 0x%02X.\n", s.al_state);
    if (s.online != sc_EL2008_dig_out_state.online)
        printf("EL2008: %s.\n", s.online ? "online" : "offline");
    if (s.operational != sc_EL2008_dig_out_state.operational)
        printf("EL2008: %soperational.\n", s.operational ? "" : "Not ");

    sc_EL2008_dig_out_state = s;

    ecrt_slave_config_state(sc_EL6751_Canopen, &s);

    if (s.al_state != sc_EL6751_Canopen_state.al_state)
        printf("EL6751: State 0x%02X.\n", s.al_state);
    if (s.online != sc_EL6751_Canopen_state.online)
        printf("EL6751: %s.\n", s.online ? "online" : "offline");
    if (s.operational != sc_EL6751_Canopen_state.operational)
        printf("EL6751: %soperational.\n", s.operational ? "" : "Not ");

    sc_EL6751_Canopen_state = s;


}

/*****************************************************************************/

#if SDO_ACCESS
void read_sdo(void)
{
    switch (ecrt_sdo_request_state(sdo)) {
        case EC_REQUEST_UNUSED: // request was not used yet
            ecrt_sdo_request_read(sdo); // trigger first read
            break;
        case EC_REQUEST_BUSY:
            fprintf(stderr, "Still busy...\n");
            break;
        case EC_REQUEST_SUCCESS:
            fprintf(stderr, "SDO value: 0x%04X\n",
                    EC_READ_U16(ecrt_sdo_request_data(sdo)));
            ecrt_sdo_request_read(sdo); // trigger next read
            break;
        case EC_REQUEST_ERROR:
            fprintf(stderr, "Failed to read SDO!\n");
            ecrt_sdo_request_read(sdo); // retry reading
            break;
    }
}
#endif

/****************************************************************************/
//********************************CYCLIC TASK*******************************//
void cyclic_task()
{
    // receive process data
    ecrt_master_receive(master);
    ecrt_domain_process(domain1);

    // check process data state (optional)
    check_domain1_state();

    if (counter) {
        counter--;
    } else { // do this at 1 Hz
        counter = FREQUENCY;

        // check for master state (optional)
        check_master_state();

        // check for islave configuration state(s) (optional)
        check_slave_config_states();

#if SDO_ACCESS
        // read process data SDO
        read_sdo();
#endif
    }


// Reading Analog Input & Writing Digital Output
nPT100_1=EC_READ_U16(domain1_pd + off_ana_in_value);
nPT100_2=EC_READ_U16(domain1_pd + off_ana_in_value2);

#if 1
        switch (nFlag){
        case 0:        // IDLE
            if (nPT100_1 > nLimitMax) {
                     EC_WRITE_BIT(domain1_pd+ off_EL2602_dig_out,0x00,1);    // Para escribir una salida u otra sumar 1 a off_dig_out
             EC_WRITE_U32(domain1_pd + off_out_CanMaster + 1,0x55555555);
                 nFlag=10;
             printf("Temperature PT100_1 Reached the Max Limit -> Value: %u\n",
                     EC_READ_U16(domain1_pd + off_ana_in_value));
             printf("Status Value: %u\n",
                     EC_READ_U8(domain1_pd + off_ana_in_status));
                 printf("Funs and Valve Turned ON\n\n");
                 }
            if (nPT100_2 > nLimitMax) {
                     EC_WRITE_BIT(domain1_pd+ off_EL2602_dig_out,0x00,1);    // Para escribir una salida u otra sumar 1 a off_dig_out
             EC_WRITE_U32(domain1_pd + off_out_CanMaster + 1,0x00000000);
                 nFlag=10;
             printf("Temperature PT100_2 Reached the Max Limit -> Value: %u\n",
                     EC_READ_U16(domain1_pd + off_ana_in_value2));
             printf("Status Value: %u\n",
                     EC_READ_U8(domain1_pd + off_ana_in_status2));
                 printf("Funs and Valve Turned ON\n\n");
                 }
             break;
        case 10:        // OverTemp
            if ((nPT100_1 < nLimitMin)&&(nPT100_2 < nLimitMin)) {
                    EC_WRITE_BIT(domain1_pd + off_EL2602_dig_out,0x00,0);
                nFlag=0;
            printf("Both Temperature Reached the Min Limit\n -> PT100_1 Value: %u || PT100_2 Value: %u \n",
                    EC_READ_U16(domain1_pd + off_ana_in_value),EC_READ_U16(domain1_pd + off_ana_in_value2));
                printf("Funs and Cooler Turned OFF\n\n");
                   }
                break;
        }
    EC_WRITE_BIT(domain1_pd + off_EL2008_dig_out, 0x02,0);
    EC_WRITE_BIT(domain1_pd + off_EL2008_dig_out, 0x03,1);
    EC_WRITE_BIT(domain1_pd + off_EL2008_dig_out, 0x04,0);
    EC_WRITE_BIT(domain1_pd + off_EL2008_dig_out, 0x05,1);
    EC_WRITE_BIT(domain1_pd + off_EL2008_dig_out, 0x06,0);
    EC_WRITE_U32(domain1_pd + off_out_CanMaster + 1,0x55555555);
    
#endif
    // send process data
    ecrt_domain_queue(domain1);
    ecrt_master_send(master);
}

/****************************************************************************/

void signal_handler(int signum) {
    switch (signum) {
        case SIGALRM:
            sig_alarms++;
            break;
    }
}

/****************************************************************************/

//********************************MAIN***************************************//
int main(int argc, char **argv)
{
    int cnt;
    unsigned char pb_config_buf[256];

    ec_slave_config_t *sc;
    struct sigaction sa;
    struct itimerval tv;
    fprintf(stderr,"Requesting Master 0 ...\n");
    master = ecrt_request_master(0);
    if (!master)
        return -1;
    fprintf(stderr,"Creating Domain 1 ...\n");
    domain1 = ecrt_master_create_domain(master);
    if (!domain1)
        return -1;

    printf("Configuring PDOs...\n");

   if (!(sc = ecrt_master_slave_config(master, EK1100Pos, Beckhoff_EK1100))) {
        fprintf(stderr, "Failed to get slave configuration.\n");
        return -1;
    }

    fprintf(stderr,"Getting EL2602 Configuration ...\n");
    if (!(sc_EL2602_dig_out = ecrt_master_slave_config(
                    master,EL2602Pos, Beckhoff_EL2602))) {
        fprintf(stderr, "Failed to get slave configuration.\n");
        return -1;
    }

    printf("Configuring EL2602 PDOs...\n");
    if (ecrt_slave_config_pdos(sc_EL2602_dig_out, EC_END, slave_1_syncs)) {
        fprintf(stderr, "Failed to configure PDOs.\n");
        return -1;
    }

    fprintf(stderr,"Getting EL2008 Configuration ...\n");
    if (!(sc_EL2008_dig_out = ecrt_master_slave_config(
                    master,EL2008Pos, Beckhoff_EL2008))) {
        fprintf(stderr, "Failed to get slave configuration.\n");
        return -1;
    }

    printf("Configuring EL2008 PDOs...\n");
    if (ecrt_slave_config_pdos(sc_EL2008_dig_out, EC_END, slave_3_syncs)) {
        fprintf(stderr, "Failed to configure PDOs.\n");
        return -1;
    }

    fprintf(stderr,"Getting EL3202 Configuration ...\n");
    if (!(sc_EL3202_ana_in = ecrt_master_slave_config(
                    master, EL3202Pos, Beckhoff_EL3202))) {
        fprintf(stderr, "Failed to get slave configuration.\n");
        return -1;
    }

    printf("Configuring EL3202 PDOs...\n");
    if (ecrt_slave_config_pdos(sc_EL3202_ana_in, EC_END, slave_2_syncs)) {
        fprintf(stderr, "Failed to configure PDOs.\n");
        return -1;
    }


    fprintf(stderr,"Getting EL6751 Configuration ...\n");
    if (!(sc_EL6751_Canopen = ecrt_master_slave_config(
                    master, EL6751Pos, Beckhoff_EL6751))) {
        fprintf(stderr, "Failed to get slave configuration.\n");
        return -1;
    }

    fprintf(stderr,"Starting EL6751 Configuration ...\n");

    fprintf(stderr,"Proceeding 0x1C32 wrinting ...\n");
    cnt = strToCharArray(pb_config_master_0x1C32,pb_config_buf);
    ecrt_slave_config_complete_sdo(sc_EL6751_Canopen, 0x1C32, pb_config_buf, cnt);

    fprintf(stderr,"Proceeding 0x1C33 wrinting ...\n");
    cnt = strToCharArray(pb_config_master_0x1C33,pb_config_buf);
    ecrt_slave_config_complete_sdo(sc_EL6751_Canopen, 0x1C33, pb_config_buf, cnt);

    fprintf(stderr,"Proceeding 0xF800 wrinting ...\n");
    cnt = strToCharArray(pb_config_master_0xf800,pb_config_buf);
    ecrt_slave_config_complete_sdo(sc_EL6751_Canopen, 0xf800, pb_config_buf, cnt);

    fprintf(stderr,"Proceeding 0x8000 wrinting ...\n");
    cnt = strToCharArray(pb_config_master_0x8000,pb_config_buf);
    ecrt_slave_config_complete_sdo(sc_EL6751_Canopen, 0x8000, pb_config_buf, cnt);

    fprintf(stderr,"Proceeding 0x8001 wrinting ...\n");
    cnt = strToCharArray(pb_config_master_0x8001,pb_config_buf);
    ecrt_slave_config_complete_sdo(sc_EL6751_Canopen, 0x8001, pb_config_buf, cnt);

    fprintf(stderr,"Proceeding 0x8002 wrinting ...\n");
    cnt = strToCharArray(pb_config_master_0x8002,pb_config_buf);
    ecrt_slave_config_complete_sdo(sc_EL6751_Canopen, 0x8002, pb_config_buf, cnt);

    fprintf(stderr,"Proceeding 0x8003 wrinting ...\n");
    cnt = strToCharArray(pb_config_master_0x8003,pb_config_buf);
    ecrt_slave_config_complete_sdo(sc_EL6751_Canopen, 0x8003, pb_config_buf, cnt);

    fprintf(stderr,"EL6751 Configuration Ended ...\n");
/*---------*/

    printf("Configuring EL6751 PDOs...\n");
    if (ecrt_slave_config_pdos(sc_EL6751_Canopen, EC_END, slave_4_syncs)) {
        fprintf(stderr, "Failed to configure PDOs.\n");
        return -1;
    }


#if SDO_ACCESS
    fprintf(stderr, "Creating SDO requests...\n");
    if (!(sdo = ecrt_slave_config_create_sdo_request(sc_EL6751_Canopen, 0xF002, 3,2))) {
        fprintf(stderr, "Failed to create SDO request.\n");
        return -1;
    }
    ecrt_sdo_request_timeout(sdo, 500); // ms
#endif

    // Create configuration for bus coupler
    sc = ecrt_master_slave_config(master, EK1100Pos, Beckhoff_EK1100);
    if (!sc)
        return -1;

    if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
        fprintf(stderr, "PDO entry registration failed!\n");
        return -1;
    }

    printf("Activating master...\n");
    if (ecrt_master_activate(master))
        return -1;

    if (!(domain1_pd = ecrt_domain_data(domain1))) {
        return -1;
    }

#if PRIORITY
    pid_t pid = getpid();
    if (setpriority(PRIO_PROCESS, pid, -19))
        fprintf(stderr, "Warning: Failed to set priority: %s\n",
                strerror(errno));
#endif

    sa.sa_handler = signal_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    if (sigaction(SIGALRM, &sa, 0)) {
        fprintf(stderr, "Failed to install signal handler!\n");
        return -1;
    }

    printf("Starting timer...\n");
    tv.it_interval.tv_sec = 0;
    tv.it_interval.tv_usec = 1000000 / FREQUENCY;
    tv.it_value.tv_sec = 0;
    tv.it_value.tv_usec = 1000;
    if (setitimer(ITIMER_REAL, &tv, NULL)) {
        fprintf(stderr, "Failed to start timer: %s\n", strerror(errno));
        return 1;
    }

    printf("Started.\n");
    while (1) {
        pause();

#if 0
        struct timeval t;
        gettimeofday(&t, NULL);
        printf("%u.%06u\n", t.tv_sec, t.tv_usec);
#endif

        while (sig_alarms != user_alarms) {
            cyclic_task();
            user_alarms++;
        }
    }

    return 0;
}

/****************************************************************************/

 

 

Thank you very much

 

Best regards

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

David Jiménez Mejías - Gran Telescopio de Canarias S.A

 

Ingeniero de Operación / Operation Engineer

​

 

  

-----Original Message-----
From: Gavin Lambert <gavinl at compacsort.com <mailto:gavinl at compacsort.com> >
To: 'David Jiménez Mejías' <david.jimenez at gtc.iac.es <mailto:david.jimenez at gtc.iac.es> >, <hm at igh-essen.com <mailto:hm at igh-essen.com> >, <etherlab-users at etherlab.org <mailto:etherlab-users at etherlab.org> >
Date: Fri, 30 Oct 2015 11:06:40 +1300
Subject: RE: [etherlab-users]  Beckhoff 6731-0010 initialization
  

Most likely, there is something invalid in the parameters for the SDO configuration functions.  You’ll need to post all of the related code if you want help in locating it.

 

From: etherlab-users [mailto:etherlab-users-bounces at etherlab.org] On Behalf Of David Jiménez Mejías
Sent: Thursday, 29 October 2015 23:53
To: hm at igh-essen.com <mailto:hm at igh-essen.com> ; etherlab-users at etherlab.org <mailto:etherlab-users at etherlab.org> 
Subject: [etherlab-users] Beckhoff 6731-0010 initialization

 

Dear Wilhelm,

 

I was reading your replies to this issue at the EtherLab-Users mailing list and it was very helpful for me.

http://lists.etherlab.org/pipermail/etherlab-users/2012/001860.html

 

I'm trying to configure a Can Network from the Beckhoff Can Master Module EL6751 with only one can slave (Phoenix Contact Can I/O Terminal).

 

I just do it the steps like the configuration of the EL6731 (Profibus Master Module):

     - Configure the Can Network with TwinCAT

     - Export the XML

     - Format it with xmllint

     - And take the necessary data:

          * PDOs Entries: Tx and Rx

          * StartUp SDO config of the next Index:

               + 0x1C32

               + 0x1C33

               + 0xF800

               + 0x8000

               + 0x8001

               + 0x8002

               + 0x8003

     - Implement the C code for the configuration, but I keep out from the app without error at the function: 

          * ecrt_slave_config_complete_sdo(sc, 0x1C32, pb_config_buf, cnt);

 

The last dmesg is:

 

[ 9574.754735] EtherCAT: Requesting master 0...
[ 9574.754754] EtherCAT: Successfully requested master 0.
[ 9574.754984] lt-ec_user_exam[7579]: segfault at 10 ip 00007fdced6058a5 sp 00007ffefada2900 error 4 in libethercat.so.1.0.0[7fdced601000+8000]
[ 9574.930388] EtherCAT 0: Releasing master...
[ 9574.930400] EtherCAT 0: Released.
[ 9607.095769] EtherCAT: Requesting master 0...
[ 9607.095792] EtherCAT: Successfully requested master 0.
[ 9607.095971] lt-ec_user_exam[7663]: segfault at 10 ip 00007fadcfdb98a5 sp 00007ffedfea14c0 error 4 in libethercat.so.1.0.0[7fadcfdb5000+8000]
[ 9607.276982] EtherCAT 0: Releasing master...
[ 9607.277021] EtherCAT 0: Released.
[ 9626.248196] EtherCAT: Requesting master 0...
[ 9626.248200] EtherCAT: Successfully requested master 0.
[ 9626.248261] lt-ec_user_exam[7744]: segfault at 10 ip 00007f741d0eb8a5 sp 00007ffe6e5358f0 error 4 in libethercat.so.1.0.0[7f741d0e7000+8000]
[ 9626.401297] EtherCAT 0: Releasing master...
[ 9626.401309] EtherCAT 0: Released.
[ 9753.014994] EtherCAT: Requesting master 0...
[ 9753.015011] EtherCAT: Successfully requested master 0.
[ 9753.015166] lt-ec_user_exam[7792]: segfault at 10 ip 00007f15e18768a5 sp 00007ffcbd184820 error 4 in libethercat.so.1.0.0[7f15e1872000+8000]
[ 9753.161441] EtherCAT 0: Releasing master...
[ 9753.161589] EtherCAT 0: Released.
[ 9799.019908] EtherCAT: Requesting master 0...
[ 9799.019915] EtherCAT: Successfully requested master 0.
[ 9799.020082] lt-ec_user_exam[7814]: segfault at 10 ip 00007fd538ee78a5 sp 00007ffd0c9fca80 error 4 in libethercat.so.1.0.0[7fd538ee3000+8000]
[ 9799.165522] EtherCAT 0: Releasing master...
[ 9799.165574] EtherCAT 0: Released.

 

I'm not sure is there is the correct information to know whats happens, tell me any doubt.

 

Thank you very much

 

King regards

 

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

David Jiménez Mejías - Gran Telescopio de Canarias S.A

 

Ingeniero de Operación / Operation Engineer

 

 

 

 


----------
ADVERTENCIA: Sobre la privacidad y cumplimiento de la Ley de Protección de Datos, acceda a http://www.gtc.iac.es/gtc/legal_es.php
WARNING: For more information on privacy and fulfilment of the Law concerning the Protection of Data, consult http://www.gtc.iac.es/gtc/legal_es.php


----------
ADVERTENCIA: Sobre la privacidad y cumplimiento de la Ley de Protección de Datos, acceda a http://www.gtc.iac.es/gtc/legal_es.php
WARNING: For more information on privacy and fulfilment of the Law concerning the Protection of Data, consult http://www.gtc.iac.es/gtc/legal_es.php

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20151102/1333fb14/attachment-0002.htm>


More information about the Etherlab-users mailing list