[etherlab-users] Accessing Different Digital I/O Channels

Akhil Chandra Maganti amaganti at exxpertsystems.de
Fri Oct 14 11:07:13 CEST 2016


Dear users,

 

I am a newbie here, working with

*         EL2124 (Digital Out)

*         EL1124(Digital In)

*         EL3102 (Analog In)

*         EL4132 (Analog Out)

 

I started with the ethercat-hg/examples/user/main.c

 

I was successfully able to run the program and see the Digital Out blinks
and I've given that to Digital In (to read the data that I've given).

 

Now I want to differentiate different channels, as EL2124 and EL 1124 are
having 4 channels. 

 

I would like to 'write' only to Channel 1 of EL2124 and 'read' from Channel
1 of 1124. Similarly for other channels of the digital terminals (also
analog).

 

I tried different things.. 

 

Case 1: By using different offsets for PDO entries for different channels


 

// offsets for PDO entries

static unsigned int off_ana_in_status;

static unsigned int off_ana_in_value;

static unsigned int off_ana_out;

static unsigned int off_dig_out;

static unsigned int off_dig_out2;

static unsigned int off_dig_out3;

static unsigned int off_dig_out4;

static unsigned int off_dig_in;

static unsigned int off_dig_in2;

static unsigned int off_dig_in3;

static unsigned int off_dig_in4;

 

const static ec_pdo_entry_reg_t domain1_regs[] = {

{AnaInSlavePos,  Beckhoff_EL3102, 0x3101, 0x01, &off_ana_in_status},

{AnaInSlavePos,  Beckhoff_EL3102, 0x3101, 0x02, &off_ana_in_value},

{AnaOutSlavePos, Beckhoff_EL4132, 0x3001, 0x01, &off_ana_out},

{DigInSlavePos, Beckhoff_EL1124, 0x6000, 1, &off_dig_in},

{DigInSlavePos, Beckhoff_EL1124, 0x6000, 1, &off_dig_in2}, 

{DigInSlavePos, Beckhoff_EL1124, 0x6000, 1, &off_dig_in3},

{DigInSlavePos, Beckhoff_EL1124, 0x6000, 1, &off_dig_in4},

{DigOutSlavePos, Beckhoff_EL2124, 0x7000, 1, &off_dig_out},

{DigOutSlavePos, Beckhoff_EL2124, 0x7010, 1, &off_dig_out2},

{DigOutSlavePos, Beckhoff_EL2124, 0x7020, 1, &off_dig_out3},

{DigOutSlavePos, Beckhoff_EL2124, 0x7030, 1, &off_dig_out4},

 

 

    {}

 

 

/*My cstruct:*/

 

/*******************Digital_Out*********************************************
**/

 

/* Master 0, Slave 1, "EL2124"

* Vendor ID:       0x00000002

* Product code:    0x084c3052

* Revision number: 0x00110000

*/

 

ec_pdo_entry_info_t slave_1_pdo_entries[] = {

    {0x7000, 0x01, 1}, /* Output */

    {0x7010, 0x01, 1}, /* Output */

    {0x7020, 0x01, 1}, /* Output */

    {0x7030, 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 */

    {0x1602, 1, slave_1_pdo_entries + 2}, /* Channel 3 */

    {0x1603, 1, slave_1_pdo_entries + 3}, /* Channel 4 */

};

 

ec_sync_info_t slave_1_syncs[] = {

    {0, EC_DIR_OUTPUT, 4, slave_1_pdos + 0, EC_WD_ENABLE},

    {0xff}

};

 

/*******************Digital_In**********************************************
*/

 

/* Master 0, Slave 2, "EL1124"

* Vendor ID:       0x00000002

* Product code:    0x04643052

* Revision number: 0x00110000

*/

 

ec_pdo_entry_info_t slave_2_pdo_entries[] = {

    {0x6000, 0x01, 1}, /* Input */

    {0x6010, 0x01, 1}, /* Input */

    {0x6020, 0x01, 1}, /* Input */

    {0x6030, 0x01, 1}, /* Input */

};

 

ec_pdo_info_t slave_2_pdos[] = {

    {0x1a00, 1, slave_2_pdo_entries + 0}, /* Channel 1 */

    {0x1a01, 1, slave_2_pdo_entries + 1}, /* Channel 2 */

    {0x1a02, 1, slave_2_pdo_entries + 2}, /* Channel 3 */

    {0x1a03, 1, slave_2_pdo_entries + 3}, /* Channel 4 */

};

 

ec_sync_info_t slave_2_syncs[] = {

    {0, EC_DIR_INPUT, 4, slave_2_pdos + 0, EC_WD_DISABLE},

    {0xff}

};

 

/*******************Analog_In***********************************************
/

 

/* Master 0, Slave 3, "EL3102"

* Vendor ID:       0x00000002

* Product code:    0x0c1e3052

* Revision number: 0x00140000

*/

 

ec_pdo_entry_info_t slave_3_pdo_entries[] = {

    {0x3101, 0x01, 8},

    {0x3101, 0x02, 16},

    {0x3102, 0x01, 8},

    {0x3102, 0x02, 16},

};

 

ec_pdo_info_t slave_3_pdos[] = {

    {0x1a00, 2, slave_3_pdo_entries + 0}, /* TxPDO-Map Channel 1 */

    {0x1a01, 2, slave_3_pdo_entries + 2}, /* TxPDO-Map Channel 2 */

};

 

ec_sync_info_t slave_3_syncs[] = {

    {1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},

    {2, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},

    {3, EC_DIR_INPUT, 2, slave_3_pdos + 0, EC_WD_DISABLE},

    {0xff}

};

 

/*******************Analog_Out**********************************************
*/

 

/* Master 0, Slave 4, "EL4132"

* Vendor ID:       0x00000002

* Product code:    0x10243052

* Revision number: 0x03fb0000

*/

 

ec_pdo_entry_info_t slave_4_pdo_entries[] = {

    {0x3001, 0x01, 16}, /* Output */

    {0x3002, 0x01, 16}, /* Output */

};

 

ec_pdo_info_t slave_4_pdos[] = {

    {0x1600, 1, slave_4_pdo_entries + 0}, /* RxPDO 01 mapping */

    {0x1601, 1, slave_4_pdo_entries + 1}, /* RxPDO 02 mapping */

};

 

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, 2, slave_4_pdos + 0, EC_WD_DISABLE},

    {3, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},

    {0xff}

};

 

 

if (!(sc_ana_in = ecrt_master_slave_config(

                    master, AnaInSlavePos, Beckhoff_EL3102))) {

        fprintf(stderr, "Failed to get slave configuration.\n");

        return -1;

    }

 

#if SDO_ACCESS

    fprintf(stderr, "Creating SDO requests...\n");

    if (!(sdo = ecrt_slave_config_create_sdo_request(sc_ana_in, 0x3102, 2,
2))) {

        fprintf(stderr, "Failed to create SDO request.\n");

        return -1;

    }

    ecrt_sdo_request_timeout(sdo, 500); // ms

#endif

 

#if CONFIGURE_PDOS

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

    if (ecrt_slave_config_pdos(sc_ana_in, EC_END, slave_3_syncs)) {

        fprintf(stderr, "Failed to configure PDOs.\n");

        return -1;

    }

 

    if (!(sc = ecrt_master_slave_config(

                    master, AnaOutSlavePos, Beckhoff_EL4132))) {

        fprintf(stderr, "Failed to get slave configuration.\n");

        return -1;

    }

 

    if (ecrt_slave_config_pdos(sc, EC_END, slave_4_syncs)) {

        fprintf(stderr, "Failed to configure PDOs.\n");

        return -1;

    }

 

if (!(sc = ecrt_master_slave_config(

                    master, DigInSlavePos, Beckhoff_EL1124))) {

        fprintf(stderr, "Failed to get slave configuration.\n");

        return -1;

    }

 

    if (ecrt_slave_config_pdos(sc, EC_END, slave_2_syncs)) {

        fprintf(stderr, "Failed to configure PDOs.\n");

        return -1;

    }

 

 

    if (!(sc = ecrt_master_slave_config(

                    master, DigOutSlavePos, Beckhoff_EL2124))) {

        fprintf(stderr, "Failed to get slave configuration.\n");

       return -1;

    }

 

    if (ecrt_slave_config_pdos(sc, EC_END, slave_1_syncs)) {

        fprintf(stderr, "Failed to configure PDOs.\n");

        return -1;

    }

 

 

 

 

 

/*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;

 

        // calculate new process data

        blink = !blink;

 

        //~ // 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

 

    }

 

#if 0

    // read process data

    printf("AnaIn: state %u value %u \n Digital_In: %u \n",

            EC_READ_U8(domain1_pd + off_ana_in_status),

            EC_READ_U16(domain1_pd + off_ana_in_value));

 

#endif

 

#if 1

    // write process data

    EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09); /*Here I
want to write to different channels*/

    printf("\nDigital_In: %u \n", EC_READ_U8(domain1_pd + off_dig_in));/*I
want to read from different Digital Channels*/    

#endif

 

    // send process data

    ecrt_domain_queue(domain1);

    ecrt_master_send(master);

 

 

 

 

 

 

 

Any help Appreciated,

 

Regards,

Akhil Chandra Maganti.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20161014/9e18418c/attachment-0002.htm>


More information about the Etherlab-users mailing list