etherlab/EthercatCFileGenerator.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 25 Nov 2019 08:26:55 +0100
branchethercat_from_kosmos
changeset 2642 65701f40d970
parent 2641 c9deff128c37
child 2643 b98d9e08231f
permissions -rw-r--r--
Close branch ethercat_from_kosmos
2165
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     1
#!/usr/bin/env python
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     2
# -*- coding: utf-8 -*-
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     3
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     4
# This file is part of Beremiz
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     5
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     6
# Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     7
#                          RTES Lab : CRKim, JBLee, youcu
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     8
#                          Higen Motor : Donggu Kang
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
     9
#
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
    10
# See COPYING file for copyrights details.
02a2b5dee5e3 Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2144
diff changeset
    11
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    12
import os
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    13
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    14
from EthercatSlave import ExtractHexDecValue, DATATYPECONVERSION, ExtractName
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    15
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    16
SLAVE_PDOS_CONFIGURATION_DECLARATION = """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    17
/* Slave %(slave)d, "%(device_type)s"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    18
 * Vendor ID:       0x%(vendor).8x
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    19
 * Product code:    0x%(product_code).8x
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    20
 * Revision number: 0x%(revision_number).8x
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    21
 */
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    22
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    23
ec_pdo_entry_info_t slave_%(slave)d_pdo_entries[] = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    24
%(pdos_entries_infos)s
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    25
};
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    26
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    27
ec_pdo_info_t slave_%(slave)d_pdos[] = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    28
%(pdos_infos)s
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    29
};
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    30
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    31
ec_sync_info_t slave_%(slave)d_syncs[] = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    32
%(pdos_sync_infos)s
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    33
    {0xff}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    34
};
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    35
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    36
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    37
SLAVE_CONFIGURATION_TEMPLATE = """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    38
    if (!(slave%(slave)d = ecrt_master_slave_config(master, %(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x))) {
2116
2b1980a038b1 Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents: 2111
diff changeset
    39
        SLOGF(LOG_CRITICAL, "EtherCAT failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d.");
2121
11102245e1d4 Fixed (again) some non-clean exit in case of SDO failure at init
Edouard Tisserant
parents: 2117
diff changeset
    40
        goto ecat_failed;
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    41
    }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    42
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    43
    if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) {
2116
2b1980a038b1 Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents: 2111
diff changeset
    44
        SLOGF(LOG_CRITICAL, "EtherCAT failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.");
2117
accc4cbca8d3 Now failure in template based part of C code also release the master for later use...
Edouard Tisserant
parents: 2116
diff changeset
    45
        goto ecat_failed;
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    46
    }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    47
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    48
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    49
SLAVE_INITIALIZATION_TEMPLATE = """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    50
    {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    51
        uint8_t value[%(data_size)d];
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    52
        EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s);
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    53
        if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) {
2116
2b1980a038b1 Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents: 2111
diff changeset
    54
            SLOGF(LOG_CRITICAL, "EtherCAT Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%d", abort_code);
2117
accc4cbca8d3 Now failure in template based part of C code also release the master for later use...
Edouard Tisserant
parents: 2116
diff changeset
    55
            goto ecat_failed;
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    56
        }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    57
    }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    58
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    59
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    60
SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    61
    {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    62
        uint8_t value[%(data_size)d];
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    63
        if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
2116
2b1980a038b1 Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents: 2111
diff changeset
    64
            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);
2117
accc4cbca8d3 Now failure in template based part of C code also release the master for later use...
Edouard Tisserant
parents: 2116
diff changeset
    65
            goto ecat_failed;
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    66
        }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    67
        %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    68
    }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    69
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    70
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    71
SLAVE_OUTPUT_PDO_DEFAULT_VALUE_BIT = """
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    72
    {
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    73
        uint8_t value[%(data_size)d];
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    74
        if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    75
            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);
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    76
            goto ecat_failed;
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    77
        }
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    78
        %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value, %(subindex)d);
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    79
    }
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    80
"""
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    81
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    82
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    83
SLAVE_INPUT_PDO_DEFAULT_VALUE = """
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    84
    {
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    85
        uint8_t value[%(data_size)d];
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    86
        if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    87
            SLOGF(LOG_CRITICAL, "EtherCAT failed to get default value for input PDO in slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%ud", abort_code);
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    88
            goto ecat_failed;
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    89
        }
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    90
        %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    91
    }
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    92
"""
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    93
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    94
DC_VARIABLE ="""
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    95
#define DC_ENABLE       %(dc_flag)d
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    96
"""
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    97
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    98
CONFIG_DC = """
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
    99
    ecrt_slave_config_dc (slave%(slave)d, 0x0%(assign_activate)ld, %(sync0_cycle_time)d, %(sync0_shift_time)d, %(sync1_cycle_time)d, %(sync1_shift_time)d);
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   100
"""
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   101
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   102
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   103
def ConfigureVariable(entry_infos, str_completion):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   104
    entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   105
    if entry_infos["data_type"] is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   106
        raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   107
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   108
    if not entry_infos.get("no_decl", False):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   109
        if entry_infos.has_key("real_var"):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   110
            str_completion["located_variables_declaration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   111
                "IEC_%(var_type)s %(real_var)s;" % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   112
        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   113
            entry_infos["real_var"] = "beremiz" + entry_infos["var_name"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   114
            str_completion["located_variables_declaration"].extend(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   115
                ["IEC_%(var_type)s %(real_var)s;" % entry_infos,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   116
                 "IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   117
        for declaration in entry_infos.get("extra_declarations", []):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   118
            entry_infos["extra_decl"] = declaration
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   119
            str_completion["located_variables_declaration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   120
                 "IEC_%(var_type)s *%(extra_decl)s = &%(real_var)s;" % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   121
    elif not entry_infos.has_key("real_var"):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   122
        entry_infos["real_var"] = "beremiz" + entry_infos["var_name"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   123
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   124
    str_completion["used_pdo_entry_offset_variables_declaration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   125
        "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   126
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   127
    if entry_infos["data_type"] == "BIT":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   128
        str_completion["used_pdo_entry_offset_variables_declaration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   129
            "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x_bit;" % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   130
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   131
        str_completion["used_pdo_entry_configuration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   132
             ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, " + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   133
              "0x%(index).4x, %(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x, " + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   134
              "&slave%(slave)d_%(index).4x_%(subindex).2x_bit},") % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   135
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   136
        if entry_infos["dir"] == "I":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   137
            str_completion["retrieve_variables"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   138
              ("    %(real_var)s = EC_READ_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   139
               "slave%(slave)d_%(index).4x_%(subindex).2x_bit);") % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   140
        elif entry_infos["dir"] == "Q":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   141
            str_completion["publish_variables"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   142
              ("    EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   143
               "slave%(slave)d_%(index).4x_%(subindex).2x_bit, %(real_var)s);") % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   144
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   145
    else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   146
        str_completion["used_pdo_entry_configuration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   147
            ("    {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   148
             "%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   149
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   150
        if entry_infos["dir"] == "I":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   151
            str_completion["retrieve_variables"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   152
                ("    %(real_var)s = EC_READ_%(data_type)s(domain1_pd + " + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   153
                 "slave%(slave)d_%(index).4x_%(subindex).2x);") % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   154
        elif entry_infos["dir"] == "Q":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   155
            str_completion["publish_variables"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   156
                ("    EC_WRITE_%(data_type)s(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   157
                 "%(real_var)s);") % entry_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   158
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   159
def ExclusionSortFunction(x, y):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   160
    if x["matching"] == y["matching"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   161
        if x["assigned"] and not y["assigned"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   162
            return -1
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   163
        elif not x["assigned"] and y["assigned"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   164
            return 1
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   165
        return cmp(x["count"], y["count"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   166
    return -cmp(x["matching"], y["matching"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   167
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   168
class _EthercatCFileGenerator:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   169
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   170
    def __init__(self, controler):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   171
        self.Controler = controler
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   172
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   173
        self.Slaves = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   174
        self.UsedVariables = {}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   175
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   176
    def __del__(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   177
        self.Controler = None            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   178
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   179
    def DeclareSlave(self, slave_index, slave):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   180
        self.Slaves.append((slave_index, slave.getInfo().getAutoIncAddr(), slave))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   181
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   182
    def DeclareVariable(self, slave_index, index, subindex, iec_type, dir, name, no_decl=False):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   183
        slave_variables = self.UsedVariables.setdefault(slave_index, {})
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   184
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   185
        entry_infos = slave_variables.get((index, subindex), None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   186
        if entry_infos is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   187
            slave_variables[(index, subindex)] = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   188
                "infos": (iec_type, dir, name, no_decl, []),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   189
                "mapped": False}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   190
            return name
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   191
        elif entry_infos["infos"][:2] == (iec_type, dir):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   192
            if name != entry_infos["infos"][2]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   193
                if dir == "I":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   194
                    entry_infos["infos"][4].append(name)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   195
                    return entry_infos["infos"][2]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   196
                else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   197
                    raise ValueError, _("Output variables can't be defined with different locations (%s and %s)") % (entry_infos["infos"][2], name)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   198
        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   199
            raise ValueError, _("Definition conflict for location \"%s\"") % name 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   200
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   201
    def GenerateCFile(self, filepath, location_str, master_number):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   202
        # Extract etherlab master code template
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   203
        plc_etherlab_filepath = os.path.join(os.path.split(__file__)[0], "plc_etherlab.c")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   204
        plc_etherlab_file = open(plc_etherlab_filepath, 'r')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   205
        plc_etherlab_code = plc_etherlab_file.read()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   206
        plc_etherlab_file.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   207
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   208
        # Initialize strings for formatting master code template
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   209
        str_completion = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   210
            "location": location_str,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   211
            "master_number": master_number,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   212
            "located_variables_declaration": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   213
            "used_pdo_entry_offset_variables_declaration": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   214
            "used_pdo_entry_configuration": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   215
            "pdos_configuration_declaration": "",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   216
            "slaves_declaration": "",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   217
            "slaves_configuration": "",
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   218
            # add jblee
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   219
            "slaves_input_pdos_default_values_extraction": "",
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   220
            "slaves_output_pdos_default_values_extraction": "",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   221
            "slaves_initialization": "",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   222
            "retrieve_variables": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   223
            "publish_variables": [],
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   224
            #-----------This Code templete for dc -------------------#
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   225
            "dc_variable" : "",
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   226
            "config_dc": ""
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   227
        }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   228
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   229
        # Initialize variable storing variable mapping state
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   230
        for slave_entries in self.UsedVariables.itervalues():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   231
            for entry_infos in slave_entries.itervalues():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   232
                entry_infos["mapped"] = False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   233
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   234
        # Sort slaves by position (IEC_Channel)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   235
        self.Slaves.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   236
        # Initialize dictionary storing alias auto-increment position values
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   237
        alias = {}
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   238
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   239
        # add jblee
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   240
        slotNumber = 1
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   241
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   242
        # Generating code for each slave
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   243
        for (slave_idx, slave_alias, slave) in self.Slaves:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   244
            type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   245
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   246
            # Defining slave alias and auto-increment position
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   247
            if alias.get(slave_alias) is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   248
                alias[slave_alias] += 1
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   249
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   250
                alias[slave_alias] = 0
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   251
            slave_pos = (slave_alias, alias[slave_alias])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   252
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   253
            # Extract slave device informations
2137
b65abacdbdf9 Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents: 2121
diff changeset
   254
            device, module_extra_params = self.Controler.GetModuleInfos(type_infos)
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   255
            if device is None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   256
                raise ValueError, _("No informations found for device %s!") % (type_infos["device_type"])
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   257
            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   258
            # Extract slaves variables to be mapped
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   259
            slave_variables = self.UsedVariables.get(slave_idx, {})
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   260
            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   261
            # Extract slave device object dictionary entries
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   262
            device_entries = device.GetEntriesList()
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   263
            #device_entries = self.Controler.CTNParent.GetEntriesList()
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   264
            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   265
            # Adding code for declaring slave in master code template strings
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   266
            for element in ["vendor", "product_code", "revision_number"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   267
                type_infos[element] = ExtractHexDecValue(type_infos[element])
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   268
            type_infos.update(dict(zip(["slave", "alias", "position"], (slave_idx,) + slave_pos)))
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   269
            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   270
            # Extract slave device CoE informations
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   271
            device_coe = device.getCoE()
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   272
            if device_coe is not None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   273
                # If device support CanOpen over Ethernet, adding code for calling 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   274
                # init commands when initializing slave in master code template strings
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   275
                initCmds = []
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   276
                
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   277
                for initCmd in device_coe.getInitCmd():
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   278
                    initCmds.append({
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   279
                        "Index": ExtractHexDecValue(initCmd.getIndex()),
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   280
                        "Subindex": ExtractHexDecValue(initCmd.getSubIndex()),
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   281
                        #"Value": initCmd.getData().getcontent()})
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   282
                        "Value": int(initCmd.getData().text, 16)})
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   283
                
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   284
                initCmds.extend(slave.getStartupCommands())
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   285
                for initCmd in initCmds:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   286
                    index = initCmd["Index"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   287
                    subindex = initCmd["Subindex"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   288
                    entry = device_entries.get((index, subindex), None)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   289
                    if entry is not None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   290
                        data_size = entry["BitSize"] / 8
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   291
                        data_str = ("0x%%.%dx" % (data_size * 2)) % initCmd["Value"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   292
                        init_cmd_infos = {
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   293
                            "index": index,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   294
                            "subindex": subindex,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   295
                            "data": data_str,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   296
                            "data_type": DATATYPECONVERSION.get(entry["Type"]),
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   297
                            "data_size": data_size
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   298
                        }
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   299
                        init_cmd_infos.update(type_infos)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   300
                        str_completion["slaves_initialization"] += SLAVE_INITIALIZATION_TEMPLATE % init_cmd_infos
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   301
            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   302
                # Extract slave device PDO configuration capabilities
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   303
                PdoAssign = device_coe.getPdoAssign()
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   304
                PdoConfig = device_coe.getPdoConfig()
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   305
            else:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   306
                PdoAssign = PdoConfig = False
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   307
            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   308
            # Test if slave has a configuration or need one
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   309
            #if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0 and PdoConfig and PdoAssign:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   310
            if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0 or device.getSlots() is not None:
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   311
                str_completion["slaves_declaration"] += "static ec_slave_config_t *slave%(slave)d = NULL;\n" % type_infos
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   312
                str_completion["slaves_configuration"] += SLAVE_CONFIGURATION_TEMPLATE % type_infos
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   313
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   314
                # Initializing 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   315
                pdos_infos = {
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   316
                    "pdos_entries_infos": [],
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   317
                    "pdos_infos": [],
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   318
                    "pdos_sync_infos": [], 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   319
                }
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   320
                pdos_infos.update(type_infos)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   321
                
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   322
                sync_managers = []
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   323
                for sync_manager_idx, sync_manager in enumerate(device.getSm()):
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   324
                    sync_manager_infos = {
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   325
                        "index": sync_manager_idx, 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   326
                        "name": sync_manager.getcontent(),
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   327
                        "slave": slave_idx,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   328
                        "pdos": [], 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   329
                        "pdos_number": 0,
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   330
                    }
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   331
                    
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   332
                    sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte())
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   333
                    sync_manager_direction = sync_manager_control_byte & 0x0c
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   334
                    sync_manager_watchdog = sync_manager_control_byte & 0x40
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   335
                    if sync_manager_direction:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   336
                        sync_manager_infos["sync_manager_type"] = "EC_DIR_OUTPUT"
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   337
                    else:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   338
                        sync_manager_infos["sync_manager_type"] = "EC_DIR_INPUT"
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   339
                    if sync_manager_watchdog:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   340
                        sync_manager_infos["watchdog"] = "EC_WD_ENABLE"
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   341
                    else:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   342
                        sync_manager_infos["watchdog"] = "EC_WD_DISABLE"
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   343
                    
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   344
                    sync_managers.append(sync_manager_infos)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   345
                
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   346
                pdos_index = []
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   347
                exclusive_pdos = {}
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   348
                selected_pdos = []
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   349
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   350
                # add jblee
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   351
                TxPdoData = []
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   352
                RxPdoData = []
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   353
                PdoData = []
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   354
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   355
                # add jblee
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   356
                if len(device.getTxPdo() + device.getRxPdo()) > 0:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   357
                    for pdo in device.getTxPdo():
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   358
                        PdoData.append((pdo, "Inputs"))
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   359
                    for pdo in device.getRxPdo():
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   360
                        PdoData.append((pdo, "Outputs"))               
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   361
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   362
                # mod jblee
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   363
                #for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   364
                #                      [(pdo, "Outputs") for pdo in device.getRxPdo()]):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   365
                #for pdo, pdo_type in (TxPdoData + RxPdoData):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   366
                data_files = os.listdir(self.Controler.CTNPath())
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   367
                PDODataList = []
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   368
                MDPData = []
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   369
                RxPDOData = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getRxPDO()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   370
                TxPDOData = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getTxPDO()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   371
                PDOList = RxPDOData.split() + TxPDOData.split()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   372
                for PDOIndex in PDOList:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   373
                    if PDOIndex in ["RxPDO", "TxPDO", "None"]:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   374
                        continue
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   375
                    PDODataList.append(int(PDOIndex, 0))
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   376
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   377
                # add jblee for DC Configuration
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   378
                dc_enable = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Enable()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   379
                sync0_cycle_time = 0
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   380
                sync0_shift_time = 0
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   381
                sync1_cycle_time = 0
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   382
                sync1_shift_time = 0
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   383
                if dc_enable :
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   384
                    sync0_cycle_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync0_Cycle_Time()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   385
                    if sync0_cycle_token != "None":
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   386
                        sync0_cycle_time = int(sync0_cycle_token.split("_")[1]) * 1000
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   387
                    sync0_shift_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync0_Shift_Time()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   388
                    if sync0_shift_token != "None":
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   389
                        sync0_shift_time = int(sync0_shift_token) * 1000
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   390
                    sync1_cycle_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync1_Cycle_Time()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   391
                    if sync1_cycle_token != "None":
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   392
                        sync1_cycle_time = int(sync1_cycle_token.split("_")[1]) * 1000
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   393
                    sync1_shift_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync1_Shift_Time()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   394
                    if sync1_shift_token != "None":
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   395
                        sync1_shift_time = int(sync1_shift_token) * 1000
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   396
                    
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   397
                    dc_config_data = {
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   398
                        "slave" : slave_idx,
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   399
                        "assign_activate" : int(self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Assign_Activate()),
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   400
                        "sync0_cycle_time" : sync0_cycle_time,
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   401
                        "sync0_shift_time" : sync0_shift_time,
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   402
                        "sync1_cycle_time" : sync1_cycle_time,
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   403
                        "sync1_shift_time" : sync1_shift_time,
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   404
                    }
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   405
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   406
                    if dc_enable and not str_completion["dc_variable"] :
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   407
                        str_completion["dc_variable"] += DC_VARIABLE % {"dc_flag" : dc_enable}
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   408
                    str_completion["config_dc"] += CONFIG_DC % dc_config_data
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   409
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   410
                for data_file in data_files:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   411
                    slave_path = os.path.join(self.Controler.CTNPath(), data_file)
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   412
                    if os.path.isdir(slave_path):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   413
                        CheckConfNodePath = os.path.join(slave_path, "baseconfnode.xml")
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   414
                        confNodeFile = open(CheckConfNodePath, 'r')
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   415
                        checklines = confNodeFile.readlines()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   416
                        confNodeFile.close()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   417
                        # checklines(ex) : <BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="EthercatSlave_0"/>
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   418
                        # checklines[1].split() : [<BaseParams, xmlns:xsd="http://www.w3.org/2001/XMLSchema",
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   419
                        #                           IEC_Channel="0", Name="EthercatSlave_0"/>]
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   420
                        # checklines[1].split()[2] : IEC_Channel="0"
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   421
                        # checklines[1].split()[2].split("\"") = [IEC_Channel=, 0, ]
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   422
                        pos_check = int(checklines[1].split()[2].split("\"")[1])
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   423
                        if slave_idx == pos_check:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   424
                            MDPDataFilePath = os.path.join(slave_path, "DataForMDP.txt")
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   425
                            if os.path.isfile(MDPDataFilePath):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   426
                                MDPDataFile = open(MDPDataFilePath, 'r')
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   427
                                MDPData = MDPDataFile.readlines()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   428
                                MDPDataFile.close()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   429
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   430
                        for MDPLine in MDPData:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   431
                            if MDPLine == "\n":
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   432
                                continue
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   433
                            module_pos = int(MDPLine.split()[-1])
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   434
                            module = self.Controler.CTNParent.GetSelectModule(module_pos)
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   435
                            for pdo in module.getTxPdo():
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   436
                                PdoData.append((pdo, "Inputs"))
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   437
                                PDODataList.append(ExtractHexDecValue(pdo.getIndex().getcontent()))
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   438
                            for pdo in module.getRxPdo():
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   439
                                PdoData.append((pdo, "Outputs"))
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   440
                                PDODataList.append(ExtractHexDecValue(pdo.getIndex().getcontent()))
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   441
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   442
                for pdo, pdo_type in PdoData:
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   443
                    pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   444
                    pdos_index.append(pdo_index)
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   445
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   446
                    if PDODataList and (pdo_index in PDODataList):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   447
                        continue
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   448
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   449
                    excluded_list = pdo.getExclude()
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   450
                    if len(excluded_list) > 0:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   451
                        exclusion_list = [pdo_index]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   452
                        for excluded in excluded_list:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   453
                            exclusion_list.append(ExtractHexDecValue(excluded.getcontent()))
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   454
                        exclusion_list.sort()                     
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   455
                        exclusion_scope = exclusive_pdos.setdefault(tuple(exclusion_list), [])                   
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   456
                        entries = pdo.getEntry()
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   457
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   458
                        pdo_mapping_match = {
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   459
                            "index": pdo_index, 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   460
                            "matching": 0, 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   461
                            "count": len(entries), 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   462
                            "assigned": pdo.getSm() is not None
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   463
                        }
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   464
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   465
                        exclusion_scope.append(pdo_mapping_match)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   466
                        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   467
                        for entry in entries:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   468
                            index = ExtractHexDecValue(entry.getIndex().getcontent())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   469
                            subindex = ExtractHexDecValue(entry.getSubIndex())
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   470
                            if slave_variables.get((index, subindex), None) is not None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   471
                                pdo_mapping_match["matching"] += 1
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   472
                    
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   473
                        if pdo.getFixed() != True:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   474
                            pdo_mapping_match["matching"] += \
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   475
                                module_extra_params["max_pdo_size"] - \
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   476
                                pdo_mapping_match["count"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   477
                    
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   478
                    elif pdo.getMandatory():
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   479
                        selected_pdos.append(pdo_index)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   480
                
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   481
                excluded_pdos = []
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   482
                for exclusion_scope in exclusive_pdos.itervalues():
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   483
                    exclusion_scope.sort(ExclusionSortFunction)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   484
                    start_excluding_index = 0
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   485
                    if exclusion_scope[0]["matching"] > 0:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   486
                        selected_pdos.append(exclusion_scope[0]["index"])
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   487
                        start_excluding_index = 1
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   488
                    excluded_pdos.extend([pdo["index"] 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   489
                        for pdo in exclusion_scope[start_excluding_index:] 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   490
                        if PdoAssign or not pdo["assigned"]])
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   491
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   492
                # mod jblee
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   493
                #for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   494
                #                      [(pdo, "Outputs") for pdo in device.getRxPdo()]):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   495
                #for pdo, pdo_type in (TxPdoData + RxPdoData):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   496
                entry_check_list = []
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   497
                index_padding = 1
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   498
                for pdo, pdo_type in PdoData:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   499
                    entries = pdo.getEntry()                   
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   500
                    
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   501
                    pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   502
                    if pdo_index in excluded_pdos:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   503
                        continue
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   504
                    if PDODataList and (pdo_index not in PDODataList):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   505
                        continue
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   506
                    
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   507
                    #pdo_needed = pdo_index in selected_pdos
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   508
                    pdo_needed = pdo_index in PDODataList
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   509
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   510
                    if len(MDPData) > 0:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   511
                        pdo_index += index_padding
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   512
                        index_padding += 1
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   513
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   514
                    entries_infos = []                   
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   515
                    for entry in entries:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   516
                        index = ExtractHexDecValue(entry.getIndex().getcontent())
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   517
                        subindex = ExtractHexDecValue(entry.getSubIndex())
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   518
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   519
                        # add jblee
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   520
                        if len(MDPData) > 0:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   521
                            increse = self.Controler.CTNParent.GetMDPInfos(type_infos)                          
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   522
                            if increse and index != 0:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   523
                                index += int(increse[0][2]) * slotNumber
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   524
                                
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   525
                        entry_infos = {
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   526
                            "index": index,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   527
                            "subindex": subindex,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   528
                            "name": ExtractName(entry.getName()),
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   529
                            "bitlen": entry.getBitLen(),
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   530
                        }
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   531
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   532
                        entry_infos.update(type_infos)
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   533
                        #temp_data = "    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   534
                        check_data = "{0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}" % entry_infos
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   535
                        if entry_check_list and check_data in entry_check_list:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   536
                            if (entry_infos["index"] == 0) or (entry_infos["name"] == None):
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   537
                                pass
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   538
                            else: 
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   539
                                continue
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   540
                        entries_infos.append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   541
                        entry_check_list.append(check_data)
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   542
                        
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   543
                        entry_declaration = slave_variables.get((index, subindex), None)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   544
                        if entry_declaration is not None and not entry_declaration["mapped"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   545
                            pdo_needed = True
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   546
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   547
                            entry_infos.update(dict(zip(["var_type", "dir", "var_name", "no_decl", "extra_declarations"], 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   548
                                                        entry_declaration["infos"])))
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   549
                            entry_declaration["mapped"] = True
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   550
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   551
                            entry_type = entry.getDataType().getcontent()
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   552
                            if entry_infos["var_type"] != entry_type:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   553
                                message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   554
                                if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   555
                                    self.Controler.GetSizeOfType(entry_type)):
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   556
                                    raise ValueError, message
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   557
                                else:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   558
                                    self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n")
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   559
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   560
                            if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   561
                                entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   562
                                raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   563
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   564
                            ConfigureVariable(entry_infos, str_completion)
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   565
                            
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   566
                        elif pdo_type == "Outputs" and entry.getDataType() is not None and device_coe is not None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   567
                            data_type = entry.getDataType().getcontent()
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   568
                            entry_infos["dir"] = "Q"
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   569
                            entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   570
                            entry_infos["data_type"] = DATATYPECONVERSION.get(data_type)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   571
                            entry_infos["var_type"] = data_type
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   572
                            entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   573
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   574
                            ConfigureVariable(entry_infos, str_completion)
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   575
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   576
                            if entry_infos["data_type"] == "BIT" :
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   577
                                str_completion["slaves_output_pdos_default_values_extraction"] += \
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   578
                                    SLAVE_OUTPUT_PDO_DEFAULT_VALUE_BIT % entry_infos
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   579
                            else :
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   580
                                str_completion["slaves_output_pdos_default_values_extraction"] += \
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   581
                                    SLAVE_OUTPUT_PDO_DEFAULT_VALUE % entry_infos
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   582
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   583
                        elif pdo_type == "Inputs" and entry.getDataType() is not None and device_coe is not None:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   584
                            data_type = entry.getDataType().getcontent()
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   585
                            entry_infos["dir"] = "I"
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   586
                            entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8)
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   587
                            entry_infos["data_type"] = DATATYPECONVERSION.get(data_type)
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   588
                            entry_infos["var_type"] = data_type
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   589
                            entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   590
                            
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   591
                            ConfigureVariable(entry_infos, str_completion)
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   592
                            
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   593
                            str_completion["slaves_input_pdos_default_values_extraction"] += \
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   594
                                SLAVE_INPUT_PDO_DEFAULT_VALUE % entry_infos
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   595
                    
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   596
                    if pdo_needed:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   597
                        for excluded in pdo.getExclude():
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   598
                            excluded_index = ExtractHexDecValue(excluded.getcontent())
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   599
                            if excluded_index not in excluded_pdos:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   600
                                excluded_pdos.append(excluded_index)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   601
                        
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   602
                        ############################################################
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   603
                        sm = pdo.getSm()
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   604
                        if sm is None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   605
                            for sm_idx, sync_manager in enumerate(sync_managers):
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   606
                                if sync_manager["name"] == pdo_type:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   607
                                    sm = sm_idx
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   608
                        if sm is None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   609
                            raise ValueError, _("No sync manager available for %s pdo!") % pdo_type
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   610
                        
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   611
                        sync_managers[sm]["pdos_number"] += 1
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   612
                        sync_managers[sm]["pdos"].append(
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   613
                            {"slave": slave_idx,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   614
                             "index": pdo_index,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   615
                             "name": ExtractName(pdo.getName()),
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   616
                             "type": pdo_type, 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   617
                             "entries": entries_infos,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   618
                             "entries_number": len(entries_infos),
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   619
                             "fixed": pdo.getFixed() == True})
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   620
                        #############################################################
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   621
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   622
                    # for MDP
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   623
                    slotNumber += 1
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   624
            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   625
                if PdoConfig and PdoAssign:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   626
                    dynamic_pdos = {}
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   627
                    dynamic_pdos_number = 0
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   628
                    for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   629
                                                           ("Outputs", 0x1a00, 0x1C00)]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   630
                        for sync_manager in sync_managers:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   631
                            if sync_manager["name"] == category:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   632
                                category_infos = dynamic_pdos.setdefault(category, {})
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   633
                                category_infos["sync_manager"] = sync_manager
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   634
                                category_infos["pdos"] = [pdo for pdo in category_infos["sync_manager"]["pdos"] 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   635
                                                          if not pdo["fixed"] and pdo["type"] == category]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   636
                                category_infos["current_index"] = min_index
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   637
                                category_infos["max_index"] = max_index
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   638
                                break
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   639
                    
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   640
                    for (index, subindex), entry_declaration in slave_variables.iteritems():
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   641
                        
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   642
                        if not entry_declaration["mapped"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   643
                            entry = device_entries.get((index, subindex), None)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   644
                            if entry is None:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   645
                                raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   646
                                                 (index, subindex, type_infos["device_type"])
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   647
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   648
                            entry_infos = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   649
                                "index": index,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   650
                                "subindex": subindex,
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   651
                                "name": entry["Name"],
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   652
                                "bitlen": entry["BitSize"],
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   653
                            }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   654
                            entry_infos.update(type_infos)
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   655
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   656
                            entry_infos.update(dict(zip(["var_type", "dir", "var_name", "no_decl", "extra_declarations"], 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   657
                                                        entry_declaration["infos"])))
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   658
                            entry_declaration["mapped"] = True
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   659
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   660
                            if entry_infos["var_type"] != entry["Type"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   661
                                message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   662
                                if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   663
                                    self.Controler.GetSizeOfType(entry["Type"])):
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   664
                                    raise ValueError, message
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   665
                                else:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   666
                                    self.Controler.GetCTRoot().logger.write_warning(message + "\n")
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   667
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   668
                            if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   669
                                pdo_type = "Inputs"
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   670
                            elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   671
                                pdo_type = "Outputs"
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   672
                            else:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   673
                                raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   674
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   675
                            if not dynamic_pdos.has_key(pdo_type):
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   676
                                raise ValueError, _("No Sync manager defined for %s!") % pdo_type
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   677
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   678
                            ConfigureVariable(entry_infos, str_completion)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   679
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   680
                            if len(dynamic_pdos[pdo_type]["pdos"]) > 0:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   681
                                pdo = dynamic_pdos[pdo_type]["pdos"][0]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   682
                            elif module_extra_params["add_pdo"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   683
                                while dynamic_pdos[pdo_type]["current_index"] in pdos_index:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   684
                                    dynamic_pdos[pdo_type]["current_index"] += 1
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   685
                                if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_index"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   686
                                    raise ValueError, _("No more free PDO index available for %s!") % pdo_type
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   687
                                pdos_index.append(dynamic_pdos[pdo_type]["current_index"])
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   688
                                
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   689
                                dynamic_pdos_number += 1
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   690
                                pdo = {"slave": slave_idx,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   691
                                       "index": dynamic_pdos[pdo_type]["current_index"],
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   692
                                       "name": "Dynamic PDO %d" % dynamic_pdos_number,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   693
                                       "type": pdo_type, 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   694
                                       "entries": [],
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   695
                                       "entries_number": 0,
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   696
                                       "fixed": False}
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   697
                                dynamic_pdos[pdo_type]["sync_manager"]["pdos_number"] += 1
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   698
                                dynamic_pdos[pdo_type]["sync_manager"]["pdos"].append(pdo)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   699
                                dynamic_pdos[pdo_type]["pdos"].append(pdo)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   700
                            else:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   701
                                break
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   702
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   703
                            pdo["entries"].append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   704
                            if entry_infos["bitlen"] < module_extra_params["pdo_alignment"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   705
                                pdo["entries"].append("    {0x0000, 0x00, %d}, /* None */" % (
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   706
                                        module_extra_params["pdo_alignment"] - entry_infos["bitlen"]))
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   707
                            pdo["entries_number"] += 1
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   708
                            
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   709
                            if pdo["entries_number"] == module_extra_params["max_pdo_size"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   710
                                dynamic_pdos[pdo_type]["pdos"].pop(0)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   711
                
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   712
                pdo_offset = 0
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   713
                entry_offset = 0
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   714
                slotNumber = 1
2144
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   715
                for sync_manager_infos in sync_managers:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   716
                    for pdo_infos in sync_manager_infos["pdos"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   717
                        pdo_infos["offset"] = entry_offset
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   718
                        pdo_entries = pdo_infos["entries"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   719
                        pdos_infos["pdos_infos"].append(
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   720
                            ("    {0x%(index).4x, %(entries_number)d, " + 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   721
                             "slave_%(slave)d_pdo_entries + %(offset)d}, /* %(name)s */") % pdo_infos)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   722
                        entry_offset += len(pdo_entries)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   723
                        pdos_infos["pdos_entries_infos"].extend(pdo_entries)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   724
                    
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   725
                    sync_manager_infos["offset"] = pdo_offset
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   726
                    pdo_offset_shift = sync_manager_infos["pdos_number"]
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   727
                    pdos_infos["pdos_sync_infos"].append(
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   728
                        ("    {%(index)d, %(sync_manager_type)s, %(pdos_number)d, " + 
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   729
                         ("slave_%(slave)d_pdos + %(offset)d" if pdo_offset_shift else "NULL") +
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   730
                         ", %(watchdog)s},") % sync_manager_infos)
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   731
                    pdo_offset += pdo_offset_shift  
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   732
                
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   733
                for element in ["pdos_entries_infos", "pdos_infos", "pdos_sync_infos"]:
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   734
                    pdos_infos[element] = "\n".join(pdos_infos[element])
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   735
                
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   736
                str_completion["pdos_configuration_declaration"] += SLAVE_PDOS_CONFIGURATION_DECLARATION % pdos_infos
bbd78ac226d0 Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents: 2140
diff changeset
   737
            
2641
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   738
            #for (index, subindex), entry_declaration in slave_variables.iteritems():
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   739
            #    if not entry_declaration["mapped"]:
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   740
            #        message = _("Entry index 0x%4.4x, subindex 0x%2.2x not mapped for device %s") % \
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   741
            #                        (index, subindex, type_infos["device_type"])
c9deff128c37 EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2165
diff changeset
   742
            #        self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n")
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   743
                    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   744
        for element in ["used_pdo_entry_offset_variables_declaration", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   745
                        "used_pdo_entry_configuration", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   746
                        "located_variables_declaration", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   747
                        "retrieve_variables", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   748
                        "publish_variables"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   749
            str_completion[element] = "\n".join(str_completion[element])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   750
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   751
        etherlabfile = open(filepath, 'w')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   752
        etherlabfile.write(plc_etherlab_code % str_completion)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   753
        etherlabfile.close()