etherlab/EthercatCFileGenerator.py
changeset 2117 accc4cbca8d3
parent 2116 2b1980a038b1
child 2121 11102245e1d4
equal deleted inserted replaced
2116:2b1980a038b1 2117:accc4cbca8d3
    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, "EtherCAT failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.");
    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         goto ecat_failed;
    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, "EtherCAT Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%d", 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             goto ecat_failed;
    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, "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);
    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             goto ecat_failed;
    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 """
    59 
    59