changeset 2654 | 7575050a80c5 |
parent 2647 | 990004083eb8 |
child 2655 | d2b2ee04bfa1 |
2649:db68cb0e6bdc | 2654:7575050a80c5 |
---|---|
55 """ |
55 """ |
56 Outputs a string to be used on C files |
56 Outputs a string to be used on C files |
57 params: child - the correspondent subplugin in Beremiz |
57 params: child - the correspondent subplugin in Beremiz |
58 """ |
58 """ |
59 node_init_template = '''/*node %(locnodestr)s*/ |
59 node_init_template = '''/*node %(locnodestr)s*/ |
60 {"%(locnodestr)s", %(slaveid)s, {naf_tcp, {.tcp = {%(host)s, "%(port)s", DEF_CLOSE_ON_SILENCE}}}, -1 /* mb_nd */, 0 /* init_state */}''' |
60 {"%(locnodestr)s", "%(config_name)s", %(slaveid)s, {naf_tcp, {.tcp = {%(host)s, "%(port)s", DEF_CLOSE_ON_SILENCE}}}, -1 /* mb_nd */, 0 /* init_state */}''' |
61 |
61 |
62 location = ".".join(map(str, child.GetCurrentLocation())) |
62 location = ".".join(map(str, child.GetCurrentLocation())) |
63 host, port, slaveid = GetCTVals(child, range(3)) |
63 config_name, host, port, slaveid = GetCTVals(child, range(4)) |
64 if host == "#ANY#": |
64 if host == "#ANY#": |
65 host = 'INADDR_ANY' |
65 host = 'INADDR_ANY' |
66 else: |
66 else: |
67 host = '"' + host + '"' |
67 host = '"' + host + '"' |
68 # slaveid = GetCTVal(child, 2) |
68 # slaveid = GetCTVal(child, 2) |
69 # if int(slaveid) not in xrange(256): |
69 # if int(slaveid) not in xrange(256): |
70 # self.GetCTRoot().logger.write_error("Error: Wrong slave ID in %s server node\nModbus Plugin C code returns empty\n"%location) |
70 # self.GetCTRoot().logger.write_error("Error: Wrong slave ID in %s server node\nModbus Plugin C code returns empty\n"%location) |
71 # return None |
71 # return None |
72 |
72 |
73 node_dict = {"locnodestr": location, |
73 node_dict = {"locnodestr": location, |
74 "config_name": config_name, |
|
74 "host": host, |
75 "host": host, |
75 "port": port, |
76 "port": port, |
76 "slaveid": slaveid} |
77 "slaveid": slaveid} |
77 return node_init_template % node_dict |
78 return node_init_template % node_dict |
78 |
79 |
118 """ |
119 """ |
119 Outputs a string to be used on C files |
120 Outputs a string to be used on C files |
120 params: child - the correspondent subplugin in Beremiz |
121 params: child - the correspondent subplugin in Beremiz |
121 """ |
122 """ |
122 node_init_template = '''/*node %(locnodestr)s*/ |
123 node_init_template = '''/*node %(locnodestr)s*/ |
123 {"%(locnodestr)s", %(slaveid)s, {naf_rtu, {.rtu = {"%(device)s", %(baud)s /*baud*/, %(parity)s /*parity*/, 8 /*data bits*/, %(stopbits)s, 0 /* ignore echo */}}}, -1 /* mb_nd */, 0 /* init_state */}''' |
124 {"%(locnodestr)s", "%(config_name)s", %(slaveid)s, {naf_rtu, {.rtu = {"%(device)s", %(baud)s /*baud*/, %(parity)s /*parity*/, 8 /*data bits*/, %(stopbits)s, 0 /* ignore echo */}}}, -1 /* mb_nd */, 0 /* init_state */}''' |
124 |
125 |
125 location = ".".join(map(str, child.GetCurrentLocation())) |
126 location = ".".join(map(str, child.GetCurrentLocation())) |
126 device, baud, parity, stopbits, slaveid = GetCTVals(child, range(5)) |
127 config_name, device, baud, parity, stopbits, slaveid = GetCTVals(child, range(6)) |
127 |
128 |
128 node_dict = {"locnodestr": location, |
129 node_dict = {"locnodestr": location, |
130 "config_name": config_name, |
|
129 "device": device, |
131 "device": device, |
130 "baud": baud, |
132 "baud": baud, |
131 "parity": modbus_serial_parity_dict[parity], |
133 "parity": modbus_serial_parity_dict[parity], |
132 "stopbits": stopbits, |
134 "stopbits": stopbits, |
133 "slaveid": slaveid} |
135 "slaveid": slaveid} |
138 """ |
140 """ |
139 Outputs a string to be used on C files |
141 Outputs a string to be used on C files |
140 params: child - the correspondent subplugin in Beremiz |
142 params: child - the correspondent subplugin in Beremiz |
141 """ |
143 """ |
142 node_init_template = '''/*node %(locnodestr)s*/ |
144 node_init_template = '''/*node %(locnodestr)s*/ |
143 {"%(locnodestr)s", {naf_rtu, {.rtu = {"%(device)s", %(baud)s /*baud*/, %(parity)s /*parity*/, 8 /*data bits*/, %(stopbits)s, 0 /* ignore echo */}}}, -1 /* mb_nd */, 0 /* init_state */, %(coms_period)s /* communication period */}''' |
145 {"%(locnodestr)s", "%(config_name)s", "%(device)s", "", {naf_rtu, {.rtu = {NULL, %(baud)s /*baud*/, %(parity)s /*parity*/, 8 /*data bits*/, %(stopbits)s, 0 /* ignore echo */}}}, -1 /* mb_nd */, 0 /* init_state */, %(coms_period)s /* communication period */}''' |
144 |
146 |
145 location = ".".join(map(str, child.GetCurrentLocation())) |
147 location = ".".join(map(str, child.GetCurrentLocation())) |
146 device, baud, parity, stopbits, coms_period = GetCTVals(child, range(5)) |
148 config_name, device, baud, parity, stopbits, coms_period = GetCTVals(child, range(6)) |
147 |
149 |
148 node_dict = {"locnodestr": location, |
150 node_dict = {"locnodestr": location, |
151 "config_name": config_name, |
|
149 "device": device, |
152 "device": device, |
150 "baud": baud, |
153 "baud": baud, |
151 "parity": modbus_serial_parity_dict[parity], |
154 "parity": modbus_serial_parity_dict[parity], |
152 "stopbits": stopbits, |
155 "stopbits": stopbits, |
153 "coms_period": coms_period} |
156 "coms_period": coms_period} |
158 """ |
161 """ |
159 Outputs a string to be used on C files |
162 Outputs a string to be used on C files |
160 params: child - the correspondent subplugin in Beremiz |
163 params: child - the correspondent subplugin in Beremiz |
161 """ |
164 """ |
162 node_init_template = '''/*node %(locnodestr)s*/ |
165 node_init_template = '''/*node %(locnodestr)s*/ |
163 {"%(locnodestr)s", {naf_tcp, {.tcp = {"%(host)s", "%(port)s", DEF_CLOSE_ON_SILENCE}}}, -1 /* mb_nd */, 0 /* init_state */, %(coms_period)s /* communication period */, 0 /* prev_error */}''' |
166 {"%(locnodestr)s", "%(config_name)s", "%(host)s", "%(port)s", {naf_tcp, {.tcp = {NULL, NULL, DEF_CLOSE_ON_SILENCE}}}, -1 /* mb_nd */, 0 /* init_state */, %(coms_period)s /* communication period */, 0 /* prev_error */}''' |
164 |
167 |
165 location = ".".join(map(str, child.GetCurrentLocation())) |
168 location = ".".join(map(str, child.GetCurrentLocation())) |
166 host, port, coms_period = GetCTVals(child, range(3)) |
169 config_name, host, port, coms_period = GetCTVals(child, range(4)) |
167 |
170 |
168 node_dict = {"locnodestr": location, |
171 node_dict = {"locnodestr": location, |
172 "config_name": config_name, |
|
169 "host": host, |
173 "host": host, |
170 "port": port, |
174 "port": port, |
171 "coms_period": coms_period} |
175 "coms_period": coms_period} |
172 return node_init_template % node_dict |
176 return node_init_template % node_dict |
173 |
177 |
182 The string that should be added on C code - if everything goes allright |
186 The string that should be added on C code - if everything goes allright |
183 """ |
187 """ |
184 |
188 |
185 req_init_template = '''/*request %(locreqstr)s*/ |
189 req_init_template = '''/*request %(locreqstr)s*/ |
186 {"%(locreqstr)s", %(nodeid)s, %(slaveid)s, %(iotype)s, %(func_nr)s, %(address)s , %(count)s, |
190 {"%(locreqstr)s", %(nodeid)s, %(slaveid)s, %(iotype)s, %(func_nr)s, %(address)s , %(count)s, |
187 DEF_REQ_SEND_RETRIES, 0 /* error_code */, 0 /* prev_code */, {%(timeout_s)d, %(timeout_ns)d} /* timeout */, %(write_on_change)d /* write_on_change */, |
191 DEF_REQ_SEND_RETRIES, 0 /* error_code */, 0 /* prev_code */, {%(timeout_s)d, %(timeout_ns)d} /* timeout */, %(write_on_change)d /* write_on_change */, |
188 {%(buffer)s}, {%(buffer)s}}''' |
192 {%(buffer)s}, {%(buffer)s}}''' |
189 |
193 |
190 timeout = int(GetCTVal(child, 4)) |
194 timeout = int(GetCTVal(child, 4)) |
191 timeout_s = timeout // 1000 |
195 timeout_s = timeout // 1000 |
192 timeout_ms = timeout - (timeout_s * 1000) |
196 timeout_ms = timeout - (timeout_s * 1000) |