Chapter 2
Developing Your Application
2-4
ni.com
status = (*PncOpenObject) ("CAN0", &MyObjh);
if (status < 0) {
printf("ncOpenObject failed");
}
Before exiting your application, you need to free
nican.dll
with the
following command:
FreeLibrary(NicanLib);
For more information on direct entry, refer to the Win32 SDK (Software
Development Kit) online help.
Choosing Which NI-CAN Objects to Use
An application written for NI-CAN communicates on the network by using
various objects. Which NI-CAN objects to use depends largely on the
needs of your application. The following sections discuss the objects
provided by NI-CAN, and reasons why you might use each class of object.
Using CAN Network Interface Objects
The CAN Network Interface Object encapsulates a physical interface to a
CAN network, usually a CAN port on an AT or PCI interface.
You use the CAN Network Interface Object to read and write complete
CAN frames. As a CAN frame arrives from over the network, it can be
placed into the read queue of the CAN Network Interface Object. You can
retrieve CAN frames from this read queue using the
ncRead
function.
For CAN Network Interface Objects, the
ncRead
function provides a
timestamp of when the frame was received, the arbitration ID of the frame,
the type of frame (data or remote), the data length, and the data bytes. You
can also use the CAN Network Interface Object to write CAN frames using
the
ncWrite
function.
Some possible uses for the CAN Network Interface Object include the
following:
•
You can use the read queue to log all CAN frames transferred across
the network. This log is useful when you need to view preceding CAN
traffic to verify that all CAN devices are functioning properly.
•
You can use the write queue to transmit a sequence of CAN frames in
quick succession. This is useful for applications in which you need to
simulate a specific sequence of CAN frames to verify proper device
operation.