<< 点击显示目录 >> 主页 exOS使用助手 > exOS Automation Help > Development > Programming > exOS Communication API reference (exos_api.h) > exos_datamodel_init() |
初始化数据模型句柄
EXOS_ERROR_CODE exos_datamodel_init(exos_datamodel_handle_t *datamodel, const char *datamodel_instance_name, const char *user_alias);
该函数初始化(重置)数据模型句柄,并 通过 数据模型实例名赋予其 用户别名。然后,数据模型句柄将被用于使用 exos_datamodel_process() 接收传入的消息 。
示例
int main(void)
{
exos_datamodel_handle_t mydatamodel;
exos_datamodel_init(&mydatamodel, "WaterTank", "WaterTank_0");
while(..)
{
exos_datamodel_process(&mydatamodel);
exos_datamodel_handle_t 有几个可以读写的字段。在初始化该结构中的值时,请 在 调用 exos_datamodel_init()之后 执行此操作
好:
exos_datamodel_init(&mydatamodel, "WaterTank", "WaterTank_0");
mydatamodel.user_context = &myAppData;
坏:
mydatamodel.user_context = &myAppData; //BAD!! this wont work as the structure is initialized (reset) in the next line.
exos_datamodel_init(&mydatamodel, "WaterTank", "WaterTank_0");
•数据模型:要初始化的句柄
•datamodel_instance_name: 在 exostarget 配置元素中配置的全局数据模型实例的名称 。通过 exostarget 配置, 数据集消息路由器 上的数据模型实例 会 获得与远程系统的连接描述。在下面的示例中, 数据模型实例 名应设置为 "WaterTank"(水箱)。
•user_alias:用户自定义名称,用于识别系统中的应用程序/或特定数据模型句柄。这样就可以在将来引入新的事件,例如 EXOS_DATASET_EVENT_RECEIVED,每个接收数据集的应用程序都会触发一次。在这种情况 下, 应用程序的 用户别名 将被转发给发布者。目前, user_alias 仅用于应用程序的内部系统日志。
Initialize the datamodel handle
EXOS_ERROR_CODE exos_datamodel_init(exos_datamodel_handle_t *datamodel, const char *datamodel_instance_name, const char *user_alias);
This function intializes (resets) a datamodel handle and gives it a user_alias via a datamodel_instance_name. The datamodel handle is then used for receiving incoming messages using the exos_datamodel_process()
Example:
int main(void)
{
exos_datamodel_handle_t mydatamodel;
exos_datamodel_init(&mydatamodel, "WaterTank", "WaterTank_0");
while(..)
{
exos_datamodel_process(&mydatamodel);
The exos_datamodel_handle_t has several fields that can be read and written to. When intializing values in the structure, do this after calling the exos_datamodel_init()
Good:
exos_datamodel_init(&mydatamodel, "WaterTank", "WaterTank_0");
mydatamodel.user_context = &myAppData;
Bad:
mydatamodel.user_context = &myAppData; //BAD!! this wont work as the structure is initialized (reset) in the next line.
exos_datamodel_init(&mydatamodel, "WaterTank", "WaterTank_0");
•datamodel: The handle to be initialized
•datamodel_instance_name: The name of the global datamodel instance configured in the exostarget Configuration Element. Via the exostarget Configuration, the datamodel instance on the Dataset Message Router gets a connection description to the remote system. In the example below, the datamodel_instance_name should be set to "WaterTank"
•user_alias: A user defined name to identify the application / or specific datamodel handle in the system. This allows for the introduction of new events in future, for example a EXOS_DATASET_EVENT_RECEIVED, that is triggered once for every application receiving a dataset. In that case the user_alias of that application would be forwarded to the publisher. Currently, the user_alias is only used for the internal system log of the application.