etherlab/EthercatCFileGenerator.py
changeset 2116 2b1980a038b1
parent 2111 f2cffda17d00
child 2117 accc4cbca8d3
equal deleted inserted replaced
2115:edb49073227e 2116:2b1980a038b1
    23 };
    23 };
    24 """
    24 """
    25 
    25 
    26 SLAVE_CONFIGURATION_TEMPLATE = """
    26 SLAVE_CONFIGURATION_TEMPLATE = """
    27     if (!(slave%(slave)d = ecrt_master_slave_config(master, %(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x))) {
    27     if (!(slave%(slave)d = ecrt_master_slave_config(master, %(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x))) {
    28         SLOGF(LOG_CRITICAL, "Failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d.\\n");
    28         SLOGF(LOG_CRITICAL, "EtherCAT failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d.");
    29         return -1;
    29         return -1;
    30     }
    30     }
    31 
    31 
    32     if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) {
    32     if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) {
    33         SLOGF(LOG_CRITICAL, "Failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.\\n");
    33         SLOGF(LOG_CRITICAL, "EtherCAT failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.");
    34         return -1;
    34         return -1;
    35     }
    35     }
    36 """
    36 """
    37 
    37 
    38 SLAVE_INITIALIZATION_TEMPLATE = """
    38 SLAVE_INITIALIZATION_TEMPLATE = """
    39     {
    39     {
    40         uint8_t value[%(data_size)d];
    40         uint8_t value[%(data_size)d];
    41         EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s);
    41         EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s);
    42         if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) {
    42         if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) {
    43             SLOGF(LOG_CRITICAL, "Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code);
    43             SLOGF(LOG_CRITICAL, "EtherCAT Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%d", abort_code);
    44             return -1;
    44             return -1;
    45         }
    45         }
    46     }
    46     }
    47 """
    47 """
    48 
    48 
    49 SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """
    49 SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """
    50     {
    50     {
    51         uint8_t value[%(data_size)d];
    51         uint8_t value[%(data_size)d];
    52         if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
    52         if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
    53             SLOGF(LOG_CRITICAL, "Failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%ud\\n", abort_code);
    53             SLOGF(LOG_CRITICAL, "EtherCAT failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%ud", abort_code);
    54             return -1;
    54             return -1;
    55         }
    55         }
    56         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
    56         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
    57     }
    57     }
    58 """
    58 """