@@ -206,6 +206,34 @@ static void attempt_connect(struct l_timeout *to, void *user_data)
206
206
l_timeout_modify (to , RECONNECT_TIMEOUT );
207
207
}
208
208
209
+ static int put_tag_name_created (struct knot_data_item * data_item )
210
+ {
211
+ struct knot_data_item * data_item_aux ;
212
+ int i ;
213
+ int rc = -1 ;
214
+
215
+ for (i = 0 ; i < thing_ethernet_ip .number_sensor ; i ++ ) {
216
+ int return_aux ;
217
+
218
+ data_item_aux = l_hashmap_lookup (thing_ethernet_ip .data_items ,
219
+ L_INT_TO_PTR (i ));
220
+ if (!data_item_aux )
221
+ rc = - EINVAL ;
222
+
223
+ return_aux = strcmp (
224
+ data_item_aux -> tag_name ,
225
+ data_item -> tag_name );
226
+ if (!return_aux ) {
227
+ data_item_aux -> tag =
228
+ data_item -> tag ;
229
+ rc = 0 ;
230
+ break ;
231
+ }
232
+ }
233
+
234
+ return rc ;
235
+ }
236
+
209
237
int iface_ethernet_ip_read_data (struct knot_data_item * data_item )
210
238
{
211
239
int rc ;
@@ -214,6 +242,17 @@ int iface_ethernet_ip_read_data(struct knot_data_item *data_item)
214
242
215
243
memset (& tmp , 0 , sizeof (tmp ));
216
244
245
+ rc = plc_tag_status (data_item -> tag );
246
+
247
+ if (rc == PLCTAG_ERR_NOT_FOUND || rc == PLCTAG_ERR_TIMEOUT ) {
248
+ l_error ("Unable to read the Data_%d! Got error code %d: %s\n" ,
249
+ data_item -> sensor_id , rc , plc_tag_decode_error (rc ));
250
+ plc_tag_destroy (data_item -> tag );
251
+ data_item -> tag = plc_tag_create (data_item -> string_tag_path ,
252
+ DATA_TIMEOUT );
253
+ put_tag_name_created (data_item );
254
+ }
255
+
217
256
rc = plc_tag_read (data_item -> tag , DATA_TIMEOUT );
218
257
219
258
if (rc == PLCTAG_STATUS_OK ) {
@@ -282,10 +321,11 @@ int iface_ethernet_ip_read_data(struct knot_data_item *data_item)
282
321
283
322
memcpy (& data_item -> current_val , & tmp , sizeof (tmp ));
284
323
} else {
285
- l_error ("Unable to read the data ! Got error code %d: %s\n" ,
324
+ l_error ("Unable to read! Got error code %d: %s\n" ,
286
325
rc , plc_tag_decode_error (rc ));
287
326
l_io_destroy (ethernet_op_io );
288
327
ethernet_op_io = NULL ;
328
+ rc = - EINTR ;
289
329
}
290
330
291
331
return rc ;
0 commit comments