<< 点击显示目录 >> 主页 exOS使用助手 > exOS Automation Help > Development > Programming > exOS Communication API reference (exos_api.h) > exos_datamodel_get_nettime() |
获取当前 AR NETTIME(同步)
int32_t exos_datamodel_get_nettime(exos_datamodel_handle_t *datamodel);
该函数返回当前的 NETTIME(在 Linux 中为外推值)。
AR 使用 NETTIME 同步 PLC 中的所有现场总线设备和其他服务。该值以同步方式传输到 Linux,因此 Linux 应用程序可以将自己的事件与来自 PLC 的数据同步。
由于 NETTIME 可以在应用程序中随时读取,因此 数据集消息路由器会 将同步的 AR NETTIME 与当前 CLOCK_MONOTONIC_RAW 一起发送给所有 Linux 应用 程序。有了这些附加信息, exos_datamodel_get_nettime()就 能 利用当前的 CLOCK_MONOTONIC_RAW 时钟, 在 调用 exos_datamodel_process() 之间推算出更精确的 NETTIME 。
•datamodel:数据模型句柄,以指针形式给出
其他同步信息通过 datamodel->sync_info 结构收集 , 该结构具有以下属性
•in_sync
与 ExSyncInfo 功能块 中的 PrecisionReached相同 ,基本上意味着净同步时间有效。这意味着 数据集消息路由器 已同步,且当前时间同步符合配置的 精确度。如果不是这样, exos_datamodel_get_nettime() 将从上次同步值推断,以防同步曾经有效。如果需要这种行为,即如果同步在之前的时间点是确定的,则使用非有效的时间戳,应用程序需要将 in_sync 值 存储 为 was_synchronized 位,并与此位进行核对。在 AR 中,该值始终为 "true",因为 NETTIME 始终可用。
•错过的 AR 循环
与 ExSyncInfo 功能块 中的 MissedCycles相同 ,它给出了 Linux DMR 进程错过 多少个 AR 循环的计数器 。 在 AR 中,该值自然总是 0。
•错过的周期
在每个周期中,Linux DMR都会 发送一条同步消息,该消息会触发 exos_datamodel_process() 函数 的 执行 (该函数块用于接收同步消息)。如果应用程序错过了其中一条消息(未能 在 DMR 的周期内 调用 exos_datamodel_process()),该计数器就会增加。在 AR 中,该值始终为 0,因为 AR 应用程序不会与 DMR 同步 (除非它们在同一任务类(默认为 TC#2) 中 执行,从而隐含地使它们与 DMR 同步 )。
AR-Linux 连接的 NETTIME 精确度可在 exostarget 配置元素中进行配置 。
AR 中的ExSyncInfo 功能块可用于监控 Linux 系统当前的 NETTIME 精确度。
Get the current AR NETTIME (synchronized)
int32_t exos_datamodel_get_nettime(exos_datamodel_handle_t *datamodel);
This function returns the current NETTIME (extrapolated in Linux).
Automation Runtime uses the NETTIME to synchronize all fieldbus devices and other services in the PLC. This value is transferred to Linux in a synchronized manner, so the Linux application can synchronize its own events with the data coming from the PLC.
As the NETTIME could be read at any time within an application, the Dataset Message Router sends out the synchronized AR NETTIME to all Linux applications together with the current CLOCK_MONOTONIC_RAW. With this additional information, the exos_datamodel_get_nettime() can extrapolate to a more accurate NETTIME between the exos_datamodel_process() calls, using the current CLOCK_MONOTONIC_RAW clock.
•datamodel: datamodel handle, given as a pointer
Additional synchronization information is gathered through the datamodel->sync_info structure which has the following properties
•in_sync
Same as the PrecisionReached in the ExSyncInfo function block, basically meaning the nettime syncronization is valid. This means that the Dataset Message Router is synchronized and that the current time synchronization meets the configured Precision. If this is not true, the exos_datamodel_get_nettime() will extrapolate from the last synchronized value, in case the synchronization has ever been valid. In case this behaviour is required, i.e to use a non-valid timestamp if the synchronization was OK at a previous point in time, the application needs to store the in_sync value as a was_synchronized bit, and check against this one. In AR, this value is always TRUE, as the NETTIME is available at all times.
•missed_ar_cycles
same as the MissedCycles in the ExSyncInfo function block, which gives a counter on how many Automation Runtime cycles the Linux DMR process has missed. In AR, this value is naturally always 0.
•missed_dmr_cycles
In each cycle, the Linux DMR sends out a synchronization message that triggers the execution of the exos_datamodel_process() function (which block for this synchronization message). Should the application miss one of these messages (fail to call exos_datamodel_process() within the cycle time of the DMR), this counter is increased. In AR, this value is always 0, as the AR applications do not synchronize with the DMR (unless they are executed in the same taskclass (default TC#2), which implicitly makes them synchronous to the DMR)
The NETTIME accuracy of the AR-Linux connection can be configured in the exostarget Configuration Element.
The ExSyncInfo function block in AR can be used to monitor the current NETTIME precision of the Linux System.