145 iotype_t req_type; |
145 iotype_t req_type; |
146 u8 mb_function; |
146 u8 mb_function; |
147 u16 address; |
147 u16 address; |
148 u16 count; |
148 u16 count; |
149 int retries; |
149 int retries; |
150 u8 error_code; // modbus error code (if any) of current request |
150 u8 mb_error_code; // modbus error code (if any) of last executed request |
|
151 u8 tn_error_code; // transaction error code (if any) of last executed request |
151 int prev_error; // error code of the last printed error message (0 when no error) |
152 int prev_error; // error code of the last printed error message (0 when no error) |
152 struct timespec resp_timeout; |
153 struct timespec resp_timeout; |
153 u8 write_on_change; // boolean flag. If true => execute MB request when data to send changes |
154 u8 write_on_change; // boolean flag. If true => execute MB request when data to send changes |
154 // buffer used to store located PLC variables |
155 // buffer used to store located PLC variables |
155 u16 plcv_buffer[REQ_BUF_SIZE]; |
156 u16 plcv_buffer[REQ_BUF_SIZE]; |
156 // buffer used to store data coming from / going to server |
157 // buffer used to store data coming from / going to server |
157 u16 coms_buffer[REQ_BUF_SIZE]; |
158 u16 coms_buffer[REQ_BUF_SIZE]; |
158 pthread_mutex_t coms_buf_mutex; // mutex to access coms_buffer[] |
159 pthread_mutex_t coms_buf_mutex; // mutex to access coms_buffer[] |
159 /* boolean flag that will be mapped onto a (BOOL) located variable |
160 /* boolean flag that will be mapped onto a (BOOL) located variable |
160 * (u16 because IEC 61131-3 BOOL are mapped onto u16 in C code! ) |
161 * (u8 because IEC 61131-3 BOOL are mapped onto u8 in C code! ) |
161 * -> allow PLC program to request when to start the MB transaction |
162 * -> allow PLC program to request when to start the MB transaction |
162 * -> will be reset once the MB transaction has completed |
163 * -> will be reset once the MB transaction has completed |
163 */ |
164 */ |
164 u16 flag_exec_req; |
165 u8 flag_exec_req; |
165 /* flag that works in conjunction with flag_exec_req |
166 /* flag that works in conjunction with flag_exec_req |
166 * (does not really need to be u16 as it is not mapped onto a located variable. ) |
167 * (does not really need to be u8 as it is not mapped onto a located variable. ) |
167 * -> used by internal logic to indicate that the client thread |
168 * -> used by internal logic to indicate that the client thread |
168 * that will be executing the MB transaction |
169 * that will be executing the MB transaction |
169 * requested by flag exec_req has already been activated. |
170 * requested by flag exec_req has already been activated. |
170 * -> will be reset once the MB transaction has completed |
171 * -> will be reset once the MB transaction has completed |
171 */ |
172 */ |
172 u16 flag_exec_started; |
173 u8 flag_exec_started; |
173 /* flag that will be mapped onto a (WORD) located variable |
174 /* flag that will be mapped onto a (BYTE) located variable |
174 * (u16 because the flag is a word! ) |
175 * (u8 because the flag is a BYTE! ) |
175 * -> MSByte will store the result of the last executed MB transaction |
176 * -> will store the result of the last executed MB transaction |
176 * 1 -> error accessing IP network, or serial interface |
177 * 1 -> error accessing IP network, or serial interface |
177 * 2 -> reply received from server was an invalid frame |
178 * 2 -> reply received from server was an invalid frame |
178 * 3 -> server did not reply before timeout expired |
179 * 3 -> server did not reply before timeout expired |
179 * 4 -> server returned a valid error frame |
180 * 4 -> server returned a valid Modbus error frame |
180 * -> if the MSByte is 4, the LSByte will store the MB error code returned by the server |
|
181 * -> will be reset (set to 0) once this MB transaction has completed sucesfully |
181 * -> will be reset (set to 0) once this MB transaction has completed sucesfully |
182 */ |
182 * |
183 u16 flag_exec_status; |
183 * In other words, this variable is a copy of tn_error_code, reset after each request attempt completes. |
|
184 * We map this copy (instead of tn_error_code) onto a located variable in case the user program decides |
|
185 * to overwrite its value and mess up the plugin logic. |
|
186 */ |
|
187 u8 flag_tn_error_code; |
|
188 /* flag that will be mapped onto a (BYTE) located variable |
|
189 * (u8 because the flag is a BYTE! ) |
|
190 * -> if flag_tn_error_code is 4, this flag will store the MB error code returned by the MB server in a MB error frame |
|
191 * -> will be reset (set to 0) once this MB transaction has completed succesfully |
|
192 * |
|
193 * In other words, this variable is a copy of mb_error_code, reset after each request attempt completes. |
|
194 * We map this copy (instead of mb_error_code) onto a located variable in case the user program decides |
|
195 * to overwrite its value and mess up the plugin logic. |
|
196 */ |
|
197 u8 flag_mb_error_code; |
184 } client_request_t; |
198 } client_request_t; |
185 |
199 |
186 |
200 |
187 /* The total number of nodes, needed to support _all_ instances of the modbus plugin */ |
201 /* The total number of nodes, needed to support _all_ instances of the modbus plugin */ |
188 #define TOTAL_TCPNODE_COUNT %(total_tcpnode_count)s |
202 #define TOTAL_TCPNODE_COUNT %(total_tcpnode_count)s |