Справочник Пользователя для National Instruments NI-DNET

Скачать
Страница из 86
Chapter 4
NI-DNET Programming Techniques
4-16
ni.com
Main Loop
If your application essentially accesses all DeviceNet input/output data as 
a single image, you would normally wait for read data to become available 
on one of the input connections (such as a strobed I/O connection), read all 
input data, execute your application code, then write all output data. The 
wait is important because it helps to synchronize your application with the 
overall DeviceNet network traffic.
In single-loop applications such as this, you normally set the 
PollMode
 
parameter of 
ncOpenDnetIntf
 to 
Automatic
 or 
Scanned
 so that all poll 
command messages are sent out in quick succession.
Within a single-loop application, error handling is often done for the entire 
application as a whole. In the C programming language, this means that 
when an error is detected with any NI-DNET object, you display the error 
and exit the application. In LabVIEW, this means that you wire all error 
clusters of NI-DNET VIs together.
If your application uses different control code for different DeviceNet 
devices, you might want to split your application into multiple tasks. You 
can easily write a multitasking application by creating a notification for the 
NI-DNET 
Read Avail
 state. This notification occurs when either input 
data is available (to synchronize your code with each device’s 
I/O messages), or an error occurs. In the C programming language, you 
create this notification callback using the 
ncCreateNotification
 
function. In LabVIEW, you create this notification callback using the 
ncCreateOccurrence
 function.
In multiple-loop applications such as this, you normally set the 
PollMode
 
parameter of 
ncOpenDnetIntf
 to 
Individual
 so that each poll 
command message can be sent out at its own individual rate.
Within a multiple-loop application, error handling is done separately for 
each task. In the C programming language, this means that when an error 
is detected, you handle it for the appropriate task, but you do not exit the 
application. In LabVIEW, this means that you only wire the error clusters 
of NI-DNET VIs that apply to each task, and thus you write different 
sub-diagrams that are not wired together in any way.