edouard@2165: #!/usr/bin/env python
edouard@2165: # -*- coding: utf-8 -*-
edouard@2165:
edouard@2165: # This file is part of Beremiz
edouard@2165: #
edouard@2165: # Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT
edouard@2165: # RTES Lab : CRKim, JBLee, youcu
edouard@2165: # Higen Motor : Donggu Kang
edouard@2165: #
edouard@2165: # See COPYING file for copyrights details.
edouard@2165:
Laurent@2111: import os
Laurent@2111:
Laurent@2111: import wx
Laurent@2111:
edouard@2641: from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, \
edouard@2641: LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
Laurent@2111:
Laurent@2111: from MotionLibrary import Headers, AxisXSD
Edouard@2152: from EthercatSlave import _EthercatSlaveCTN, _CommonSlave
Laurent@2111: from ConfigEditor import CIA402NodeEditor
Laurent@2111:
edouard@2641: #HSAHN 2015.07.26
edouard@2641: #remove NODE_VARIABLES's optional items.
edouard@2641: #As for now, optional items will be added dynamicaly.
Laurent@2111: NODE_VARIABLES = [
edouard@2641: ("ControlWord", 0x6040, 0x00, "UINT", "Q"),
edouard@2641: ("ModesOfOperation", 0x6060, 0x00, "SINT", "Q"),
edouard@2641: ("StatusWord", 0x6041, 0x00, "UINT", "I"),
Laurent@2153: ("ModesOfOperationDisplay", 0x6061, 0x00, "SINT", "I"),
Laurent@2111: ]
Laurent@2111:
edouard@2641: #HSAHN 2015.07.26
edouard@2641: #reference variable
edouard@2641: ADD_NODE_VARIABLES = ({'name':"TargetPosition" , 'index':0x607a, 'sub-index':0x00, 'type':"DINT", 'direction':"Q"},
edouard@2641: {'name':"TargetVelocity" , 'index':0x60ff, 'sub-index':0x00, 'type':"DINT", 'direction':"Q"},
edouard@2641: {'name':"TargetTorque" , 'index':0x6071, 'sub-index':0x00, 'type':"INT", 'direction':"Q"},
edouard@2641: {'name':"ActualPosition" , 'index':0x6064, 'sub-index':0x00, 'type':"DINT", 'direction':"I"},
edouard@2641: {'name':"ActualVelocity" , 'index':0x606c, 'sub-index':0x00, 'type':"DINT", 'direction':"I"},
edouard@2641: {'name':"ActualTorque" , 'index':0x6077, 'sub-index':0x00, 'type':"INT", 'direction':"I"})
edouard@2641:
edouard@2641: DEFAULT_RETRIEVE = " __CIA402Node_%(location)s.axis->%(name)s = *(__CIA402Node_%(location)s.%(name)s);"
edouard@2641: DEFAULT_PUBLISH = " *(__CIA402Node_%(location)s.%(name)s) = __CIA402Node_%(location)s.axis->%(name)s;"
edouard@2641:
Laurent@2153: # Definition of optional node variables that can be added to PDO mapping.
Laurent@2153: # A checkbox will be displayed for each section in node configuration panel to
Laurent@2153: # enable them
Laurent@2153: # [(section_name,
Laurent@2153: # [{'description', (name, index, subindex, type,
Laurent@2153: # direction for master ('I': input, 'Q': output)),
Laurent@2153: # 'retrieve', string_template_for_retrieve_variable (None: not retrieved,
Laurent@2153: # default string template if not defined),
Laurent@2153: # 'publish', string_template_for_publish_variable (None: not published,
Laurent@2153: # default string template if not defined),
Laurent@2153: # },...]
edouard@2641:
Laurent@2111: EXTRA_NODE_VARIABLES = [
Laurent@2111: ("ErrorCode", [
Laurent@2111: {"description": ("ErrorCode", 0x603F, 0x00, "UINT", "I"),
Laurent@2111: "publish": None}
Laurent@2111: ]),
Laurent@2111: ("DigitalInputs", [
Laurent@2111: {"description": ("DigitalInputs", 0x60FD, 0x00, "UDINT", "I"),
Laurent@2111: "publish": None}
Laurent@2111: ]),
Laurent@2111: ("DigitalOutputs", [
edouard@2641: {"description": ("DigitalOutputs", 0x60FE, 0x01, "UDINT", "I"),
edouard@2641: "publish": None}
Laurent@2146: ]),
Laurent@2146: ("TouchProbe", [
Laurent@2146: {"description": ("TouchProbeFunction", 0x60B8, 0x00, "UINT", "Q"),
Laurent@2146: "retrieve": None},
Laurent@2146: {"description": ("TouchProbeStatus", 0x60B9, 0x00, "UINT", "I"),
Laurent@2146: "publish": None},
Laurent@2146: {"description": ("TouchProbePos1PosValue", 0x60BA, 0x00, "DINT", "I"),
Laurent@2146: "publish": None},
Laurent@2146: {"description": ("TouchProbePos1NegValue", 0x60BB, 0x00, "DINT", "I"),
Laurent@2146: "publish": None},
Laurent@2146: ]),
Laurent@2111: ]
Laurent@2153:
Laurent@2153: # List of parameters name in no configuration panel for optional variable
Laurent@2153: # sections
Laurent@2153: EXTRA_NODE_VARIABLES_DICT = {
Laurent@2153: "Enable" + name: params
Laurent@2153: for name, params in EXTRA_NODE_VARIABLES}
Laurent@2153:
edouard@2641: BLOCK_INPUT_TEMPLATE = " __SET_VAR(%(blockname)s->,%(input_name)s, %(input_value)s);"
edouard@2641: BLOCK_OUTPUT_TEMPLATE = " __SET_VAR(data__->,%(output_name)s, __GET_VAR(%(blockname)s->%(output_name)s));"
edouard@2641:
edouard@2641: BLOCK_FUNCTION_TEMPLATE = """
edouard@2641: extern void ETHERLAB%(ucase_blocktype)s_body__(ETHERLAB%(ucase_blocktype)s* data__);
edouard@2641: void __%(blocktype)s_%(location)s(MC_%(ucase_blocktype)s *data__) {
edouard@2641: __DECLARE_GLOBAL_PROTOTYPE(ETHERLAB%(ucase_blocktype)s, %(blockname)s);
edouard@2641: ETHERLAB%(ucase_blocktype)s* %(blockname)s = __GET_GLOBAL_%(blockname)s();
edouard@2641: __SET_VAR(%(blockname)s->, POS, AxsPub.axis->NetworkPosition);
edouard@2641: %(extract_inputs)s
edouard@2641: ETHERLAB%(ucase_blocktype)s_body__(%(blockname)s);
edouard@2641: %(return_outputs)s
edouard@2641: }
edouard@2641: """
edouard@2641:
edouard@2641: BLOCK_FUNTION_DEFINITION_TEMPLATE = " __CIA402Node_%(location)s.axis->__mcl_func_MC_%(blocktype)s = __%(blocktype)s_%(location)s;"
edouard@2641:
Laurent@2153: FIELDBUS_INTERFACE_GLOBAL_INSTANCES = [
Laurent@2111: {"blocktype": "GetTorqueLimit",
Laurent@2111: "inputs": [],
Laurent@2111: "outputs": [{"name": "TorqueLimitPos", "type": "UINT"},
Laurent@2111: {"name": "TorqueLimitNeg", "type": "UINT"}]},
Laurent@2111: {"blocktype": "SetTorqueLimit",
Laurent@2111: "inputs": [{"name": "TorqueLimitPos", "type": "UINT"},
Laurent@2111: {"name": "TorqueLimitNeg", "type": "UINT"}],
Laurent@2111: "outputs": []},
Laurent@2111: ]
Laurent@2111:
edouard@2641: # add jblee
edouard@2641: MODEOFOP_HOMING_METHOD_TEMPLATE = """
edouard@2641: if(*(AxsPub.ModesOfOperation) == 0x06){
edouard@2641: IEC_BOOL homing = AxsPub.axis->HomingOperationStart;
edouard@2641: if(power){
edouard@2641: if (homing)
edouard@2641: CW |= Homing_OperationStart_Origin;
edouard@2641: else
edouard@2641: CW &= ~(Homing_OperationStart_Origin);
edouard@2641: }
edouard@2641: else{
edouard@2641: if (homing)
edouard@2641: CW |= Homing_OperationStart_Edit;
edouard@2641: else
edouard@2641: CW &= ~(EnableOperation);
edouard@2641: }
edouard@2641:
edouard@2641: }
edouard@2641: """
edouard@2641:
edouard@2641: MODEOFOP_COMPUTATION_MODE_TEMPLATE = """
edouard@2641: switch (AxsPub.axis->AxisMotionMode) {
edouard@2641: //ssh_add
edouard@2641: case mc_mode_hm:
edouard@2641: *(AxsPub.ModesOfOperation) = 0x06;
edouard@2641: break;
edouard@2641: case mc_mode_cst:
edouard@2641: *(AxsPub.ModesOfOperation) = 0x0a;
edouard@2641: break;
edouard@2641: case mc_mode_csv:
edouard@2641: *(AxsPub.ModesOfOperation) = 0x09;
edouard@2641: break;
edouard@2641: default:
edouard@2641: *(AxsPub.ModesOfOperation) = 0x08;
edouard@2641: break;
edouard@2641: }
edouard@2641: """
edouard@2641:
Laurent@2111: #--------------------------------------------------
Laurent@2111: # Ethercat CIA402 Node
Laurent@2111: #--------------------------------------------------
Laurent@2111:
Laurent@2111: class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
Laurent@2111: XSD = """
Laurent@2111:
Laurent@2111:
Laurent@2111:
Laurent@2111: %s
Laurent@2111:
Laurent@2111:
Laurent@2111:
Laurent@2153: """ % ("\n".join(["""\
Laurent@2153: """ % category
Laurent@2153: for category, variables in EXTRA_NODE_VARIABLES]) + AxisXSD)
Laurent@2111:
Laurent@2111: NODE_PROFILE = 402
Laurent@2111: EditorType = CIA402NodeEditor
Laurent@2111:
Laurent@2111: ConfNodeMethods = [
Laurent@2111: {"bitmap" : "CIA402AxisRef",
Laurent@2111: "name" : _("Axis Ref"),
Laurent@2111: "tooltip" : _("Initiate Drag'n drop of Axis ref located variable"),
Laurent@2111: "method" : "_getCIA402AxisRef",
Laurent@2111: "push": True},
Laurent@2154: {"bitmap" : "CIA402NetPos",
Laurent@2154: "name" : _("Axis Pos"),
Laurent@2154: "tooltip" : _("Initiate Drag'n drop of Network position located variable"),
Laurent@2154: "method" : "_getCIA402NetworkPosition",
Laurent@2154: "push": True},
Laurent@2153: ]
Edouard@2152:
Edouard@2152: #--------------------------------------------------
Edouard@2152: # class code
Edouard@2152: #--------------------------------------------------
Edouard@2152:
Edouard@2152: def __init__(self):
Edouard@2152: # ----------- call ethercat mng. function --------------
Edouard@2152: self.CommonMethod = _CommonSlave(self)
Laurent@2111:
edouard@2641: #HSAHN
edouard@2641: # Select PDO Mapping
edouard@2641: self.SelectedPDOIndex = []
edouard@2641: self.SelectedRxPDOIndex = []
edouard@2641: self.SelectedTxPDOIndex = []
edouard@2641: #HSAHN END
edouard@2641:
Laurent@2111: def GetIconName(self):
Laurent@2111: return "CIA402Slave"
Laurent@2111:
Laurent@2111: def SetParamsAttribute(self, path, value):
Laurent@2111: if path == "CIA402SlaveParams.Type":
Laurent@2111: path = "SlaveParams.Type"
Laurent@2111: elif path == "CIA402SlaveParams.Alias":
Laurent@2111: path = "SlaveParams.Alias"
Laurent@2111: return _EthercatSlaveCTN.SetParamsAttribute(self, path, value)
Laurent@2111:
Laurent@2111: def GetVariableLocationTree(self):
Laurent@2111: axis_name = self.CTNName()
Laurent@2111: current_location = self.GetCurrentLocation()
Laurent@2155: children = [{"name": name_frmt % (axis_name),
Laurent@2154: "type": LOCATION_VAR_INPUT,
Laurent@2154: "size": "W",
Laurent@2155: "IEC_type": iec_type,
Laurent@2155: "var_name": var_name_frmt % axis_name,
Laurent@2155: "location": location_frmt % (
Laurent@2155: ".".join(map(str, current_location))),
Laurent@2154: "description": "",
Laurent@2155: "children": []}
Laurent@2155: for name_frmt, iec_type, var_name_frmt, location_frmt in
Laurent@2155: [("%s Network Position", "UINT", "%s_pos", "%%IW%s"),
Laurent@2155: ("%s Axis Ref", "AXIS_REF", "%s", "%%IW%s.402")]]
Laurent@2155: children.extend(self.CTNParent.GetDeviceLocationTree(
Laurent@2155: self.GetSlavePos(), current_location, axis_name))
Laurent@2111: return {"name": axis_name,
Laurent@2111: "type": LOCATION_CONFNODE,
Laurent@2111: "location": self.GetFullIEC_Channel(),
Laurent@2111: "children": children,
Laurent@2111: }
Laurent@2111:
Laurent@2111: def CTNGlobalInstances(self):
Laurent@2111: current_location = self.GetCurrentLocation()
Laurent@2153: return [("%s_%s" % (block_infos["blocktype"],
Laurent@2153: "_".join(map(str, current_location))),
Laurent@2153: "EtherLab%s" % block_infos["blocktype"], "")
Laurent@2153: for block_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES]
Laurent@2111:
Laurent@2154: def StartDragNDrop(self, data):
Laurent@2154: data_obj = wx.TextDataObject(str(data))
Laurent@2154: dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
Laurent@2154: dragSource.SetData(data_obj)
Laurent@2154: dragSource.DoDragDrop()
Laurent@2154:
Laurent@2154: def _getCIA402NetworkPosition(self):
Laurent@2154: self.StartDragNDrop(
Laurent@2154: ("%%IW%s" % ".".join(map(str, self.GetCurrentLocation())),
Laurent@2154: "location", "UINT", self.CTNName() + "_Pos", ""))
Laurent@2154:
Laurent@2111: def _getCIA402AxisRef(self):
Laurent@2154: self.StartDragNDrop(
Laurent@2154: ("%%IW%s.402" % ".".join(map(str, self.GetCurrentLocation())),
Laurent@2154: "location", "AXIS_REF", self.CTNName(), ""))
edouard@2641:
edouard@2641: # add jblee
edouard@2641: """
edouard@2641: def LoadPDOSelectData(self):
edouard@2641: ReadData = []
edouard@2641: files = os.listdir(self.CTNPath())
edouard@2641: filepath = os.path.join(self.CTNPath(), "DataForPDO.txt")
edouard@2641: if os.path.isfile(filepath):
edouard@2641: PDODataRead = open(filepath, 'r')
edouard@2641: ReadData = PDODataRead.readlines()
edouard@2641: PDODataRead.close()
edouard@2641:
edouard@2641: if len(ReadData) > 1:
edouard@2641: for data in ReadData[0].split() :
edouard@2641: if data == "RxPDO":
edouard@2641: continue
edouard@2641: self.SelectedRxPDOIndex.append(int(data, 0))
edouard@2641:
edouard@2641: for data in ReadData[1].split() :
edouard@2641: if data == "TxPDO":
edouard@2641: continue
edouard@2641: self.SelectedTxPDOIndex.append(int(data, 0))
edouard@2641: """
edouard@2641:
edouard@2641: def LoadPDOSelectData(self):
edouard@2641: RxPDOData = self.BaseParams.getRxPDO()
edouard@2641: RxPDOs = []
edouard@2641: if RxPDOData != "None":
edouard@2641: RxPDOs = RxPDOData.split()
edouard@2641: if RxPDOs :
edouard@2641: for RxPDO in RxPDOs :
edouard@2641: self.SelectedRxPDOIndex.append(int(RxPDO, 0))
edouard@2641:
edouard@2641: TxPDOData = self.BaseParams.getTxPDO()
edouard@2641: TxPDOs = []
edouard@2641: if TxPDOData != "None":
edouard@2641: TxPDOs = TxPDOData.split()
edouard@2641: if TxPDOs :
edouard@2641: for TxPDO in TxPDOs :
edouard@2641: self.SelectedTxPDOIndex.append(int(TxPDO, 0))
edouard@2641:
edouard@2641: def LoadDefaultPDOSet(self):
edouard@2641: ReturnData = []
edouard@2641: rx_pdo_entries = self.CommonMethod.GetRxPDOCategory()
edouard@2641: if len(rx_pdo_entries):
edouard@2641: for i in range(len(rx_pdo_entries)):
edouard@2641: if rx_pdo_entries[i]['sm'] is not None:
edouard@2641: ReturnData.append(rx_pdo_entries[i]['pdo_index'])
edouard@2641:
edouard@2641: tx_pdo_entries = self.CommonMethod.GetTxPDOCategory()
edouard@2641: if len(tx_pdo_entries):
edouard@2641: for i in range(len(tx_pdo_entries)):
edouard@2641: if tx_pdo_entries[i]['sm'] is not None:
edouard@2641: ReturnData.append(tx_pdo_entries[i]['pdo_index'])
edouard@2641:
edouard@2641: if ReturnData :
edouard@2641: return ReturnData
edouard@2641: else :
edouard@2641: return [5632, 6656]
Laurent@2154:
Laurent@2111: def CTNGenerate_C(self, buildpath, locations):
Laurent@2111: current_location = self.GetCurrentLocation()
Laurent@2111:
Laurent@2111: location_str = "_".join(map(lambda x:str(x), current_location))
edouard@2641:
edouard@2641: plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_cia402node.c")
Laurent@2111: plc_cia402node_file = open(plc_cia402node_filepath, 'r')
Laurent@2111: plc_cia402node_code = plc_cia402node_file.read()
Laurent@2111: plc_cia402node_file.close()
edouard@2641: # HSAHN 150726
edouard@2641: # add "default_variables_retrieve": [], "default_variables_publish": [],
edouard@2641: # As PDO mapping object, it will add auto-complete code.
edouard@2641: # add "modeofop_homing_method", "modeofop_computation_mode" by jblee
edouard@2641: str_completion = {
edouard@2641: "slave_pos": self.GetSlavePos(),
edouard@2641: "location": location_str,
edouard@2641: "MCL_headers": Headers,
edouard@2641: "extern_located_variables_declaration": [],
edouard@2641: "fieldbus_interface_declaration": [],
edouard@2641: "fieldbus_interface_definition": [],
edouard@2641: "entry_variables": [],
edouard@2641: "init_axis_params": [],
edouard@2641: "init_entry_variables": [],
edouard@2641: "default_variables_retrieve": [],
edouard@2641: "default_variables_publish": [],
edouard@2641: "extra_variables_retrieve": [],
edouard@2641: "extra_variables_publish": [],
edouard@2641: "modeofop_homing_method": [],
edouard@2641: "modeofop_computation_mode": []
edouard@2641: }
edouard@2641:
Laurent@2153: for blocktype_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES:
edouard@2641: texts = {
edouard@2641: "blocktype": blocktype_infos["blocktype"],
edouard@2641: "ucase_blocktype": blocktype_infos["blocktype"].upper(),
edouard@2641: "location": "_".join(map(str, current_location))
edouard@2641: }
edouard@2641: texts["blockname"] = "%(ucase_blocktype)s_%(location)s" % texts
Laurent@2153:
edouard@2641: inputs = [{"input_name": "POS", "input_value": str(self.GetSlavePos())},
edouard@2641: {"input_name": "EXECUTE", "input_value": "__GET_VAR(data__->EXECUTE)"}] +\
edouard@2641: [{"input_name": input["name"].upper(),
edouard@2641: "input_value": "__GET_VAR(data__->%s)" % input["name"].upper()}
edouard@2641: for input in blocktype_infos["inputs"]]
edouard@2641: input_texts = []
edouard@2641: for input_infos in inputs:
edouard@2641: input_infos.update(texts)
edouard@2641: input_texts.append(BLOCK_INPUT_TEMPLATE % input_infos)
edouard@2641: texts["extract_inputs"] = "\n".join(input_texts)
Laurent@2153:
edouard@2641: outputs = [{"output_name": output} for output in ["DONE", "BUSY", "ERROR"]] + \
edouard@2641: [{"output_name": output["name"].upper()} for output in blocktype_infos["outputs"]]
edouard@2641: output_texts = []
edouard@2641: for output_infos in outputs:
edouard@2641: output_infos.update(texts)
edouard@2641: output_texts.append(BLOCK_OUTPUT_TEMPLATE % output_infos)
edouard@2641: texts["return_outputs"] = "\n".join(output_texts)
Laurent@2153:
edouard@2641: str_completion["fieldbus_interface_declaration"].append(
edouard@2641: BLOCK_FUNCTION_TEMPLATE % texts)
edouard@2641:
edouard@2641: str_completion["fieldbus_interface_definition"].append(
edouard@2641: BLOCK_FUNTION_DEFINITION_TEMPLATE % texts)
edouard@2641:
edouard@2641: variables = NODE_VARIABLES[:]
edouard@2641:
edouard@2641: #HSAHN
edouard@2641: #2015. 7. 24 PDO Variable
edouard@2641: #if PDO is not selected, use 1st PDO set
edouard@2641: self.LoadPDOSelectData()
edouard@2641: if not self.SelectedRxPDOIndex and not self.SelectedTxPDOIndex :
edouard@2641: self.SelectedPDOIndex = self.LoadDefaultPDOSet()
edouard@2641: else :
edouard@2641: self.SelectedPDOIndex = self.SelectedRxPDOIndex + self.SelectedTxPDOIndex
edouard@2641:
edouard@2641: add_idx = []
edouard@2641: for i in range(len(ADD_NODE_VARIABLES)):
edouard@2641: add_idx.append(ADD_NODE_VARIABLES[i]['index'])
edouard@2641:
edouard@2641: self.CommonMethod.RequestPDOInfo()
edouard@2641: pdo_info = self.CommonMethod.GetRxPDOCategory() + self.CommonMethod.GetTxPDOCategory()
edouard@2641: pdo_entry = self.CommonMethod.GetRxPDOInfo() + self.CommonMethod.GetTxPDOInfo()
edouard@2641: list_index = 0
edouard@2641: ModeOfOpFlag = False
edouard@2641: ModeOfOpDisplayFlag = False
edouard@2641: for i in range(len(pdo_info)):
edouard@2641: #if pdo_index is in the SelectedPDOIndex: put the PDO mapping information intto the "used" object
edouard@2641: if pdo_info[i]['pdo_index'] in self.SelectedPDOIndex:
edouard@2641: used = pdo_entry[list_index:list_index + pdo_info[i]['number_of_entry']]
edouard@2641: for used_data in used:
edouard@2641: # 24672 -> 0x6060, Mode of Operation
edouard@2641: if used_data['entry_index'] == 24672:
edouard@2641: ModeOfOpFlag = True
edouard@2641: # 24673 -> 0x6061, Mode of Operation Display
edouard@2641: elif used_data["entry_index"] == 24673:
edouard@2641: ModeOfOpDisplayFlag = True
edouard@2641:
edouard@2641: if used_data['entry_index'] in add_idx:
edouard@2641: idx = add_idx.index(used_data['entry_index'])
edouard@2641: adder = list([ADD_NODE_VARIABLES[idx]['name'], ADD_NODE_VARIABLES[idx]['index'], \
edouard@2641: ADD_NODE_VARIABLES[idx]['sub-index'], ADD_NODE_VARIABLES[idx]['type'], \
edouard@2641: ADD_NODE_VARIABLES[idx]['direction']])
edouard@2641: variables.append(adder)
edouard@2641: if ADD_NODE_VARIABLES[idx]['direction'] == "Q":
edouard@2641: parsed_string = ADD_NODE_VARIABLES[idx]['name'].replace("Target", "")
edouard@2641: # add jblee
edouard@2641: check_q_data = " *(AxsPub.Target%s) = AxsPub.axis->Raw%sSetPoint;" %(parsed_string, parsed_string)
edouard@2641: if check_q_data not in str_completion["default_variables_publish"]:
edouard@2641: str_completion["default_variables_publish"].append(check_q_data)
edouard@2641: elif ADD_NODE_VARIABLES[idx]['direction'] == "I":
edouard@2641: parsed_string = ADD_NODE_VARIABLES[idx]['name'].replace("Actual", "")
edouard@2641: # add jblee
edouard@2641: check_i_data = " AxsPub.axis->ActualRaw%s = *(AxsPub.Actual%s);" %(parsed_string, parsed_string)
edouard@2641: if check_i_data not in str_completion["default_variables_retrieve"]:
edouard@2641: str_completion["default_variables_retrieve"].append(check_i_data)
edouard@2641: list_index += pdo_info[i]['number_of_entry']
edouard@2641: #HSAHN END
edouard@2641:
edouard@2641: params = self.CTNParams[1].getElementInfos(self.CTNParams[0])
edouard@2641: for param in params["children"]:
edouard@2641: if param["name"] in EXTRA_NODE_VARIABLES_DICT:
edouard@2641: if param["value"]:
edouard@2641: extra_variables = EXTRA_NODE_VARIABLES_DICT.get(param["name"])
edouard@2641: for variable_infos in extra_variables:
edouard@2641: var_infos = {
edouard@2641: "location": location_str,
edouard@2641: "name": variable_infos["description"][0]
edouard@2641: }
edouard@2641: variables.append(variable_infos["description"])
edouard@2641: retrieve_template = variable_infos.get("retrieve", DEFAULT_RETRIEVE)
edouard@2641: publish_template = variable_infos.get("publish", DEFAULT_PUBLISH)
Laurent@2153:
edouard@2641: if retrieve_template is not None:
edouard@2641: str_completion["extra_variables_retrieve"].append(
edouard@2641: retrieve_template % var_infos)
edouard@2641: if publish_template is not None:
edouard@2641: str_completion["extra_variables_publish"].append(
edouard@2641: publish_template % var_infos)
edouard@2641:
edouard@2641: #elif param["value"] is not None:
Laurent@2155: if param["value"] is not None:
edouard@2641: param_infos = {
edouard@2641: "location": location_str,
edouard@2641: "param_name": param["name"],
edouard@2641: }
edouard@2641: if param["type"] == "boolean":
edouard@2641: param_infos["param_value"] = {True: "1", False: "0"}[param["value"]]
edouard@2641: param_infos["param_name"] = param["name"].replace("Enable", "") + "Enabled"
edouard@2641: if param["value"] == False:
edouard@2641: continue
edouard@2641: else:
edouard@2641: param_infos["param_value"] = str(param["value"])
edouard@2641: # param_name = param_name.replace("Enable", "") + "Enabled"
edouard@2641: str_completion["init_axis_params"].append(
edouard@2641: " __CIA402Node_%(location)s.axis->%(param_name)s = %(param_value)s;" % param_infos)
edouard@2641:
edouard@2641: check_variable = []
edouard@2641: for variable in variables:
edouard@2641: # add jblee
edouard@2641: if variable in check_variable:
edouard@2641: continue
edouard@2641:
edouard@2641: var_infos = dict(zip(["name", "index", "subindex", "var_type", "dir"], variable))
edouard@2641: var_infos["location"] = location_str
edouard@2641: var_infos["var_size"] = self.GetSizeOfType(var_infos["var_type"])
edouard@2641: var_infos["var_name"] = "__%(dir)s%(var_size)s%(location)s_%(index)d_%(subindex)d" % var_infos
edouard@2641:
edouard@2641: # add jblee
edouard@2641: if var_infos["index"] in [24672] and ModeOfOpFlag:
edouard@2641: str_completion["modeofop_homing_method"].append(MODEOFOP_HOMING_METHOD_TEMPLATE)
edouard@2641: str_completion["modeofop_computation_mode"].append(MODEOFOP_COMPUTATION_MODE_TEMPLATE)
edouard@2641:
edouard@2641: # add jblee
edouard@2641: if var_infos["index"] in [24672, 24673] and (not ModeOfOpFlag or not ModeOfOpDisplayFlag):
edouard@2641: continue
edouard@2641:
edouard@2641: str_completion["extern_located_variables_declaration"].append(
edouard@2641: "IEC_%(var_type)s *%(var_name)s;" % var_infos)
edouard@2641: str_completion["entry_variables"].append(
edouard@2641: " IEC_%(var_type)s *%(name)s;" % var_infos)
edouard@2641: str_completion["init_entry_variables"].append(
edouard@2641: " __CIA402Node_%(location)s.%(name)s = %(var_name)s;" % var_infos)
Laurent@2111:
Laurent@2111: self.CTNParent.FileGenerator.DeclareVariable(
edouard@2641: self.GetSlavePos(), var_infos["index"], var_infos["subindex"],
edouard@2641: var_infos["var_type"], var_infos["dir"], var_infos["var_name"])
edouard@2641:
edouard@2641: # add jblee
edouard@2641: check_variable.append(variable)
edouard@2641:
edouard@2641: for element in ["extern_located_variables_declaration",
edouard@2641: "fieldbus_interface_declaration",
edouard@2641: "fieldbus_interface_definition",
edouard@2641: "entry_variables",
edouard@2641: "init_axis_params",
edouard@2641: "init_entry_variables",
edouard@2641: "default_variables_retrieve",
edouard@2641: "default_variables_publish",
edouard@2641: "extra_variables_retrieve",
edouard@2641: "extra_variables_publish",
edouard@2641: "modeofop_homing_method",
edouard@2641: "modeofop_computation_mode"]:
edouard@2641: str_completion[element] = "\n".join(str_completion[element])
edouard@2641:
edouard@2641: Gen_CIA402Nodefile_path = os.path.join(buildpath, "cia402node_%s.c"%location_str)
Laurent@2111: cia402nodefile = open(Gen_CIA402Nodefile_path, 'w')
edouard@2641: cia402nodefile.write(plc_cia402node_code % str_completion)
Laurent@2111: cia402nodefile.close()
Laurent@2111:
Laurent@2111: return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))],"",True
edouard@2641: