LIN Interface Accesses Single Subscribing Slave Device

NI-CAN

LIN Interface Accesses Single Subscribing Slave Device

The following steps demonstrate how to use the Frame API functions in a LIN application in which the LIN interface is to provide simple access to a single slave device that subscribes to data. The steps are shown in the following flowchart.

Frame API – LIN interface provides simple access to a single slave device that subscribes to data

  1. Open a Network Interface Object.

    You must call the ncOpenObject function to open the Network Interface Object used in this example.

    The ncOpenObject function returns a handle for use in all subsequent Frame API calls for that object. When you are using the LabVIEW function library, this handle is passed through the upper left and right terminals of each Frame API function used after the open.

  2. Set attributes for the Network Interface Object.

    Prior to starting the Network Interface Object, you must configure it with its initial attribute settings. These are configured by calling the ncSetAttribute function with each desired attribute ID and value. This function takes the name of the object to configure, along with the attribute ID and value.

    For this example, the baud rate and checksum type should be configured to match those of the slave device. Self-reception is shown as enabled but itis optional. In this example the NI LIN interface slave task is publishing data in response to a master task header. When the slave task publishes data, the resulting full frame is logged into the read queue only if self-reception is enabled. Logging of bus errors is useful for troubleshooting, in the event the slave device does not behave as expected.

  3. Start Communication.

    You must start communication on the LIN bus before you can use the Network Interface Object to transfer data.

  4. Write to the master and slave tasks using the Network Interface Object

    Writing a full frame type containing the ID of the slave device to the LIN interface combines three tasks into a single step. First, the LIN interface slave task response queue is updated with the ID and data transferred in the full frame, and the response type is set to publish. Second, the LIN interface master task transmits a header containing the ID onto the bus.

    Finally, the LIN interface slave task publishes the data in response to the header (because its response queue has been updated to publish data in response to a header containing this ID). The net effect is that the LIN interface writes data to the slave device (the LIN interface slave task publishes data in response to the header ID while the slave device subscribes to data in response to the header ID). Write completion of the full frame type will set a write success flag in the interface. ncWaitForState should be used to wait for write success following the write.
  5. Read from the slave task using the Network Interface Object.

    If the slave device is working as expected, it will subscribe to data in response to the header transmitted in step 4. The NI LIN interface slave task will publish data in response and, if self-reception is enabled, combine the header and response data into a full frame type to be logged in the read queue. If the slave device is not working as expected (perhaps it publishes in response to the header, in which case there is a collision on the LIN), the resulting bus error frame will be placed into the read queue, since logging of bus errors has been enabled. Steps 4 and 5 should be repeated for each data set you want to write to the slave device.

  6. Stop communication.

    Stop communication on the LIN bus before closing the Network Interface Object.

  7. Close the Network Interface Object.

    When you are finished accessing the LIN bus, close the Network Interface Object using the ncCloseObject function before you exit the application.