DCTag SDK: DCTag.h Source File

DCTag SDK 1.2.1

DCTag SDK  1.2.1
Copyright © 1983-2016 Advantech Co., Ltd.
DCTag.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright © 1983-2014 Advantech Co., Ltd.
3 ********************************************************************************
4 THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY INFORMATION
5 WHICH IS THE PROPERTY OF ADVANTECH CORP., ANY DISCLOSURE, USE, OR REPRODUCTION,
6 WITHOUT WRITTEN AUTHORIZATION FROM ADVANTECH CORP., IS STRICTLY PROHIBITED.
7 
8 ================================================================================
9 File: DCTag.h
10 Author: lin.lei
11 Created: 7/22/2014
12 --------------------------------------------------------------------------------
13 */
14 
15 #ifndef DCTAG_H
16 #define DCTAG_H
17 
25 #include <stdint.h>
26 #include <stdbool.h>
27 #include "QualityDefine.h"
28 
29 #ifdef _MSC_VER
30 #ifdef DCTAG_EXPORTS
31 #define DCTAG_API __declspec(dllexport)
32 #else
33 #define DCTAG_API __declspec(dllimport)
34 #endif
35 #else
36 #define DCTAG_API
37 #endif
38 
40 #define DC_TAG_MAX_RW_COUNT 3000
41 
44 {
65 };
66 
67 #define DCU_CAPABILITY_READ 1
68 #define DCU_CAPABILITY_WRITE 2
69 #define DCU_CAPABILITY_UPDATE 4
70 
71 #ifdef __cplusplus
72 extern "C"
73 {
74 #endif /* __cplusplus */
75 
77  typedef void * DC_TAG_HANDLE;
78 
80  struct dc_tag
81  {
83  double value;
84 
86  int16_t quality;
87 
89  uint64_t time;
90 
92  uint32_t usec;
93  };
95  typedef struct dc_tag DC_TAG;
96 
99  {
101  uint32_t size;
102 
104  int (*read_tag) (
105  DC_TAG_HANDLE tag_handles[],
106  void * tag_contexts[],
107  DC_TAG tag_values[],
108  uint32_t tag_count,
109  void * user_context );
110 
112  int (*write_tag) (
113  DC_TAG_HANDLE tag_handles[],
114  void * tag_contexts[],
115  double tag_values[],
116  uint32_t tag_count,
117  void * user_context );
118 
120  int (*update_tag) (
121  DC_TAG_HANDLE tag_handle,
122  void * tag_context,
123  DC_TAG * tag_value,
124  void * user_context );
125  };
128 
129  /*!*************************************************************************
130  * \brief
131  * Initialize the DCTag SDK.
132  *
133  * \details
134  * Before any other API can be used correctly, you must call this function
135  * once and only once to perform a runtime initialization firstly.
136  *
137  * \param[in] max_tag_count
138  * the max tag count you will handle in your application.
139  * \param[in] callback
140  * the callback function pointer, in struct \ref dc_tag_callback. If your
141  * application will not add any tag to the DataCenter, you can ignore this
142  * parameter and give a NULL value.
143  * \param[in] user_context
144  * the context pointer, which will be passed in the callback functions.
145  *
146  * \return
147  * On success, zero is returned, otherwise an error code is returned.
148  * please refer to the enum \ref dc_tag_error_code for the error code
149  * description.
150  *
151  * \see dc_tag_callback
152  ***************************************************************************/
153  DCTAG_API int dc_tag_init (
154  uint32_t max_tag_count,
155  DC_TAG_CALLBACK * callback,
156  void * user_context );
157 
158  /*!*************************************************************************
159  * \brief
160  * Uninitialize the DCTag SDK.
161  *
162  * \details
163  * Call this function before application exit to release all resources
164  * allocated by the DCTag SDK.
165  ***************************************************************************/
166  DCTAG_API void dc_tag_uninit ( void );
167 
168  /*!*************************************************************************
169  * \brief
170  * Add a tag to the DataCenter.
171  *
172  * \details
173  *
174  * \param[in] tag_name
175  * Specify the name of the tag you want to add to the DataCenter, if an
176  * exist tag in the DataCenter has the same name with the tag adding, then
177  * this function will return error and no new tag will be added to the
178  * DataCenter.
179  * \param[in] tag_context
180  * The context related to the tag added, it will be passed by the read or
181  * write callback function.
182  *
183  * \return
184  * On success, a valid tag handle is returned, otherwise NULL is returned.
185  ***************************************************************************/
186  DCTAG_API DC_TAG_HANDLE dc_tag_add (
187  char const * tag_name,
188  void * tag_context );
189 
190  /*!*************************************************************************
191  * \brief
192  * Remove a tag from the DataCenter which previous added by yourself.
193  *
194  * \details
195  * When calling this function, please make sure the tag be removed is the
196  * tag added by \ref dc_tag_add previous, not the tag opened.
197  *
198  * \param[in] tag_handle
199  * The tag handle returned by a successful call of the \ref dc_tag_add.
200  *
201  * \return
202  * On success, zero is returned, otherwise an error code is returned,
203  * please refer to the enum \ref dc_tag_error_code for the error code
204  * description.
205  ***************************************************************************/
206  DCTAG_API int dc_tag_remove ( DC_TAG_HANDLE tag_handle );
207 
208  /*!*************************************************************************
209  * \brief
210  * Open a exist tag in the DataCenter with the specified name.
211  *
212  * \details
213  * Even the tag would be opened is not present in the DataCenter, this
214  * function also return a valid handle, but if you read the tag you would
215  * get a exception quality code.
216  *
217  * \param[in] tag_name
218  * Specify the name of the tag you want to add to the DataCenter.
219  * \param[in] tag_context
220  * The context related to the tag opened, it will be passed by the update
221  * callback function.
222  *
223  * \return
224  * On success, a valid tag handle is returned, otherwise NULL is returned.
225  ***************************************************************************/
226  DCTAG_API DC_TAG_HANDLE dc_tag_open (
227  char const * tag_name,
228  void * tag_context );
229 
230  /*!*************************************************************************
231  * \brief
232  * Close a tag from the DataCenter which previous opened by yourself.
233  *
234  * \details
235  * When calling this function, please make sure the tag be closed is the
236  * tag added by \ref dc_tag_open previous, not the tag added.
237  *
238  * \param[in] tag_handle
239  * The tag handle returned by a successful call of the \ref dc_tag_open.
240  *
241  * \return
242  * On success, zero is returned, otherwise an error code is returned.
243  * please refer to the enum \ref dc_tag_error_code for the error code
244  * description.
245  ***************************************************************************/
246  DCTAG_API int dc_tag_close ( DC_TAG_HANDLE tag_handle );
247 
248  /*!*************************************************************************
249  * \brief
250  * Subscribe tags for read.
251  *
252  * \details
253  * If you need to read some tags periodically, you can subscribe these tags
254  * before read and call \ref dc_tag_read_subscription to read tag values,
255  * this will achieve the best reading performance.
256  *
257  * \param[in] tag_handles
258  * The tag handle array contains all tag handles to be read.
259  * \param[in] tag_count
260  * The count of the tag handle in the tag_handles.
261  *
262  * \return
263  * On success, a subscription context will returned, otherwise a NULL is
264  * returned.
265  ***************************************************************************/
266  DCTAG_API void * dc_tag_add_subscription (
267  DC_TAG_HANDLE tag_handles[],
268  uint32_t tag_count );
269 
270  /*!*************************************************************************
271  * \brief
272  * Remove a previous subscription.
273  *
274  * \details
275  * When you finished all operation on a subscription, you can call this
276  * function to remove the subscription from the Data Center.
277  *
278  * \param[in] subscription
279  * The subscription context returned by a successful call to the \ref
280  * dc_tag_add_subscription.
281  *
282  * \return
283  * On success, zero is returned, otherwise an error code is returned.
284  * please refer to the enum \ref dc_tag_error_code for the error code
285  * description.
286  ***************************************************************************/
287  DCTAG_API int dc_tag_remove_subscription ( void * subscription );
288 
289  /*!*************************************************************************
290  * \brief
291  * Read one or more tags by previous subscription.
292  *
293  * \details
294  * Used together with the \ref dc_tag_add_subscription function to
295  * complete a read operation.
296  *
297  * \param[in] subscription
298  * The subscription context returned by a successful call to the \ref
299  * dc_tag_add_subscription.
300  * \param[out] tag_values
301  * The tag value array contains all tag value returned, be sure the count
302  * of the tag value equals to or larger than the count of the tag handle.
303  * \param[in] tag_count
304  * The count of the tag values in the tag_values.
305  *
306  * \return
307  * On success, zero is returned, otherwise an error code is returned.
308  * please refer to the enum \ref dc_tag_error_code for the error code
309  * description.
310  ***************************************************************************/
311  DCTAG_API int dc_tag_read_subscription (
312  void * subscription,
313  DC_TAG tag_values[],
314  uint32_t tag_count );
315 
316  /*!*************************************************************************
317  * \brief
318  * Read one or more tags.
319  *
320  * \details
321  * Before perform read operation, you should prepare a tag handle array,
322  * which contains all tag handles to be read, be note the max tag count is
323  * limited by \ref DC_TAG_MAX_RW_COUNT.
324  *
325  * \param[in] tag_handles
326  * The tag handle array contains all tag handles to be read.
327  * \param[out] tag_values
328  * The tag value array contains all tag value returned, be sure the count
329  * of the tag value equals to or larger than the count of the tag handle.
330  * \param[in] tag_count
331  * The count of the tag handle in the tag_handles.
332  *
333  * \return
334  * On success, zero is returned, otherwise an error code is returned.
335  * please refer to the enum \ref dc_tag_error_code for the error code
336  * description.
337  *
338  * \remark
339  * If there is only one tag, be sure to use the pointer of the tag handle
340  * instead of using the tag handle directly.
341  ***************************************************************************/
342  DCTAG_API int dc_tag_read (
343  DC_TAG_HANDLE tag_handles[],
344  DC_TAG tag_values[],
345  uint32_t tag_count );
346 
347  /*!*************************************************************************
348  * \brief
349  * Write one or more tags.
350  *
351  * \details
352  * Before perform write operation, you should prepare a tag handle array,
353  * which contains all tag handles to be written, be note the max tag count
354  * is limited by \ref DC_TAG_MAX_RW_COUNT.
355  *
356  * \param[in] tag_handles
357  * The tag handle array contains all tag handles to be written.
358  * \param[out] tag_values
359  * The tag value array contains all tag value to be written, be sure the
360  * count of the tag value equals to or larger than the count of the tag
361  * handle.
362  * \param[in] tag_count
363  * The count of the tag handle in the tag_handles.
364  *
365  * \return
366  * On success, zero is returned, otherwise an error code is returned.
367  * please refer to the enum \ref dc_tag_error_code for the error code
368  * description.
369  ***************************************************************************/
370  DCTAG_API int dc_tag_write (
371  DC_TAG_HANDLE tag_handles[],
372  double tag_values[],
373  uint32_t tag_count );
374 
375  /*!*************************************************************************
376  * \brief
377  * Update one or more tags.
378  *
379  * \details
380  * This function is called by tag provider only. Whenever the value or
381  * quality of tags added by the tag provider changed, the tag provider
382  * should call this function to make the changes pushed to all data users
383  * through the data center.
384  *
385  * \param[in] tag_handles
386  * The tag handle array contains all tag handles to be updated.
387  * \param[out] tag_values
388  * The tag value array contains all tag value to be updated, be sure the
389  * count of the tag value equals to or larger than the count of the tag
390  * handle.
391  * \param[in] tag_count
392  * The count of the tag handle in the tag_handles.
393  *
394  * \return
395  * On success, zero is returned, otherwise an error code is returned.
396  * please refer to the enum \ref dc_tag_error_code for the error code
397  * description.
398  ***************************************************************************/
399  DCTAG_API int dc_tag_update (
400  DC_TAG_HANDLE tag_handles[],
401  DC_TAG tag_values[],
402  uint32_t tag_count );
403 
404  /*!*************************************************************************
405  * \brief
406  * obtain explanations for the specified quality value.
407  *
408  * \details
409  * This function is used to obtain an explanation of the quality value of a tag.
410  *
411  * \param[in] quality
412  * The quality value to be explained.
413  *
414  * \return
415  * The explain text to the quality.
416  ***************************************************************************/
417  DCTAG_API char const * dc_tag_explain_quality ( int16_t quality );
418 
419  /*!*************************************************************************
420  * \example dc_tag_owner.c
421  * This is an example of how to add tags to the DataCenter.
422  * This example will add three tags into the DataCenter: tag_1, tag_2 and
423  * tag_3. The tag_1 and the tag_2 can be write, but the tag_3 can only be
424  * read, the value of the tag_3 is calculated by tag_1 * tag_2.
425  *
426  * \example dc_tag_read.c
427  * This is an example of how to read tags in the DataCenter.
428  *
429  * \example dc_tag_read_subscription.c
430  * This is an example of how to read tags in the DataCenter by subscription.
431  *
432  * \example dc_tag_write.c
433  * This is an example of how to write tag in the DataCenter.
434  *
435  * \example dc_tag_update.c
436  * This is an example of how to add and update tags in the DataCenter.
437  * This example will add three tags into the DataCenter: tag_1, tag_2 and
438  * tag_3. The tag_1 and the tag_2 are initialized with a random value, and
439  * added up every 10 seconds. The tag_3 is calculated by tag_1 + tag_2.
440  ***************************************************************************/
441 
442 #ifdef __cplusplus
443 }
444 #endif /* __cplusplus */
445 
446 #endif
int dc_tag_remove(DC_TAG_HANDLE tag_handle)
Remove a tag from the DataCenter which previous added by yourself.
Definition: DCTag.c:1507
DC_TAG_HANDLE dc_tag_add(char const *tag_name, void *tag_context)
Add a tag to the DataCenter.
Definition: DCTag.c:1493
dc_tag_error_code
Definition: DCTag.h:43
uint32_t size
Definition: DCTag.h:101
double value
Definition: DCTag.h:83
Definition: DCTag.h:54
uint32_t usec
Definition: DCTag.h:92
void * dc_tag_add_subscription(DC_TAG_HANDLE tag_handles[], uint32_t tag_count)
Subscribe tags for read.
Definition: DCTag.c:1562
char const * dc_tag_explain_quality(int16_t quality)
obtain explanations for the specified quality value.
Definition: DCTag.c:1994
int dc_tag_read(DC_TAG_HANDLE tag_handles[], DC_TAG tag_values[], uint32_t tag_count)
Read one or more tags.
Definition: DCTag.c:1716
DC_TAG_HANDLE dc_tag_open(char const *tag_name, void *tag_context)
Open a exist tag in the DataCenter with the specified name.
Definition: DCTag.c:1519
void * DC_TAG_HANDLE
Definition: DCTag.h:77
int dc_tag_write(DC_TAG_HANDLE tag_handles[], double tag_values[], uint32_t tag_count)
Write one or more tags.
Definition: DCTag.c:1783
Definition: DCTag.h:62
Definition: DCTag.h:48
int dc_tag_close(DC_TAG_HANDLE tag_handle)
Close a tag from the DataCenter which previous opened by yourself.
Definition: DCTag.c:1551
int dc_tag_remove_subscription(void *subscription)
Remove a previous subscription.
Definition: DCTag.c:1603
Definition: DCTag.h:98
Definition: DCTag.h:56
uint64_t time
Definition: DCTag.h:89
Definition: DCTag.h:58
int dc_tag_update(DC_TAG_HANDLE tag_handles[], DC_TAG tag_values[], uint32_t tag_count)
Update one or more tags.
Definition: DCTag.c:1893
Definition: DCTag.h:60
Definition: DCTag.h:52
int16_t quality
Definition: DCTag.h:86
Definition: DCTag.h:50
int dc_tag_read_subscription(void *subscription, DC_TAG tag_values[], uint32_t tag_count)
Read one or more tags by previous subscription.
Definition: DCTag.c:1649
int dc_tag_init(uint32_t max_tag_count, DC_TAG_CALLBACK *callback, void *user_context)
Initialize the DCTag SDK.
Definition: DCTag.c:1329
Definition: DCTag.h:64
Definition: DCTag.h:80
Definition: DCTag.h:46
void dc_tag_uninit(void)
Uninitialize the DCTag SDK.
Definition: DCTag.c:1421
Generated on Thu May 19 2016 14:18:17 for DCTag SDK by   doxygen 1.8.11