modbus/modbus.py
changeset 2713 680ea4684209
parent 2663 54f5b8e5c8d2
child 2714 0b636dc947a2
equal deleted inserted replaced
2667:253110ba0fd7 2713:680ea4684209
   129         #          %QX1.2.3.2
   129         #          %QX1.2.3.2
   130         #            ..
   130         #            ..
   131         #          %QX1.2.3.n
   131         #          %QX1.2.3.n
   132         entries = []
   132         entries = []
   133         entries.append({
   133         entries.append({
   134             "name": "Exec. request flag",
   134             "name": "Execute request flag",
   135             "type": LOCATION_VAR_MEMORY,
   135             "type": LOCATION_VAR_MEMORY,
   136             "size": 1,           # BOOL flag
   136             "size": 1,           # BOOL flag
   137             "IEC_type": "BOOL",  # BOOL flag
   137             "IEC_type": "BOOL",  # BOOL flag
   138             "var_name": "var_name",
   138             "var_name": "var_name",
   139             "location": "X" + ".".join([str(i) for i in current_location]) + ".0.0",
   139             "location": "X" + ".".join([str(i) for i in current_location]) + ".0.0",
   140             "description": "MB request execution control flag",
   140             "description": "Modbus request execution control flag",
       
   141             "children": []})        
       
   142         entries.append({
       
   143             "name": "Request Status flag",
       
   144             "type": LOCATION_VAR_MEMORY,
       
   145             "size": 16,          # WORD flag
       
   146             "IEC_type": "WORD",  # WORD flag
       
   147             "var_name": "var_name",
       
   148             "location": "W" + ".".join([str(i) for i in current_location]) + ".0.1",
       
   149             "description": "Modbus request status flag",
   141             "children": []})        
   150             "children": []})        
   142         for offset in range(address, address + count):
   151         for offset in range(address, address + count):
   143             entries.append({
   152             entries.append({
   144                 "name": dataname + " " + str(offset),
   153                 "name": dataname + " " + str(offset),
   145                 "type": LOCATION_VAR_MEMORY,
   154                 "type": LOCATION_VAR_MEMORY,
   877                         #        In the following if, we check for this condition by checking
   886                         #        In the following if, we check for this condition by checking
   878                         #        if their are at least 4 or more number in the location's address.
   887                         #        if their are at least 4 or more number in the location's address.
   879                         if (        relative_addr in xrange(int(GetCTVal(subchild, 2)))  # condition (a) explained above
   888                         if (        relative_addr in xrange(int(GetCTVal(subchild, 2)))  # condition (a) explained above
   880                             and len(iecvar["LOC"]) < 5):                                  # condition (b) explained above
   889                             and len(iecvar["LOC"]) < 5):                                  # condition (b) explained above
   881                             if str(iecvar["NAME"]) not in loc_vars_list:
   890                             if str(iecvar["NAME"]) not in loc_vars_list:
   882                                 loc_vars.append(
   891                                 loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr))
   883                                     "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr))
       
   884                                 loc_vars_list.append(str(iecvar["NAME"]))
   892                                 loc_vars_list.append(str(iecvar["NAME"]))
   885                         # Now add the located variable in case it is a flag (condition (b) above
   893                         # Now add the located variable in case it is a flag (condition (b) above
   886                         if  len(iecvar["LOC"]) >= 5:       # condition (b) explained above
   894                         if  len(iecvar["LOC"]) >= 5:       # condition (b) explained above
   887                             if str(iecvar["NAME"]) not in loc_vars_list:
   895                             if str(iecvar["NAME"]) not in loc_vars_list:
   888                                 loc_vars.append(
   896                                 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0'
   889                                     "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
   897                                 if iecvar["LOC"][4] == 0:
   890                                 loc_vars_list.append(str(iecvar["NAME"]))
   898                                     loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
       
   899                                     loc_vars_list.append(str(iecvar["NAME"]))
       
   900                                 # Add if it is a Communication Status Flag (mapped onto %QWa.b.c.0.1), so last number is a '1'
       
   901                                 if iecvar["LOC"][4] == 1:
       
   902                                     loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_status;" % (client_requestid))
       
   903                                     loc_vars_list.append(str(iecvar["NAME"]))
   891                     client_requestid += 1
   904                     client_requestid += 1
   892                 tcpclient_node_count += 1
   905                 tcpclient_node_count += 1
   893                 client_nodeid += 1
   906                 client_nodeid += 1
   894             #
   907             #
   895             if child.PlugType == "ModbusRTUclient":
   908             if child.PlugType == "ModbusRTUclient":
   918                         #        While all Modbus registers/coils are mapped onto a location
   931                         #        While all Modbus registers/coils are mapped onto a location
   919                         #        with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped
   932                         #        with 4 numbers (e.g. %QX0.1.2.55), this control flag is mapped
   920                         #        onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last
   933                         #        onto a location with 4 numbers (e.g. %QX0.1.2.0.0), where the last
   921                         #        two numbers are always '0.0', and the first two identify the request.
   934                         #        two numbers are always '0.0', and the first two identify the request.
   922                         #        In the following if, we check for this condition by checking
   935                         #        In the following if, we check for this condition by checking
   923                         #        if their are at least 4 or more number in the location's address.
   936                         #        if there are at least 4 or more number in the location's address.
   924                         if (        relative_addr in xrange(int(GetCTVal(subchild, 2)))  # condition (a) explained above
   937                         if (        relative_addr in xrange(int(GetCTVal(subchild, 2)))  # condition (a) explained above
   925                             and len(iecvar["LOC"]) < 5):                                  # condition (b) explained above
   938                             and len(iecvar["LOC"]) < 5):                                  # condition (b) explained above
   926                             if str(iecvar["NAME"]) not in loc_vars_list:
   939                             if str(iecvar["NAME"]) not in loc_vars_list:
   927                                 loc_vars.append(
   940                                 loc_vars.append(
   928                                     "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr))
   941                                     "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].plcv_buffer[%d];" % (client_requestid, relative_addr))
   929                                 loc_vars_list.append(str(iecvar["NAME"]))
   942                                 loc_vars_list.append(str(iecvar["NAME"]))
   930                         # Now add the located variable in case it is a flag (condition (b) above
   943                         # Now add the located variable in case it is a flag (condition (b) above
   931                         if  len(iecvar["LOC"]) >= 5:       # condition (b) explained above
   944                         if  len(iecvar["LOC"]) >= 5:       # condition (b) explained above
   932                             if str(iecvar["NAME"]) not in loc_vars_list:
   945                             if str(iecvar["NAME"]) not in loc_vars_list:
   933                                 loc_vars.append(
   946                                 # Add if it is a Execution Request Flag (mapped onto %QXa.b.c.0.0), so last number is a '0'
   934                                     "u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
   947                                 if iecvar["LOC"][4] == 0:
   935                                 loc_vars_list.append(str(iecvar["NAME"]))
   948                                     loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_req;" % (client_requestid))
       
   949                                     loc_vars_list.append(str(iecvar["NAME"]))
       
   950                                 # Add if it is a Communication Status Flag (mapped onto %QWa.b.c.0.1), so last number is a '1'
       
   951                                 if iecvar["LOC"][4] == 1:
       
   952                                     loc_vars.append("u16 *" + str(iecvar["NAME"]) + " = &client_requests[%d].flag_exec_status;" % (client_requestid))
       
   953                                     loc_vars_list.append(str(iecvar["NAME"]))
   936                     client_requestid += 1
   954                     client_requestid += 1
   937                 rtuclient_node_count += 1
   955                 rtuclient_node_count += 1
   938                 client_nodeid += 1
   956                 client_nodeid += 1
   939             nodeid += 1
   957             nodeid += 1
   940 
   958