Table of Contents

Advertisement

Quick Links

CAN
NI-CAN
User Manual
NI-CAN User Manual
August 2000 Edition
Part Number 370290A-01

Advertisement

Table of Contents
loading

Summary of Contents for National Instruments NI-CAN

  • Page 1 ™ NI-CAN User Manual NI-CAN User Manual August 2000 Edition Part Number 370290A-01...
  • Page 2 Sweden 08 587 895 00, Switzerland 056 200 51 51, Taiwan 02 2528 7227, United Kingdom 01635 523545 For further support information, see the Technical Support Resources appendix. To comment on the documentation, send e-mail to techpubs@ni.com © Copyright 1996, 2000 National Instruments Corporation. All rights reserved.
  • Page 3 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.
  • Page 4 Classification requirements are the same for the Federal Communications Commission (FCC) and the Canadian Department of Communications (DOC). Changes or modifications not expressly approved by National Instruments could void the user’s authority to operate the equipment under the FCC Rules.
  • Page 5 interference to radio or television reception, which can be determined by turning the equipment off and on, the user is encouraged to try to correct the interference by one or more of the following measures: • Reorient or relocate the receiving antenna. •...
  • Page 6: Table Of Contents

    Acknowledgment Bit (ACK) ............1-5 End of Frame..................1-5 CAN Error Detection and Confinement ............1-5 Error Detection..................1-5 Error Confinement ................1-6 Low-Speed CAN .....................1-8 NI-CAN Software Overview ..................1-9 Independent Design ..................1-9 Object-Oriented Design...................1-9 NI-CAN Object Hierarchy ................1-10 NI-CAN Software Components ..............1-12 NI-CAN Driver and Utilities.............1-12 Firmware Image Files ...............1-13...
  • Page 7 Contents Chapter 2 Developing Your Application Choosing Your Programming Method ................2-1 Choosing a Method to Access the NI-CAN Software ........2-1 G Language (LabVIEW) Function Library ........2-1 C/C++ Language Interfaces.............. 2-1 Direct Entry Access ................2-2 Choosing Which NI-CAN Objects to Use ............2-4 Using CAN Network Interface Objects..........
  • Page 8 Contents Chapter 5 NI-CAN Configuration Utility Overview........................5-1 Starting the NI-CAN Configuration Utility in Windows 98/95 ........5-1 Starting the NI-CAN Configuration Utility in Windows NT ........5-2 Configuring Objects with the NI-CAN Configuration Utility........5-3 Select the Port....................5-4 Select the CAN Network Interface Object Name..........5-4 Specify the Configuration Attributes...............5-4...
  • Page 9 Program Flowchart for Example 2............4-6 Figure 4-3. Program Flowchart for Example 3............4-8 Figure 5-1. NI-CAN Settings Dialog Box for an AT-CAN/2 ......... 5-3 Figure 5-2. CAN Object Configuration Dialog Box ..........5-5 Figure A-1. Selecting an Interface to Remove from Windows 98/95 ...... A-2 Figure A-2.
  • Page 10: About This Manual

    Use the getting started manual to install and configure your CAN hardware and the NI-CAN software. Use this NI-CAN User Manual to learn the basics of CAN and how to develop an application program. The user manual also contains detailed examples.
  • Page 11: Related Documentation

    Data Communications, Part 1 and 2 • CAN Specification Version 2.0, 1991, Robert Bosch Gmbh., Postfach 500, D-7000 Stuttgart 1 • LabVIEW Online Reference • Win32 Software Development Kit (SDK) online help • Microsoft User’s Guide NI-CAN User Manual www.ni.com...
  • Page 12: Introduction

    Introduction This chapter gives an overview of CAN and the NI-CAN software. CAN Overview History and Usage of CAN In the past few decades, the need for improvements in automotive technology has led to increased usage of electronic control systems for functions such as engine timing, anti-lock brake systems, and distributorless ignition.
  • Page 13: Can Identifiers And Message Priority

    CAN’s identifier is often referred to as an arbitration ID. This ability to resolve collisions and continue with high-priority transmissions is one feature that makes CAN ideal for real-time applications. NI-CAN User Manual ni.com...
  • Page 14: Can Frames

    Arbitration ID of Arbitration ID Figure 1-2. Standard and Extended Frame Formats Start of Frame (SOF) Start of Frame is a single bit (0) that marks the beginning of a CAN frame. © National Instruments Corporation NI-CAN User Manual...
  • Page 15: Arbitration Id

    CRC based on the preceding bits of the frame, and all receivers recalculate it for comparison. If the CRC calculated by a receiver differs from the CRC in the frame, the receiver detects an error. NI-CAN User Manual ni.com...
  • Page 16: Acknowledgment Bit (Ack)

    CAN devices detect the following errors, which are described in the following sections: • Bit error • Stuff error • CRC error © National Instruments Corporation NI-CAN User Manual...
  • Page 17: Error Confinement

    The transmit error counter is incremented when errors are detected for transmitted frames, and decremented when a frame is transmitted successfully. The receive error counter is used for received frames in much the same way. The error NI-CAN User Manual ni.com...
  • Page 18 Thus, if a CAN network consists of only one device (for instance, if you do not connect a cable to your National Instruments CAN interface), and that device attempts to transmit a frame, it retransmits continuously but never goes into bus off state (although it eventually reaches error passive state).
  • Page 19: Low-Speed Can

    (with both counters reset to zero) by manual intervention. For sensor/actuator types of devices, this often involves powering the device off then on. For NI-CAN network interfaces, communication can be started again using a function such as ncAction Low-Speed CAN Low-speed CAN is commonly used to control “comfort”...
  • Page 20: Ni-Can Software Overview

    The NI-CAN Application Programming Interface (API), like most National Instruments APIs, is largely independent of operating system and programming language. You can use NI-CAN in a wide variety of programming environments, including LabVIEW and C programming environments such as LabWindows/CVI. Applications written for NI-CAN are also portable across different operating systems, such as Windows 98/95 and Windows NT.
  • Page 21: Ni-Can Object Hierarchy

    ID 13. The frame data consists of a single byte—zero if the button is off, one if the button is on. For an NI-CAN application to obtain the current state of the pushbutton, it transmits a CAN remote frame with standard arbitration ID 13.
  • Page 22 Figure 1-4 shows how NI-CAN objects encapsulate access to this CAN device network. The ovals in Figure 1-4 indicate NI-CAN objects, and the dotted lines indicate what each object encapsulates.
  • Page 23: Ni-Can Software Components

    • A documentation file, , contains important information readme.txt about the NI-CAN software and a description of any new features. Before you use the software, read this file for the most recent information. • A 32-bit, multitasking aware device driver is used to interface with National Instruments CAN hardware.
  • Page 24: Firmware Image Files

    All National Instruments CAN hardware products contain an on-board microprocessor. This microprocessor is used so that all time-critical aspects of the NI-CAN software can be executed separately from your Windows application. The firmware image which runs on the on-board microprocessor, , is loaded and executed automatically when nican.nfw...
  • Page 25: Rtsi Bus Overview

    PCI-CAN and AT-CAN series RTSI interfaces. For the PXI-846x series CAN boards, the RTSI bus consists of using the National Instruments PXI trigger bus to route timing and trigger signals between the PXI-846x series board and other National Instruments RTSI-equipped PXI boards.
  • Page 26: Synchronizing With Ni-Daq

    Before using RTSI between CAN and DAQ, you must decide which board to use as the Master. NI-CAN software allows easy configuration of the Network Interface or CAN Objects as a Master or Slave. Note that both configurations can exist on the same board, but not on the same object.
  • Page 27 The last three modes configure the object (Network Interface or CAN Object) as a Master. For more information on these modes and a list of examples that configure and test them, refer to the NI-CAN Programmer Reference Manual. NI-CAN User Manual 1-16...
  • Page 28: Developing Your Application

    Functions palette for placement into your diagram. The NI-CAN controls can be found in your LabVIEW Controls palette for placement into your front panel. For a description of how each NI-CAN function in LabVIEW maps to the corresponding C language NI-CAN function, refer to the NI-CAN Programmer Reference Manual.
  • Page 29: Direct Entry Access

    C++ to the C language NI-CAN functions. For Microsoft Visual C++, link your application with the NI-CAN language interface for Microsoft C/C++, nicanmsc.lib For Borland C/C++ (5.0 or later), link your application with the NI-CAN language interface for Borland C/C++, . For Borland nicanbor.lib C/C++ 4.5, you must use direct entry access for NI-CAN.
  • Page 30 Next, your application must use the Win32 function to GetProcAddress get the addresses of the NI-CAN functions your application needs to use. For each NI-CAN function used by your application, you must define a direct entry prototype. For the prototypes for each function exported by , refer to the NI-CAN Programmer Reference Manual.
  • Page 31: Choosing Which Ni-Can Objects To Use

    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.
  • Page 32: Using Can Objects

    CAN Object, data transfer is handled in the background using read and write queues. For example, if the CAN Object periodically polls for data, the NI-CAN driver automatically handles the periodic transmission of remote frames, and stores incoming...
  • Page 33: Programming Model For Ni-Can Applications

    ID, especially when that data transfer needs to occur periodically. Programming Model for NI-CAN Applications The following steps demonstrate how to use the NI-CAN functions in your application. The steps are shown in Figure 2-1 in flowchart form. NI-CAN User Manual...
  • Page 34 • Wait for Data Available (ncWaitForState, ncCreateNotification) • Read Data (ncRead) • Write Data (ncwrite) and so on Finished CAN Programming? Close Object (ncCloseObject) Are All Objects Closed? Figure 2-1. General Program Steps Using NI-CAN Functions © National Instruments Corporation NI-CAN User Manual...
  • Page 35: Step 1. Configure Objects

    NI-CAN calls for that object. When you are using the G language (LabVIEW) function library, this handle is passed through the upper left and right terminals of each NI-CAN function used after the open.
  • Page 36: Step 4. Communicate Using Objects

    For more information on ncWaitForState , refer to the NI-CAN Programmer Reference ncCreateNotification Manual. When receiving data from the device, if your only requirement is to obtain the most recent data, you are not required to wait for the state.
  • Page 37: Checking Status Of Function Calls

    NI-CAN Status Format To provide the maximum amount of information, the status returned by NI-CAN functions is encoded as a signed 32-bit integer. The format of this integer is shown in Figure 2-2. 31 30 29–16...
  • Page 38: Qualifier

    This ensures that all NI-CAN objects are closed properly when execution stops due to an error. When a warning occurs in an NI-CAN function, execution proceeds normally. To detect suspected warnings in your application, you can write...
  • Page 39: Checking Status In C

    Chapter 2 Developing Your Application For each NI-CAN function, you can find numeric values for the returned status code and qualifier in the online description of the function, which you can access in the Block Diagram by selecting the function and typing <Ctrl-H>.
  • Page 40: Ni-Can Programming Techniques

    FIFO (first-in-first-out) buffers. The basic behavior of such queues is common to all NI-CAN objects. There are two basic types of NI-CAN queues: the read queue and the write queue. NI-CAN uses the read queue to store incoming network data items in the order they arrive.
  • Page 41: Full Queues

    NC_ST_WRITE_SUCCESS usual, but you can ignore them if you want only the most recent data. For example, when NI-CAN writes a new data item to the read buffer, the state becomes true until the data item is read. If you...
  • Page 42 Chapter 3 NI-CAN Programming Techniques CAN Objects. The flowchart in Figure 3-1 shows the steps performed by NI-CAN when a CAN frame is received. Frame Received Arbitration ID Handled by an Open CAN Object Uses Frame CAN Object? CAN Network Interface Object...
  • Page 43: Detecting State Changes

    Chapter 3 NI-CAN Programming Techniques comparator attributes to . By doing this, the CAN NC_CAN_ARBID_NONE communications controller chip is best able to filter out all incoming frames except those handled by CAN Objects. Detecting State Changes You can detect state changes for an object using one of the following schemes: •...
  • Page 44: Application Examples

    This chapter describes the sample applications provided with your NI-CAN software. The examples in this chapter are designed to illustrate basic NI-CAN programming, as well as specific concepts and techniques that can help you write your own applications. The description of each example includes the programmer’s task, a program flowchart, and numbered steps that...
  • Page 45: Rtsi Examples

    Object to transmit different speeds, the test engineer can verify that the speed display always shows the correct speed. To use NI-CAN to test the speed sensor, the engineer uses a CAN Object to simulate the role of the speed display. This CAN Object is configured to receive speeds from the sensor and display them.
  • Page 46 CAN Network ncConfig Interface Objects for both ports ( ). Normally, this CAN0 CAN1 configuration would be handled using the NI-CAN Configuration utility, but is used instead to keep the example ncConfig self-contained. The application calls to configure the CAN Objects for...
  • Page 47: Example 2. Simple Can Bus Analyzer

    C programming language. It illustrates a simple CAN bus analyzer using the CAN Network Interface Object. An automotive test engineer is writing a diagnostic utility for use in service bays. This utility is used to diagnose problems with car models that use NI-CAN User Manual ni.com...
  • Page 48 NC_ST_READ_AVAIL state. After creating the notification thread, the main thread proceeds to Step 7. The notification thread remains idle until its callback function is invoked by the NI-CAN driver. If the callback function detects the state, NC_ST_READ_AVAIL is called to read the frame, and the frame is placed into the ncRead buffer for processing by the main thread.
  • Page 49: Example 3. Interactive Can Example

    This example provides an overview of how the features of NI-CAN are used within LabVIEW. It provides a LabVIEW front panel that you can use to interact with CAN devices and to learn the basic operation of NI-CAN. front panel provides CAN Network Interface and interact.vi...
  • Page 50 CAN frame has been received. If returns a code of ncRead zero (success) in its cluster, the received CAN frame is error out inserted into the Received Frames array. © National Instruments Corporation NI-CAN User Manual...
  • Page 51 CAN Object to update the data used for periodic ncWrite transmissions. If no NI-CAN error has occurred and the Stop button has not been selected, the application loops back to Step 5. The application calls to close the CAN Network...
  • Page 52: Ni-Can Configuration Utility

    Windows NT Control Panel. You can use the NI-CAN Configuration utility to view or modify the configuration of NI-CAN objects. For each CAN interface in your system, you can use the NI-CAN Configuration utility to configure each CAN port as a CAN Network Interface Object.
  • Page 53: Starting The Ni-Can Configuration Utility In Windows Nt

    Windows NT Control Panel, and double-click on NI-CAN Configuration. Because you can use the NI-CAN Configuration utility to modify the configuration of the NI-CAN kernel drivers, you must be logged on to Windows NT as the to make any changes. If you start the...
  • Page 54: Configuring Objects With The Ni-Can Configuration Utility

    Note specify valid hardware resources for the CAN interface using the Resources button before using your National Instruments CAN interface with Windows NT. For information on verifying proper resource assignment, refer to your NI-CAN getting started manual. After you have finished configuring your CAN interfaces, click on the OK button to close the dialog box.
  • Page 55: Select The Port

    AT-CAN interfaces installed in the same computer. To access online help for the NI-CAN Configuration utility, right-click the mouse anywhere on the Settings tab, and select Full Help from the pop-up menu that appears.
  • Page 56: Configure The Can Objects

    Use the CAN Object list box to select the CAN Object you want to configure. The list box lists all existing CAN Objects. The names are the same as those used with NI-CAN, with the arbitration ID of the CAN Object shown in decimal format ( , and so on).
  • Page 57: Add Can Object Configurations

    #MotorSpeed CAN0::STD5 information on user-defined aliases, refer to the description of in the NI-CAN Programmer Reference Manual. ncOpenObject After entering the arbitration ID, click on the Add button to add the CAN Object to the list. You may then specify the attributes for the CAN Object.
  • Page 58: Exit The Can Object Setting Dialog Box

    CAN interface. Complete the Configuration When you have finished using the NI-CAN Configuration utility, click OK to close the dialog box and saves any changes you have made, or click Cancel to close the dialog box without saving any changes you have made.
  • Page 59: Uninstalling The Hardware And Software

    System Properties dialog box that appears, click the View devices by type button at the top of the Device Manager tab, and double-click on the National Instruments CAN Interfaces icon. To remove an interface, select it from the list of interfaces under National Instruments CAN Interfaces as shown in Figure A-1, and click the Remove button.
  • Page 60 CAN interfaces from your computer. Power off your computer and physically remove the CAN interfaces. Uninstalling the NI-CAN Software Before uninstalling the NI-CAN software, you should remove all CAN interface hardware from your computer. Complete the following steps to remove the NI-CAN software.
  • Page 61 Figure A-2. Add/Remove Programs Properties Dialog Box Select the NI-CAN software you want to remove, and click the Add/Remove button. The uninstall program runs and removes all folders, utilities, device drivers, DLLs, and registry entries associated with the NI-CAN software.
  • Page 62 Appendix A Uninstalling the Hardware and Software Figure A-3. NI-CAN Uninstallation Results The uninstall program removes only items that the installation program installed. If you add anything to a directory that was created by the installation program, the uninstall program does not delete that directory, because the directory is not empty after the uninstallation.
  • Page 63: Windows 98/95: Troubleshooting And Common Questions

    Device Manager tab and click the View devices by type radio button at the top of the tab. If there is no National Instruments CAN Interfaces item and you are certain you have a CAN interface installed, refer to the No National Instruments CAN Interfaces section of this appendix.
  • Page 64 National Instruments. Missing CAN Interface If the National Instruments CAN Interfaces item exists, but the CAN interface you are looking for is not listed there, the CAN interface is not properly installed. For National Instruments CAN hardware, this problem indicates that the interface is not physically present in the system.
  • Page 65 If your computer does not have any available Interrupt Request levels, Windows 98/95 might configure your CAN interface without an Interrupt Request level. The NI-CAN software cannot function without an Interrupt Request level. Another way to verify this problem is to look at the Resource settings list on the Resources tab to verify that the CAN interface was not assigned an Interrupt Request level.
  • Page 66 NI-CAN Diagnostic utility again. NI-CAN Software Problem Encountered This error occurs if the NI-CAN Diagnostic utility detects that it is unable to communicate correctly with the CAN hardware using the installed NI-CAN software. If you get this error, shut down your computer, restart it, and run the NI-CAN Diagnostic utility again.
  • Page 67 Start»Programs»National Instruments CAN. The NI-CAN Diagnostic utility displays information about the version of the NI-CAN software currently installed. What do I do if the NI-CAN Diagnostic utility fails with an error? Refer to the Troubleshooting Diagnostic Utility Failures...
  • Page 68 For information about using NI-CAN language interfaces, refer to Chapter 2, Developing Your Application. How do I use NI-CAN from within LabVIEW? For information about using NI-CAN from within LabVIEW, refer to Chapter 2, Developing Your Application. Why does the uninstall program leave some components installed? The uninstall program removes only items that the installation program installed.
  • Page 69: Windows Nt: Troubleshooting And Common Questions

    No Resources Assigned This error occurs if you have not assigned resources to the CAN interface. Refer to Chapter 2, Installation and Configuration, in your NI-CAN getting started manual for information on assigning memory and interrupt resources to the CAN interface.
  • Page 70 Missing CAN Interface If a National Instruments CAN interface is physically installed in your system, but is not listed in the NI-CAN Diagnostic utility, check to see if the NI-CAN Configuration utility has detected the hardware. For more information, refer to the...
  • Page 71 Start»Programs»National Instruments CAN. The NI-CAN Diagnostic utility displays information about the version of the NI-CAN software currently installed. What do I do if the NI-CAN Diagnostic utility fails with an error? Refer to the Troubleshooting Diagnostic Utility Failures...
  • Page 72 If you add anything to a directory that was created by the installation program, the uninstall program does not delete that directory, because the directory is not empty after the uninstallation. You will need to remove any remaining components yourself. NI-CAN User Manual ni.com...
  • Page 73: Technical Support Resources

    Technical Support Resources Web Support National Instruments Web support is your first stop for help in solving installation, configuration, and application problems and questions. Online problem-solving and diagnostic resources include frequently asked questions, knowledge bases, product-specific troubleshooting wizards, manuals, drivers, software updates, and more. Web support is available through the Technical Support section of ni.com...
  • Page 74 Appendix D Technical Support Resources Worldwide Support National Instruments has offices located around the world to help address your support needs. You can access our branch office Web sites from the . Branch office Web sites provide Worldwide Offices section of ni.com...
  • Page 75 Application A collection of functions used by a user application to access hardware. Programming Within NI-CAN, you use API functions to make calls into the NI-CAN Interface (API) driver. arbitration ID An 11- or 29-bit ID transmitted as the first field of a CAN frame. The arbitration ID determines the priority of the frame, and is normally used to identify the data transmitted in the frame.
  • Page 76 ID, an Identifier Extension, SOF and EOF bits, the RTR bit, a four-bit Data Length Code, and zero to eight bytes of data. CAN Network Within NI-CAN, an object that encapsulates a CAN network interface on Interface Object the host computer.
  • Page 77 Also known as packet. Hexadecimal. Hertz. instance An abstraction of a specific real-world thing; for example, Mike is an instance of the class Human. Also known as object. International Standards Organization. Kilobytes of memory. © National Instruments Corporation NI-CAN User Manual...
  • Page 78 Megabytes of memory. method An action performed on an instance to affect its behavior; the externally visible code of an object. Within NI-CAN, you use NI-CAN functions to execute methods for objects. Also known as service, operation, and action. minimum interval For a given connection, the minimum amount of time between subsequent attempts to transmit frames on the connection.
  • Page 79 Random-access memory. remote Within NI-CAN, anything that exists in another node of the device network (not on the same host as the NI-CAN driver). Remote Transmission This bit follows the arbitration ID in a frame, and indicates whether the...
  • Page 80 Glossary resource Hardware settings used by National Instruments CAN hardware, including an interrupt request level (IRQ) and an 8 KB physical memory range (such as D0000 to D1FFF hex). RTSI Real-Time System Integration Bus. The National Instruments timing bus that connects CAN and DAQ boards directly (via connectors on top of the PCI-CAN and AT-CAN series boards, and the PXI trigger bus on the PXI-846x series boards) for precise synchronization of functions.
  • Page 81 CAN identifiers, 1-2 CAN interfaces See also missing CAN interfaces. number of configurable interfaces C/C++ languages Windows 98/95, B-5 accessing NI-CAN software, 2-1 Windows NT, C-3 status checking, 2-12 CAN Network Interface Objects, 2-4 See also NI-CAN. © National Instruments Corporation...
  • Page 82 CAN Object dialog box, 5-7 software, 1-9 methods for, 2-8 DeviceNet protocol, 1-9 object configuration dialog box direct entry access to NI-CAN software, 2-2 (figure), 5-5 DLC (Data Length Code) field, 1-4 removing configurations, 5-6 documentation selecting CAN Object, 5-5...
  • Page 83 Windows 98/95, B-5 form error, 1-6 Windows NT, C-3 stuff error, 1-6 ISO 11898 standard, 1-1 error warning indicators (severity), 2-10 See also NI-CAN status format. LabVIEW G language function library, 2-1 firmware image files, 1-13 interactive front panel application example, 4-6...
  • Page 84 NI-CAN object hierarchy, 1-10 obj2obj.c source code, 4-1 applying NI-CAN objects (figure), 1-11 obj2obj.vi source code, 4-1 simple CAN device network application object hierarchy, in NI-CAN software, 1-10 (figure), 1-10 applying NI-CAN objects (figure), 1-11 NI-CAN software simple CAN device network application See also programming.
  • Page 85 ReadMultObj.vi example file, 4-1 CAN Objects, 2-5 related documentation, xii detecting state changes, 3-4 Remote Transmit Request (RTR) field, 1-4 interaction of NI-CAN software with your RTSI bus application (figure), 1-14 overview, 1-14 synchronizing with NI-DAQ, 1-15 © National Instruments Corporation...
  • Page 86 CAN, 1-1 memory resource conflict, C-1 Start of Frame (SOF) field, 1-3 missing CAN interface, C-2 state changes, detecting, 3-4 missing CAN interface in NI-CAN state transitions, queues, 3-1 Configuration utility, C-1 status of function calls, checking, 2-10 NI-CAN Diagnostic utility...
  • Page 87 CAN interface, B-2, B-4 memory resource conflict, C-1 NI-CAN Diagnostic utility failures, B-3 missing CAN interface, C-2 problem shown in device missing CAN interface in NI-CAN manager, B-2 Configuration utility, C-1 uninstalling NI-CAN Diagnostic utility failures, C-1 CAN hardware, A-1...

Table of Contents