For further support information, refer to the Technical Support and Professional Services appendix. To comment
on the documentation, send email to techpubs@ni.com.
The CAN/DeviceNet hardware is warranted against defects in materials and workmanship for a period of one year from the date of shipment,
as evidenced by receipts or other documentation. National Instruments will, at its option, repair or replace equipment that proves to be defective
during the warranty period. This warranty includes parts and labor.
The media on which you receive National Instruments software are warranted not to fail to execute programming instructions, due to defects
in materials and workmanship, for a period of 90 days from date of shipment, as evidenced by receipts or other documentation. National
Instruments will, at its option, repair or replace software media that do not execute programming instructions if National Instruments receives
notice of such defects during the warranty period. National Instruments does not warrant that the operation of the software shall be
uninterrupted or error free.
A Return Material Authorization (RMA) number must be obtained from the factory and clearly marked on the outside of the package before
any equipment will be accepted for warranty work. National Instruments will pay the shipping costs of returning to the owner parts which are
covered by warranty.
National Instruments believes that the information in this document is accurate. The document has been carefully reviewed for technical
accuracy. In the event that technical or typographical errors exist, National Instruments reserves the right to make changes to subsequent
editions of this document without prior notice to holders of this edition. The reader should consult National Instruments if errors are suspected.
In no event shall National Instruments be liable for any damages arising out of or related to this document or the information contained in it.
XCEPTASSPECIFIEDHEREIN, NATIONAL INSTRUMENTSMAKESNOWARRANTIES, EXPRESSORIMPLIED, ANDSPECIFICALLYDISCLAIMSANYWAR RANTYOF
E
MERCHANTABILITYORFITNESSFORAPARTICULARPURPOSE . CUSTOMER’SRIGHTTORECOVERDAMAGESCAUSEDBYFAULTORNEGLIGENCEONTHEPART OF
N
ATIONAL INSTRUMENTSSHALLBELIMITEDTOTHEAMOUNTTHERETOFOREPAIDBYTHECUSTOMER. NATIONAL INSTRUMENTSWILLNOTBELIABLEFOR
DAMAGESRESULTINGFROMLOSSOFDATA, PROFITS, USEOFPRODUCTS, ORINCIDENTALORCONSEQUENTIALDAMAGES, EVENIFADVISEDOFTHEPOSS IBILITY
THEREOF. This limitation of the liability of National Instruments will apply regardless of the form of action, whether in contract or tort, including
negligence. Any action against National Instruments must be brought within one year after the cause of action accrues. National Instruments
shall not be liable for any delay in performance due to causes beyond its reasonable control. The warranty provided herein does not cover
damages, defects, malfunctions, or service failures caused by owner’s failure to follow the National Instruments installation, operation, or
maintenance instructions; owner’s modification of the product; owner’s abuse, misuse, or negligent acts; and power failure or surges, fire,
flood, accident, actions of third parties, or other events outside reasonable control.
Copyright
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying,
recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent of National
Instruments Corporation.
Trademarks
CVI™, LabVIEW™, National Instruments™, ni.com™, NI-CAN™, and NI-DNET™ are trademarks of National Instruments Corporation.
Product and company names mentioned herein are trademarks or trade names of their respective companies.
Patents
For patents covering National Instruments products, refer to the appropriate location: Help»Patents in your software, the patents.txt file
on your CD, or
ni.com/patents.
WARNING REGARDING USE OF NATIONAL INSTRUMENTS PRODUCTS
(1) NATIONAL INSTRUMENTS PRODUCTS ARE NOT DESIGNED WITH COMPONENTS AND TESTING FOR A LEVEL OF
RELIABILITY SUITABLE FOR USE IN OR IN CONNECTION WITH SURGICAL IMPLANTS OR AS CRITICAL COMPONENTS IN
ANY LIFE SUPPORT SYSTEMS WHOSE FAILURE TO PERFORM CAN REASONABLY BE EXPECTED TO CAUSE SIGNIFICANT
INJURY TO A HUMAN.
(2) IN ANY APPLICATION, INCLUDING THE ABOVE, RELIABILITY OF OPERATION OF THE SOFTWARE PRODUCTS CAN BE
IMPAIRED BY ADVERSE FACTORS, INCLUDING BUT NOT LIMITED TO FLUCTUATIONS IN ELECTRICAL POWER SUPPLY,
COMPUTER HARDWARE MALFUNCTIONS, COMPUTER OPERATING SYSTEM SOFTWARE FITNESS, FITNESS OF COMPILERS
AND DEVELOPMENT SOFTWARE USED TO DEVELOP AN APPLICATION, INSTALLATION ERRORS, SOFTWARE AND
HARDWARE COMPATIBILITY PROBLEMS, MALFUNCTIONS OR FAILURES OF ELECTRONIC MONITORING OR CONTROL
DEVICES, TRANSIENT FAILURES OF ELECTRONIC SYSTEMS (HARDWARE AND/OR SOFTWARE), UNANTICIPATED USES OR
MISUSES, OR ERRORS ON THE PART OF THE USER OR APPLICATIONS DESIGNER (ADVERSE FACTORS SUCH AS THESE ARE
HEREAFTER COLLECTIVELY TERMED “SYSTEM FAILURES”). ANY APPLICATION WHERE A SYSTEM FAILURE WOULD
CREATE A RISK OF HARM TO PROPERTY OR PERSONS (INCLUDING THE RISK OF BODILY INJURY AND DEATH) SHOULD
NOT BE RELIANT SOLELY UPON ONE FORM OF ELECTRONIC SYSTEM DUE TO THE RISK OF SYSTEM FAILURE. TO AVOID
DAMAGE, INJURY, OR DEATH, THE USER OR APPLICATION DESIGNER MUST TAKE REASONABLY PRUDENT STEPS TO
PROTECT AGAINST SYSTEM FAILURES, INCLUDING BUT NOT LIMITED TO BACK-UP OR SHUT DOWN MECHANISMS.
BECAUSE EACH END-USER SYSTEM IS CUSTOMIZED AND DIFFERS FROM NATIONAL INSTRUMENTS' TESTING
PLATFORMS AND BECAUSE A USER OR APPLICATION DESIGNER MAY USE NATIONAL INSTRUMENTS PRODUCTS IN
COMBINATION WITH OTHER PRODUCTS IN A MANNER NOT EVALUATED OR CONTEMPLATED BY NATIONAL
INSTRUMENTS, THE USER OR APPLICATION DESIGNER IS ULTIMATELY RESPONSIBLE FOR VERIFYING AND VALIDATING
THE SUITABILITY OF NATIONAL INSTRUMENTS PRODUCTS WHENEVER NATIONAL INSTRUMENTS PRODUCTS ARE
INCORPORATED IN A SYSTEM OR APPLICATION, INCLUDING, WITHOUT LIMITATION, THE APPROPRIATE DESIGN,
PROCESS AND SAFETY LEVEL OF SUCH SYSTEM OR APPLICATION.
Contents
About This Manual
How to Use the Manual Set ...........................................................................................ix
This manual describes the basics of DeviceNet and explains how to
develop an application program, including reference to examples. The user
manual also contains hardware information.
How to Use the Manual Set
Installation Guide
(CD Sleeve)
Software and
Hardware
Installation
NI-DNET Users
NI-DNET
User Manual
First-Time
and Examples
Application
Development
Experienced
NI-DNET Users
NI-DNET
Programmer
Reference Manual
Function
and Object
Descriptions
Use the installation guide to install and configure your DeviceNet hardware
and the NI-DNET software.
Use this NI-DNET User Manual to learn the basics of DeviceNet and how
to develop an application program. The user manual also contains
information on DeviceNet hardware.
Use the NI-DNET Programmer Reference Manual for specific information
about each NI-DNET function and object.
The DeviceNet software provided with National Instruments DeviceNet
hardware is called NI-DNET. This section provides an overview of the
NI-DNET software.
Installation and Configuration
Measurement & Automation Explorer (MAX)
Measurement & Automation Explorer (MAX) provides access to all of
your National Instruments products. Like other NI software products,
NI-DNET uses MAX as the centralized location for all configuration
and tools.
To launch MAX, select the Measurement & Automation shortcut on your
desktop, or within your Windows Programs menu under National Instruments»Measurement & Automation.
For information about the NI-DNET software within MAX, consult the
MAX online help. A reference is in the MAX Help menu under
Help Topics»NI-DNET.
1
View help for items in the MAX Configuration tree by using the built-in
MAX help pane. If this help pane is not shown on the far right, select the
Show/Hide button in the upper right.
View help for a dialog box by selecting the Help button in the window.
The following sections provide an overview of some common tasks you
can perform within MAX.
Verify Installation of Your DeviceNet Hardware
Within the Devices & Interfaces branch of the MAX Configuration tree,
NI DeviceNet cards are listed along with other hardware in the local
computer system, as shown in Figure 1-1.
Each card’s name uses the word CAN, because the Controller Area Network is the
communication protocol upon which DeviceNet is built.
If your NI DeviceNet hardware is not listed here, MAX is not configured
to search for new devices on startup. To search for the new hardware,
press <F5>.
To verify installation of your DeviceNet hardware, right-click the
DeviceNet card, then select Self-test. If the self-test passes, the card icon
shows a checkmark. If the self-test fails, the card icon shows an X mark, and
the Test Status in the right pane describes the problem. Refer to
Appendix C, Troubleshooting and Common Questions, for information
about resolving hardware installation problems.
NI-DNET User Manual1-2ni.com
Configure DeviceNet Port
The physical port of each DeviceNet card is listed under the card’s name.
To configure software properties, right-click the port and select
Properties.
In the Properties dialog, you assign an interface name to the port, such as
DNET0 or DNET1. The interface name identifies the physical port within
NI-DNET APIs.
Change Protocol
To change the default protocol for the DeviceNet (CAN) card, right-click
the card and select Protocol. In this dialog you can select either DeviceNet
for NI-DNET (default), or CAN for NI-CAN. For more information, refer
to the section Using NI-CAN with NI-DNET.
LabVIEW Real-Time (RT) Configuration
LabVIEW Real-Time (RT) combines easy-to-use LabVIEW programming
with the power of real-time systems. When you use a National Instruments
PXI controller as a LabVIEW RT system, you can install a PXI DeviceNet
card and use the NI-DNET APIs to develop real-time applications. For
example, you can control a network of DeviceNet devices as a master, and
write your control algorithm in LabVIEW.
Chapter 1NI-DNET Software Overview
When you install the NI-DNET software, the installer checks for the
presence of the LabVIEW RT module. If LabVIEW RT exists, the
NI-DNET installer copies components for LabVIEW RT to your
Windows system. As with any other NI product for LabVIEW RT, you then
download the NI-DNET and NI-CAN software to your LabVIEW RT
system using the Remote Systems branch in MAX. For more information,
refer to the LabVIEW RT documentation.
After you have installed your PXI DeviceNet cards and downloaded the
NI-DNET software to your LabVIEW RT system, you need to verify
the installation. Within the Tools menu in MAX, select NI-DNET»RT Hardware Configuration. The RT Hardware Configuration tool
provides features similar to Devices & Interfaces on your local system.
Use the RT Hardware Configuration tool to self-test the DeviceNet cards
and assign an interface name to each physical DeviceNet port.
Tools
NI-DNET provides tools that you can launch from MAX.
This tool monitors function calls to the NI-DNET APIs. This tool helps in
debugging programming problems in your application. To launch this tool,
open the Software branch of the MAX Configuration tree, right-click
NI Spy, and select Launch NI Spy.
SimpleWho
To provide valid parameters for the NI-DNET open functions
(
ncOpenDnetIntf, ncOpenDnetExplMsg, and ncDnetOpenIO), you
need to determine some basic information about your DeviceNet devices.
This information includes the MAC ID of each device, the I/O connections
it supports, and the input/output lengths for those I/O connections.
In most cases, the vendor of each DeviceNet device provides this
information, but if not, NI-DNET provides a tool that helps you determine
this information. Searching a DeviceNet network to determine information
about connected devices is often referred to as a network who, and thus the
NI-DNET tool is called SimpleWho. This tool is not a complete network
management or configuration tool. It provides read-only information about
the DeviceNet devices connected to your National Instruments DeviceNet
interface.
To launch SimpleWho, right-click the DeviceNet interface (such as DNET0) in MAX, and select SimpleWho.
For more information on the SimpleWho tool, refer to the NI-DNET help
file in MAX. This help file can be opened using the Help button in the
SimpleWho tool itself.
NI-DNET Objects
The NI-DNET software, like the DeviceNet Specification, uses
object-oriented concepts to represent components in the DeviceNet system
(for more information about object-oriented concepts in the DeviceNet
Specification, refer to Appendix A, DeviceNet Overview). However,
whereas in the DeviceNet Specification objects represent a multitude of
components in DeviceNet devices, NI-DNET objects represent
components of the Windows device driver software. The NI-DNET device
driver objects do not correspond directly to objects contained in remote
devices. To facilitate access to the DeviceNet network, the NI-DNET
objects provide a more concise representation of various objects defined in
the DeviceNet Specification.
NI-DNET User Manual1-4ni.com
Interface Object
Chapter 1NI-DNET Software Overview
Much like any other object-oriented system, NI-DNET device driver
objects use the concepts of class, instance, attribute, and service to describe
their features. The NI-DNET device driver software provides three classes
of objects: Interface Objects, Explicit Messaging Objects, and I/O Objects.
You can open an instance of an NI-DNET object using one of the three
open functions (
ncOpenDnetIO). The services for an NI-DNET object are accomplished
ncOpenDnetExplMsg, ncOpenDnetIntf, or
using the NI-DNET functions, which can be called directly from your
programming environment (such as Microsoft C/C++ or LabVIEW). The
essential attributes of an NI-DNET object are initialized using its open
function; you can access other attributes using
ncSetDriverAttr. The attributes of NI-DNET device driver objects are
ncGetDriverAttr or
called driver attributes, to differentiate them from actual attributes in
remote DeviceNet devices.
For complete information on each NI-DNET object, including its driver
attributes and supported functions (services), refer to your NI-DNET Programmer Reference Manual.
The Interface Object represents a DeviceNet interface (physical DeviceNet
port on your DeviceNet board). Since this interface acts as a device on the
DeviceNet network much like any other device, it is configured with its
own MAC ID and baud rate.
Use the Interface Object to do the following:
•Configure NI-DNET settings that apply to the entire interface
•Start and stop communication for all NI-DNET objects associated with
the interface
Explicit Messaging Object
The Explicit Messaging Object represents an explicit messaging
connection to a remote DeviceNet device (physical device attached to your
interface by a DeviceNet cable). Since only one explicit messaging
connection is created for a given device, the Explicit Messaging Object is
also used for features that apply to the device as a whole.
Use the Explicit Messaging Object to do the following:
•Execute the DeviceNet Get Attribute Single service on the remote
device (
•Execute the DeviceNet Set Attribute Single service on the remote
device (
•Send any other explicit message request to the remote device and
receive the associated explicit message response
(
•Configure NI-DNET settings that apply to the entire remote device
I/O Object
The I/O Object represents an I/O connection to a remote DeviceNet device
(physical device attached to your interface by a DeviceNet cable). The
I/O Object usually represents I/O communication as a master with a remote
slave device, but it can also be used for I/O communication as a slave.
The I/O Object supports as many master/slave I/O connections as currently
allowed by the DeviceNet Specification. This means that you can use
polled, strobed, and COS/cyclic I/O connections simultaneously for a given
device. As specified by the DeviceNet Specification, only one master/slave
I/O connection of a given type can be used for each device (MAC ID). For
example, you cannot open two polled I/O connections for the same device.
Use the I/O Object to do the following:
•Read data from the most recent message received on the
I/O connection (
•Write data for the next message produced on the I/O connection
(
ncSetDnetAttribute)
ncWriteDnetExplMsg, ncReadDnetExplMsg)
ncReadDnetIO)
ncWriteDnetIO)
Example
Figure 1-2 shows an example of how NI-DNET objects can be used to
communicate on a DeviceNet network. This example shows three
DeviceNet devices. The first device (at MAC ID 1) is the National
Instruments DeviceNet interface. The second device (at MAC ID 5) uses
NI-DNET to access a polled and a COS I/O connection simultaneously.
The third device (at MAC ID 8) uses NI-DNET to access an explicit
messaging connection and a strobed I/O connection.
NI-DNET User Manual1-6ni.com
Chapter 1NI-DNET Software Overview
Access to device at
MAC ID 5
I/O Object
Device MAC ID = 5
Connection Type = COS
I/O Object
Device MAC ID = 5
Connection Type = Poll
Your National Instruments
DeviceNet Interface
Interface Object
Interface MAC ID = 1
Baud Rate = 500K
Figure 1-2. NI-DNET Objects for a Network of Three Devices
Using NI-CAN with NI-DNET
Controller Area Network (CAN) is the low-level protocol used for
DeviceNet communications. In addition to the NI-DNET functions, your
National Instruments DeviceNet hardware can also be used for low-level
access to CAN messages using the NI-CAN software. NI-CAN is intended
primarily for applications that require direct access to CAN messages, such
as test applications for automotive (non-DeviceNet) networks. When
connecting to a DeviceNet network, the NI-CAN capabilities are useful for
the following applications:
•Low-level monitoring of CAN messages to determine conformance to
DeviceNet specifications
•Implementation of sections of the DeviceNet Specification yourself,
such as custom configuration tools
Access to device at
Explicit Messaging
Object
Device MAC ID = 8
MAC ID 8
I/O Object
Device MAC ID = 8
Connection Type = Strobe
NI-CAN uses the same software infrastructure as NI-DNET, so both APIs
can be used with the same CAN card. The general rule is that each CAN
card can only be used for one API at a time.
Use of NI-DNET is restricted to port 1 (top port) of Series 1 CAN cards.
For more information on hardware provided in CAN kits, refer to
Chapter 2, NI-DNET Hardware Overview.
You can view each CAN card in MAX with either DeviceNet or CAN
features. To change the view of a CAN card in MAX, right-click the card
and select Protocol. In this dialog you can select either DeviceNet for
NI-DNET (default), or CAN for NI-CAN. When the CAN protocol is
selected, you can access CAN tools in MAX, such as the Bus Monitor tool
that displays CAN messages in their raw form.
In order to develop NI-CAN applications, you must install NI-CAN
components such as documentation and examples. The NI-CAN software
components are available within the NI-DNET installer.
Launch the
manner as your original installation (CD or
setup.exe program for the NI-DNET installer in the same
ni.com download). Within
the installer, select both NI-DNET and NI-CAN components in the
feature tree.
When you right-click a port in MAX and select Properties, the resulting
Interface selection uses the syntax
CAN
x
or DNETx based on your protocol
selection. Regardless of which protocol is selected, the number x is the only
relevant identifier with respect to NI-CAN and NI-DNET functions. For
example, if you select DNET0 as an interface in MAX, you can run an
NI-DNET application that uses DNET0, then you can run an NI-CAN
application that uses CAN0. Both applications refer to the same port,
and can run at different times, but not simultaneously.
NI-DNET User Manual1-8ni.com
NI-DNET Hardware Overview
Types of Hardware
The National Instruments DeviceNet hardware includes the PCI-CAN,
PXI-8461, and PCMCIA-CAN.
The PCI-CAN is software configurable and compliant with the PCI Local
Bus Specification. It features the National Instruments MITE bus interface
chip that connects the card to the PCI I/O bus. With a PCI-CAN, you can
make your PC-compatible computer with PCI Local Bus slots
communicate with and control DeviceNet devices.
The PXI-8461 is software configurable and compliant with the PXI Specification and CompactPCI Specification. It features the National
Instruments MITE bus interface chip that connects the card to the PXI or
CompactPCI I/O bus. With a PXI-8461 card, you can make your PXI or
CompactPCI chassis communicate with and control DeviceNet devices.
PCMCIA-CAN hardware is a 16-bit, Type II PC Card that is software
configurable and compliant with the PCMCIA standards for 16-bit PC
cards. With a PCMCIA-CAN card, you can make your PC-compatible
notebook with PCMCIA slots communicate with and control DeviceNet
devices.
2
The PCI-CAN, PXI-8461, or PCMCIA-CAN in your DeviceNet kit is fully
compliant with the DeviceNet Specification.
All of the DeviceNet hardware uses the Intel 386EX embedded processor
to implement time-critical features provided by the NI-DNET software.
The cards communicate with the NI-DNET driver through on-board shared
memory and an interrupt.
The DeviceNet physical communication link protocol is based on the
Controller Area Network (CAN) protocol. The physical layers of the
PCI-CAN, PXI-8461, and PCMCIA-CAN fully conform to the DeviceNet
physical layer requirements. The physical layer is optically isolated to
500 V and is powered from the DeviceNet bus power supply. DeviceNet
interfacing is accomplished using the Intel 82527 CAN controller chip.
For more information on the DeviceNet physical layer and cables used to
connect to your DeviceNet devices, refer to Appendix B, Cabling
Requirements.
For connection to the network, the PCI-CAN, PXI-8461, and
PCMCIA-CAN for DeviceNet provide combicon-style pluggable screw
terminals, as required by the DeviceNet Specification.
Differences Between CAN Kits and DeviceNet Kits
National Instruments provides hardware/software kits for both CAN and
DeviceNet. Since the CAN kits apply to a broad range of applications such
as automotive testing, the hardware in those kits offers a wide variety of
options. To ensure that the hardware product operates properly on a
DeviceNet network, we recommend that you purchase DeviceNet kits only.
The card provided in your DeviceNet kit can be used with both NI-DNET
and NI-CAN software.
Hardware in CAN kits is referenced as Series 2. Hardware in DeviceNet
kits is referenced as Series 1. Series 2 CAN cards cannot be used with the
NI-DNET software (NI-CAN only). The features of Series 2 CAN cards are
specifically designed for CAN applications, and provide no distinct
advantages for DeviceNet. For more information on Series 2 hardware,
refer to the hardware overview in the NI-CAN Hardware and Software Manual.
Hardware in CAN kits offers 1-port and 2-port variants. NI-DNET operates
on one port only. If you use NI-DNET on a 2-port Series 1 CAN card, only
the top port can be used.
Hardware in CAN kits offer special transceivers (physical layer) such as
Low-Speed/Fault-Tolerant (LS) and Single-Wire (SW). Hardware in CAN
kits also offer the option to power the transceiver from the card, not the
network. These transceivers cannot be used with DeviceNet. Only
High-Speed (HS) transceivers comply with the DeviceNet specification.
Hardware in CAN kits use the DB-9 D-SUB connector. Hardware in
DeviceNet kits use the combicon-style connector from the DeviceNet
specification.
NI-DNET User Manual2-2ni.com
Developing Your Application
This chapter explains how to develop an application using the NI-DNET
functions.
Accessing NI-DNET from your Programming
Environment
3
LabVIEW
Applications can access the NI-DNET driver software by using either
LabVIEW, LabWindows
C/C++, or Visual Basic. If you are using any other development
environment, you must access the DNET library directly. Each of these
language interface techniques is summarized below.
For applications written in LabVIEW, NI-DNET provides a complete
function library, front panel controls, and examples.
NI-DNET functions and controls are available in the LabVIEW palettes. In
LabVIEW 7.1 or later, the NI-DNET palette is located within the top-level
NI Measurements palette. In earlier LabVIEW versions, the NI-DNET
palette is located at the top-level.
The reference for each NI-DNET function is provided in the NI-DNET Programmer Reference Manual. To access the reference for a function
from within LabVIEW, press <Ctrl-H> to open the help window, click on
the NI-DNET function, and then follow the link.
The NI-DNET software includes a full set of examples for LabVIEW.
These examples teach basic NI-DNET programming as well as advanced
topics. The example help describes each example and includes a link you
can use to open the VI. The NI-DNET example help is in Help»Find Examples»Hardware Input and Output»DeviceNet.
Within LabWindows/CVI, the NI-DNET function panel is located in
Library»NI-DNET. Like other LabWindows/CVI function panels, the
NI-DNET function panel provides help for each function and the ability to
generate code.
The reference for each NI-DNET function is provided in the NI-DNET Programmer Reference Manual. You can access reference for each
function directly from within the function panel.
The header file for NI-DNET is
nidnet.lib.
The NI-DNET software includes a full set of examples for
LabWindows/CVI. The NI-DNET examples are installed in the
LabWindows/CVI directory under samples\nidnet. Each example
provides a complete LabWindows/CVI project (
of each example is provided in comments at the top of the
When you compile your LabWindows/CVI application for NI-DNET,
it is automatically linked with
LabWindows/CVI. When NI-DNET is installed, the installation program
checks to see which compatible C compiler you are using with
LabWindows/CVI (Microsoft or Borland), and copies an appropriate
nidnet.lib for that compiler.
Microsoft Visual Basic
To create an NI-DNET application in Visual Basic, add the nidnet.bas
file to your project. This allows you to call any NI-DNET function file from
your code.
The
NI-DNET folder. The typical path to this folder is \Program Files\
National Instruments\NI-DNET\MS Visual Basic
nidnet.h. The library for NI-DNET is
.prj file). A description
.c file.
nidnet.lib, the link library for
nidnet.bas file is located in the MS Visual Basic folder of the
.
The reference for each NI-DNET function is provided in the NI-DNET
Programmer Reference Manual, which you can open from Start»All
Programs»National Instruments»NI-DNET.
You can find examples for Visual Basic in the
MS Visual Basic folder. Each example is in a separate folder. A .vbp
examples subfolder of the
file with the same name as the example opens the Visual Basic project. A
description of the example is located in a Help form within the project.
NI-DNET User Manual3-2ni.com
Microsoft C/C++
Chapter 3Developing Your Application
The NI-DNET software supports Microsoft Visual C/C++ version 6.
The header file and library for Visual C/C++ 6 are in the
folder of the
Files\National Instruments\NI-DNET\MS Visual C
NI-DNET, include the
the
nidnetms.lib library file.
For C applications (files with a
adding a
#include "nidnet.h"
NI-DNET folder. The typical path to this folder is \Program
nidnet.h header file in your code, then link with
.c extension), include the header file by
#include to the beginning of your code, as in:
MS Visual C
. To use
For C++ applications (files with .cpp extension), define _cplusplus
before including the header, such as:
#define _cplusplus
#include "nidnet.h"
The _cplusplus define enables the transition from C++ to the C language
NI-DNET functions.
The reference for each NI-DNET function is provided in the NI-DNET
Programmer Reference Manual, which you can open from Start»All
Programs»National Instruments»NI-DNET. You can find examples for
Visual C++ in the
example is in a separate folder. A
examples subfolder of the MS Visual C folder. Each
.c file with the same name as the
example contains a description the example in comments at the top of the
code. At the command prompt, after setting MSVC environment variables
(such as with MS
vcvars32.bat), you can build each example using a
command such as:
cl –I.. singin.c ..\nidnetms.lib
Borland C/C++
The NI-DNET software supports Borland C/C++ version 5 or later.
The header file and library for Borland C/C++ are in the Borland C folder
of the NI-DNET folder. The typical path to this folder is
For C applications (files with .c extension), include the header file by
adding a
#include "nidnet.h"
For C++ applications (files with .cpp extension), define _cplusplus
before including the header, such as:
#define _cplusplus
#include "nidnet.h"
The _cplusplus define enables the transition from C++ to the C language
NI-DNET functions.
The reference for each NI-DNET function is provided in the NI-DNET
Programmer Reference Manual, which you can open from Start»All
Programs»National Instruments»NI-DNET.
#include to the beginning of your code, like this:
You can find examples for Visual C++ in the
Borland C folder. Each example is in a separate folder. A .c file with the
same name as the example contains a description the example in comments
at the top of the code.
Other Programming Languages
You can directly access NI-DNET from any programming environment
that allows you to request addresses of functions that a dynamic link library
(DLL) exports. The functions used to access a DLL in this manner are
provided by the Microsoft Win32 functions of Windows. Using these
Microsoft Win32 functions to access a DLL is often referred to as direct
entry. To use direct entry with NI-DNET, complete the following steps:
1.Load the NI-DNET DLL,
The following C language code fragment illustrates how to call the
Win32
LoadLibrary function and check for an error.
#include <windows.h>
#include "nidnet.h"
HINSTANCE NidnetLib = NULL;
NidnetLib=LoadLibrary("nican.dll");
if (NidnetLib == NULL) {
return FALSE; /*Error*/
}
examples subfolder of the
nican.dll.
NI-DNET User Manual3-4ni.com
Chapter 3Developing Your Application
2.Get the addresses for the NI-DNET DLL functions you will use.
Your application must use the Win32
GetProcAddress function to
get the addresses of the NI-DNET functions your application needs.
For each NI-DNET function used by your application, you must define
a direct entry prototype. For the prototypes for each function exported
by
nican.dll, refer to the NI-DNET Programmer Reference Manual.
The following code fragment illustrates how to get the addresses of the
ncOpenDnetIO, ncCloseObject, and ncReadDnetIO functions.
3.Configure your application to de-reference the pointer to call an
NI-DNET function, as illustrated by the following code.
NCTYPE_STATUS status;
NCTYPE_OBJH MyObjh;
status = (*PncOpenDnetIO) ("DNET0", &MyObjh);
if (status < 0) {
printf("ncOpenDnetIO failed");
}
4.Free nican.dll.
Before exiting your application, you need to free
nican.dll with the
following command.
FreeLibrary(NidnetLib);
Programming Model for NI-DNET Applications
The following steps provide an overview of how to use the NI-DNET
functions in your application. The steps are shown in Figure 3-1 in
flowchart form. The NI-DNET functions are described in detail in the
NI-DNET Programmer Reference Manual.
NI-DNET User Manual3-6ni.com
Chapter 3Developing Your Application
Start
1. Open Interface object
2. Open all I/O and Explicit Messaging (EM)
objects required for your application
3. Call ncSetDriverAttr, if needed
Start communication
Your DeviceNet Application:
• Write output data
• Wait for available input data
• Read input data
• Get or Set DeviceNet Attribute
• Open/Close any new I/O or EM
connection if the interface PollMode
is not equal to NC_POLL_AUTO
Finished?
Yes
Stop communication
1. Close I/O and EM objects.
2. Close the Interface object.
End
No
Figure 3-1. General Programming Steps for an NI-DNET Application