AB&T
/
EasyCAT_LAB_very_simple
EasyCAT LAB - EtherCAT master very simple example
- This repository contains a very basic example for the EasyCAT LAB , a complete educational and experimental EtherCAT® system, composed of one master and two slaves.
- The EasyCAT LAB is provided as a kit by AB&T Tecnologie Informatiche, to allow everybody to have an educational EtherCAT® system up and running in a matter of minutes.
- It uses the SOEM (Simple Open EtherCAT® Master) library by rt-labs, that has been ported in the ecosystem by AB&T Tecnologie Informatiche.
- The slaves are based on the EasyCAT SHIELD and the Arduino UNO.
Note
- This example uses two LAB 2 slaves.
Note
- In this example, to keep things as simple as possible, only two bytes of data are exchanged between the slaves and the TFT display is not used .
config.h
- Committer:
- sulymarco
- Date:
- 2019-07-09
- Revision:
- 0:bc829777f1ea
- Child:
- 2:368e7d4d8171
File content as of revision 0:bc829777f1ea:
#ifndef config_H #define config_H #include "ethercat.h" //------------------------------------------------------------------------------ #define LAB_2_1 1 #define LAB_2_2 2 #define SLAVE_NUM 2 //------------------------------------------------------------------------------ #define IO_MAP_SIZE 256 //------------------------------------------------------------------------------ typedef struct __attribute__((__packed__)) { uint8_t Segments; }out_LAB_2_1t; typedef struct __attribute__((__packed__)) { uint16_t Potentiometer; // in this example we don't use the uint8_t Buttons; // potentiometer but we have to }in_LAB_2_1t; // declare it in the data structure //------------------------------------------------------------------------------ typedef struct __attribute__((__packed__)) { uint8_t Segments; }out_LAB_2_2t; typedef struct __attribute__((__packed__)) { uint16_t Potentiometer; // in this example we don't use the uint8_t Buttons; // potentiometer but we have to }in_LAB_2_2t; // declare it in the data structure //------------------------------------------------------------------------------ out_LAB_2_1t *out_LAB_2_1; in_LAB_2_1t *in_LAB_2_1; out_LAB_2_2t *out_LAB_2_2; in_LAB_2_2t *in_LAB_2_2; //------------------------------------------------------------------------------ char IOmap[IO_MAP_SIZE]; char IOmapSafe[IO_MAP_SIZE]; void MapLocalStructures (void) { out_LAB_2_1 = (out_LAB_2_1t*)((char *)ec_slave[LAB_2_1].outputs - &IOmap[0] + &IOmapSafe[0]); in_LAB_2_1 = (in_LAB_2_1t*)((char *)ec_slave[LAB_2_1].inputs - &IOmap[0] + &IOmapSafe[0]); out_LAB_2_2 = (out_LAB_2_2t*)((char *)ec_slave[LAB_2_2].outputs - &IOmap[0] + &IOmapSafe[0]); in_LAB_2_2 = (in_LAB_2_2t*)((char *)ec_slave[LAB_2_2].inputs - &IOmap[0] + &IOmapSafe[0]); } //------------------------------------------------------------------------------ uint32_t network_configuration(void) { if (ec_slavecount != SLAVE_NUM) // check if the number of slaves matches what we expect return 0; if (strcmp(ec_slave[LAB_2_1].name,"LAB_2")) // verify slave by slave that the slave names are correct return 0; else if (strcmp(ec_slave[LAB_2_2].name,"LAB_2")) return 0; return 1; } #endif