Example Code

NI-XNET dotNET API for CAN

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Programming Language

  • .NET

Code and Documents

Attachment

Description

This example is a wrapper around the National Instruments NI-XNET C driver using PInvoke.

List of functions

The following functions have been wrapped in niXNET.cs (see the NI-XNET Hardware and Software Manual for more information about the different functions):

  • nx_Clear
  • nxCreateSession which is used as constructor for the session object
  • nx_Flush
  • nx_GetProperty for the following properties
    • niXNET.xNETConstants.nxPropSession_InfBaudRate
    • niXNET.xNETConstants.nxPropSession_DatabaseName
  • nx_ReadFrame
  • nx_ReadSignalSinglePoint
  • nx_ReadState
    • niXNET.xNETConstants.nxState_CANComm
  • nx_SetProperty for the following properties
    • niXNET.xNETConstants.nxPropSession_IntfBaudRate
  • nx_Start
  • nx_StatusToString
  • nx_WriteFrame
  • nx_WriteSignalSinglePoint
  • nx_WriteWaveform
  • nx_WriteSignalXY

 

The examples provided only cover CAN, excluding J1939.

Examples

  • CAN Frame Single Point Input
    • niXNET (nxCreateSession)
    • nx_Start
    • nx_ReadFrame
    • nx_Clear
  • CAN Frame Single Point Ouput
    • niXNET (nxCreateSession)
    • nx_WriteFrame
    • nx_Clear
  • CAN Frame Stream Input
    • niXNET (nxCreateSession)
    • nx_SetProperty
      • niXNET.xNETConstants.nxPropSession_IntfBaudRate
    • nx_GetProperty
      • niXNET.xNETConstants.nxPropSession_InfBaudRate
      • niXNET.xNETConstants.nxPropSession_DatabaseName
    • nx_ReadState
      • niXNET.xNETConstants.nxState_CANComm
    • nx_ReadFrame
    • nx_Clear
  • CAN Frame Stream Output
    • niXNET (nxCreateSession)
    • nx_SetProperty
      • niXNET.xNETConstants.nxPropSession_IntfBaudRate
    • nx_WriteFrame
    • nx_Clear
  • CAN Input Output Same Port
    • niXNET (nxCreateSession)
    • nx_WriteSignalSinglePoint
    • nx_ReadSignalSinglePoint
    • nx_Clear
  • CAN Loopback
    • niXNET (nxCreateSession)
    • nx_WriteSignalSinglePoint
    • nx_ReadSignalSinglePoint
    • nx_Clear
  • CAN Signal Single Point Input
    • niXNET (nxCreateSession)
    • nx_ReadSignalSinglePoint
    • nx_Clear
  • CAN Signal Single Point Output
    • niXNET (nxCreateSession)
    • nx_WriteSignalSinglePoint
    • nx_Clear
  • CAN Signal Waveform Output
    • niXNET (nxCreateSession)
    • nx_WriteSignalWaveform
    • nx_Clear
  • CAN Signal XY Output
    • niXNET (nxCreateSession)
    • nx_WriteSignalXY
    • nx_Clear

 

How to Use

Requirements

To be able to use the wrapper, you should install :

  • NI-XNET 14.0
  • Microsoft Visual Studio 2010

Additional Information

This code was created for NI-XNET 14.0 and is not owned by NI R&D.

NI currently does not support .NET for the NI XNET driver officially.

For more information, please refer to .NET Wrappers for NI XNET.

 

The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: https://ni.com/samplecodelicense.

Senior Technical Support Engineer | CLD CTA | NI


DISCLAIMER: The attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system, or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.