LIN Interface as Bus Monitor
The following steps demonstrate how to use the Frame API functions with a LIN application in which the LIN interface is acting as a bus monitor. The steps are shown in the following flowchart.
Frame API with LIN Interface as Bus Monitor
- 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.
- Set attribute(s) 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 LIN. Logging of bus errors is useful for troubleshooting, in the event any of the devices attached to the LIN do not behave as expected.
- Start communication.
You must start communication on the LIN bus before you can use the Network Interface Object to transfer data.
- Read from the slave task using the Network Interface Object.
By default, the NI LIN interface will subscribe to data in response to all headers received from the bus. Upon successful reception of response data and checksum for a header, the slave task will combine the header and response data into a single full frame and load it into the read queue. If log bus errors is enabled, then the first bus error that occurs within the header or response portion of each LIN frame will be placed into a bus error frame and loaded into the read queue. The LIN interface slave task will ignore the remainder of the frame transaction on the bus and prepare for the reception of the next header. The loading of the full or bus error frame into the read queue will set a read available flag in the interface. ncWaitForState should be used to wait for read available before executing the ncRead or ncReadMult function. Step 4 should be repeated for monitoring situations, as the read queue is being continuously filled with LIN frame data resulting from bus transactions initiated by an external master.
- Stop communication.
Stop communication on the LIN bus before closing the Network Interface Object.
- 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.