Channel API Additional Programming Topics

NI-CAN

Channel API Additional Programming Topics

The following sections provide information you can use to extend the basic programming model.

Get Names

If you are developing an application that another person will use, you may not want to specify a fixed channel list in the application. Ideally, you want the end-user to select the channels of interest from user interface controls, such as list boxes.

The Get Names function queries MAX or a CAN database and returns a list of all channels in that database. You can use this list to populate user-interface controls. The end-user can then select channels from these controls, avoiding the need to type each name using the keyboard. Once the user makes his selections, the application can pass the resulting list to Init Start.

The Get Names function is CAN Get Names in LabVIEW and nctGetNames in other languages.

Synchronization

The NI-CAN Channel API uses RTSI to synchronize specific functional units on each card. For CAN cards, the functional unit is the interface (port). For DAQ cards, the functional unit is a specific measurement such as Analog Input or Analog Output. Each function routes two signals over the RTSI connection:

  • timebase—This is a common clock shared by both cards. The shared timebase ensures that sampling does not drift. The timebase applies to all functional units on the card.
  • start trigger—This signal is sent from one functional unit to the other functional unit when sampling starts. The shared start trigger ensures that both units start simultaneously.

Set Property

The Init Start function uses interface and channel configuration as specified in MAX or the CAN database file. If you need to change this configuration within the application, you cannot use Init Start, because most properties cannot be changed while the task is running.

For example, to set the baud rate for the interface within the application, use the following calling sequence:

  • Initialize the task as stopped. The Initialize function is CAN Initialize in LabVIEW and nctInitialize in other languages.
  • Use Set Property to specify the new value for the baud rate property. The Set Property function is CAN Set Property in LabVIEW and nctSetProperty in other languages.
  • Start the task with the Start function. The Start function is CAN Start in LabVIEW and nctStart in other languages.

After the task is started, you may need to change properties again. To change properties within the application, use the Stop function to stop the task, Set Property to change properties, and then Start the task again.

You also can use the Get Property function to get the value of any property. The Get Property function returns values whether the task is running or not.