Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

TTL Output

TTL Output Sample Application (SSK 1.x)

Overview

The TTL Output sample application demonstrates how to control TTL (Transistor-Transistor Logic) output channels using the NAI Software Support Kit (SSK 1.x). It covers the fundamental TTL output operations you will need in your own application: configuring a channel for output mode, setting the output state to logic high or low, and toggling the output between states.

TTL is a family of digital logic where signal levels are defined by fixed voltage thresholds. A logic low (0) is typically 0 to 0.8 V, and a logic high (1) is typically 2.0 to 5.0 V. NAI TTL modules drive these standard voltage levels on their output pins, making them suitable for controlling digital inputs on external equipment, driving indicator LEDs, triggering external logic, or providing simple on/off control signals. The module’s output drivers source or sink current at TTL-compatible levels, so external devices expecting standard TTL signals can connect directly without level translation.

This sample supports the following TTL module types: D7 (Gen5), and TL1 through TL8 (Gen3). The D7 uses a different API call to set the I/O direction (naibrd_TTL_SetIOFormat()) compared to the TL-series modules (naibrd_TTL_SetOpMode()), and the sample handles both variants. It serves as a practical API reference — each menu command maps directly to one or more naibrd_TTL_*() API calls that you can lift into your own code.

For the full set of TTL configuration operations (mode configuration, all status flags, enhanced modes), see the TTL BasicOps sample application guide.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a TTL module installed (D7, or TL1 through TL8).

  • SSK 1.x installed on your development host.

  • The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.

How to Run

Launch the TTL_Output executable from your build output directory. On startup the application looks for a configuration file (default_TTL_Output.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, select a channel and the command menu lets you set the output high, low, or toggle.

Board Connection and Module Selection

Note
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to TTL. For details on board connection configuration, see the First Time Setup Guide.

The main() function follows a standard SSK 1.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_TTL_Output.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear.

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Retrieve the module ID with naibrd_GetModuleID() so downstream code can adapt to the specific TTL variant installed.

#if defined (__VXWORKS__)
int32_t TTL_Output(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_TTL_Output(cardIndex, module, moduleID);
               }
            }
         }

         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR,
                  inputBuffer, &inputResponseCnt);
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}
Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — indices are zero-based for cards and one-based for modules. Ensure the values you pass match your hardware setup.

  • Module not present at selected slot — the slot you selected does not contain a TTL module. Use the board menu to verify which slots are populated.

Program Structure

Entry Point

On standard platforms the entry point is main(). On VxWorks the entry point is TTL_Output() — the SSK 1.x build system selects the correct variant via a preprocessor guard:

#if defined (__VXWORKS__)
int32_t TTL_Output(void)
#else
int32_t main(void)
#endif

The startup flow is the same in both cases:

  1. Attempt to load the saved configuration file via naiapp_RunBoardMenu(CONFIG_FILE). If the file does not yet exist, the interactive board menu is presented instead.

  2. Enter a loop that queries for card index and module slot.

  3. Call Run_TTL_Output() to validate the module and enter the interactive command loop.

  4. On exit, close all open board connections with naiapp_access_CloseAllOpenCards().

Module Validation

Run_TTL_Output() validates the selected module by calling naibrd_TTL_GetChannelCount(). If the module is not a recognized TTL type, the channel count returns zero and the function prints an error. In your own application, use this same check to confirm the target slot contains a TTL module before issuing TTL API calls:

MaxChannel = naibrd_TTL_GetChannelCount(ModuleID);

if (MaxChannel == 0)
{
   printf(" *** Module selection not recognized as TTL module. ***\n\n");
}
else
{
   Run_TTL_Output_Start(cardIndex, module, ModuleID, MaxChannel);
}

Application Parameters

The Run_TTL_Output_Start() function populates an naiapp_AppParameters_t struct that is passed to every command handler. Your application will need to track these same values to identify which board, module, and channel you are targeting:

naiapp_AppParameters_t  ttl_params;
p_naiapp_AppParameters_t ttl_output_params = &ttl_params;
ttl_output_params->cardIndex = cardIndex;
ttl_output_params->module = module;
  • cardIndex — identifies which board in a multi-board system.

  • module — the slot number where the TTL module is installed.

  • channel — the currently selected channel (set after the channel selection query).

Command Loop

Run_TTL_Output_Start() drives the interactive command loop. On each iteration it displays the command menu, prints the current channel status (mode and output state), and dispatches the user’s selection to the matching handler function.

The available commands are registered in the TTL_Output_MainMenuCmds[] table:

Command Description

High

Set the output to logic 1 (high)

Low

Set the output to logic 0 (low)

Toggle

Toggle the output between high and low

The menu-driven structure is a convenience of the sample application. In your own application, you would call the same underlying naibrd_TTL_*() API functions directly — for example, calling naibrd_TTL_SetOutputState() instead of navigating to the "High" or "Low" menu commands.

Channel Setup and Output Mode Configuration

Before you can drive a TTL output, the channel must be configured for output mode. The sample’s Cfg_TTL_Setup() function handles this, and the setup differs between module generations.

VCC Source Configuration

TTL modules can be powered from an internal or external VCC source. The sample configures bank 1 to use the internal VCC supply so the output drivers have a voltage source without requiring an external power connection:

check_status(naibrd_TTL_SetBankVCCSource(cardIndex, module, 1,
             (nai_ttl_vcc_t)NAI_TTL_VCC_INTERNAL));
  • cardIndex — identifies the board.

  • module — the slot containing the TTL module.

  • 1 — the bank number (bank 1 in this sample).

  • NAI_TTL_VCC_INTERNAL — selects the on-board internal power supply as the VCC source.

If your application requires a specific external VCC voltage, you would pass NAI_TTL_VCC_EXTERNAL instead and provide the external supply on the module’s VCC input pin. The sample calls this twice (before and after channel setup) to ensure the internal supply is active.

Reset and Mode Configuration

The Cfg_TTL_Setup() function first resets the channel timer, then configures the channel direction based on the module type:

static int32_t Cfg_TTL_Setup(int32_t cardIndex, int32_t module, int32_t modid,
                              int32_t channel)
{
   int32_t status;

   status = (int32_t)check_status(naibrd_TTL_Reset(cardIndex, module, channel,
                                   NAI_TTL_RESET_TIMER_ONLY));

   switch (modid)
   {
   case NAI_MODULE_ID_TL1:
   case NAI_MODULE_ID_TL2:
      status |= (int32_t)check_status(naibrd_TTL_SetOpMode(cardIndex, module,
                          channel, NAI_TTL_MODE_STD_INPUT_OUTPUT));
      break;
   case NAI_MODULE_ID_D7:
      status |= (int32_t)check_status(naibrd_TTL_SetIOFormat(cardIndex, module,
                          channel, NAI_TTL_GEN5_IOFORMAT_OUTPUT));
   }

   return status;
}

The key difference between module generations:

  • TL1, TL2 (Gen3) — use naibrd_TTL_SetOpMode() with NAI_TTL_MODE_STD_INPUT_OUTPUT to place the channel in standard I/O mode, where the output state register controls the pin level.

  • D7 (Gen5) — use naibrd_TTL_SetIOFormat() with NAI_TTL_GEN5_IOFORMAT_OUTPUT to explicitly set the channel as an output. Gen5 modules separate I/O direction from operating mode.

The naibrd_TTL_Reset() call with NAI_TTL_RESET_TIMER_ONLY resets any timer or counter state on the channel without changing the output level. This ensures a clean starting state for output operations.

In your own application, call the appropriate setup function for your module type before writing output states. If you are unsure which module is installed, use the module ID returned by naibrd_GetModuleID() to select the correct API call, as the sample does.

Important

Common Errors

  • Output does not change after SetOutputState() — the channel may not be configured for output mode. Ensure you have called naibrd_TTL_SetOpMode() (TL-series) or naibrd_TTL_SetIOFormat() (D7) before writing output states.

  • NAI_ERROR_NOT_SUPPORTED — the mode or I/O format you requested is not supported by the installed module. Check that you are using the correct API call for your module generation.

  • No voltage on output pin — the VCC source may not be configured. Ensure naibrd_TTL_SetBankVCCSource() has been called with either NAI_TTL_VCC_INTERNAL or NAI_TTL_VCC_EXTERNAL (with external supply connected).

Output State Control

The core purpose of this sample is to demonstrate the three basic output operations: set high, set low, and toggle. All three use naibrd_TTL_SetOutputState() with different state values.

Set Output High

To drive a TTL channel to logic 1 (high) in your own application, call naibrd_TTL_SetOutputState() with NAI_TTL_STATE_HI:

status = check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel,
                       NAI_TTL_STATE_HI));
  • cardIndex — identifies the board.

  • module — the slot containing the TTL module.

  • channel — the channel to drive.

  • NAI_TTL_STATE_HI — sets the output to logic high (typically 2.0 to 5.0 V depending on the VCC source).

The function returns NAI_SUCCESS on success. Any other return value indicates an error — check the status code to determine whether the channel is properly configured for output.

Set Output Low

To drive a TTL channel to logic 0 (low), call naibrd_TTL_SetOutputState() with NAI_TTL_STATE_LO:

status = check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel,
                       NAI_TTL_STATE_LO));
  • NAI_TTL_STATE_LO — sets the output to logic low (typically 0 to 0.8 V).

Toggle Output

To toggle a TTL channel between its current state and the opposite state, first read the current output state with naibrd_TTL_GetOutputState(), then write the opposite value:

nai_ttl_state_t state;
status = check_status(naibrd_TTL_GetOutputState(cardIndex, module, channel, &state));

if (NAI_TTL_STATE_HI == state)
   status |= check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel,
                            NAI_TTL_STATE_LO));
else
   status |= check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel,
                            NAI_TTL_STATE_HI));

This read-modify-write pattern is the standard way to toggle a TTL output. Note that there is no atomic toggle API call — your application reads the current state and writes the inverse. If multiple threads or processes control the same channel, you will need to serialize access to avoid race conditions between the read and the write.

Important

Common Errors

  • Output stuck at one level — the channel may still be in input mode. Verify that the output mode setup (see Channel Setup section) was called before attempting to set the output state.

  • Toggle does not change the output — if naibrd_TTL_GetOutputState() fails, the state variable may contain a stale value, causing the write to set the same level. Always check the return status of the read call.

  • Output voltage lower than expected — if using external VCC and the supply voltage is low, the output high level will be reduced accordingly. Check the VCC source configuration and external supply voltage.

Channel Status Display

The sample’s Print_TTL_Channel_Header() function reads and displays the current operating mode and output state for a channel. This is useful for confirming that your configuration took effect.

Read Operating Mode and Output State

To read the current mode and output state of a TTL channel, use naibrd_TTL_GetOpMode() and naibrd_TTL_GetOutputState():

nai_ttl_state_t state;
nai_ttl_enhanced_mode_t mode;

status = check_status(naibrd_TTL_GetOpMode(cardIndex, module, channel, &mode));
status |= check_status(naibrd_TTL_GetOutputState(cardIndex, module, channel, &state));
  • mode — returns the current operating mode as a numeric value. The exact meaning depends on the module type; consult your module’s manual for the mode definitions.

  • state — returns NAI_TTL_STATE_LO or NAI_TTL_STATE_HI.

The sample displays 'L' for low and 'H' for high in its status output. In your own application, you can use these read-back calls to verify that a previous write took effect or to monitor the channel state in a status display.

Important

Common Errors

  • Mode reads as 0 but output works — some module types report the mode differently depending on whether you configured with SetOpMode() or SetIOFormat(). The mode read-back is informational; the output behavior is what matters.

  • State reads as low immediately after setting high — if an external device is pulling the line low, the read-back may reflect the actual pin level rather than the commanded state. Check external wiring and loads.

Troubleshooting Reference

The following table summarizes common errors and symptoms you may encounter when working with TTL output control. This consolidates the error information from the preceding sections. Consult your module’s manual for hardware-specific diagnostics and specifications.

Error / Symptom Possible Causes Suggested Resolution

Output does not change after SetOutputState()

Channel not configured for output mode.

Call naibrd_TTL_SetOpMode() (TL-series) or naibrd_TTL_SetIOFormat() (D7) to configure the channel as an output before writing states.

No voltage on output pin

VCC source not configured; external supply not connected.

Call naibrd_TTL_SetBankVCCSource() with NAI_TTL_VCC_INTERNAL or ensure external VCC is connected if using NAI_TTL_VCC_EXTERNAL.

NAI_ERROR_NOT_SUPPORTED on mode or format call

Wrong API call for the installed module generation.

Use naibrd_TTL_SetOpMode() for TL1/TL2 and naibrd_TTL_SetIOFormat() for D7. Check the module ID to select the correct call.

Output voltage lower than expected

External VCC supply voltage is low; internal VCC not selected.

Verify VCC source configuration and measure the external supply voltage if applicable.

Toggle does not change output

Read of current state failed, causing write of same level.

Check the return status of naibrd_TTL_GetOutputState() before using the returned state value.

State reads low immediately after setting high

External device pulling the line low.

Check external wiring. The pin may be overloaded or shorted to ground.

Module selection not recognized as TTL module

The selected slot does not contain a TTL module (D7, or TL1 through TL8).

Use the board menu to verify which modules are installed and select the correct slot.

Mode reads as 0 but output works correctly

Module reports mode differently based on which API set the direction.

This is expected behavior on some modules. The output state is the reliable indicator.

Full Source

Full Source — TTL_Output.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ttl.h"
#include "advanced/nai_ether_adv.h"

static const int8_t *CONFIG_FILE = (const int8_t *)"default_TTL_Output.txt";
static const int32_t DEF_TTL_FIRST_CHAN = 1;

/* Function Prototypes */
void Run_TTL_Output(int32_t cardIndex, int32_t module, int32_t ModuleID);
void Run_TTL_Output_Start(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Print_TTL_Channel_Header(int32_t cardIndex, int32_t module, int32_t channelCount);

nai_status_t Set_TTL_High(int32_t paramCount, int32_t* p_params);
nai_status_t Set_TTL_Low(int32_t paramCount, int32_t* p_params);
nai_status_t Set_TTL_Toggle(int32_t paramCount, int32_t* p_params);
static int32_t Cfg_TTL_Setup(int32_t cardIndex, int32_t module, int32_t modid, int32_t channel);

enum ttl_SynchronousPreload_commands
{
   TTL_OUTPUT_CMD_HIGH,
   TTL_OUTPUT_CMD_LOW,
   TTL_OUTPUT_CMD_TOGGLE,
   TTL_OUTPUT_CMD_LAST
};

naiapp_cmdtbl_params_t TTL_Output_MainMenuCmds[] =
{
   {"High",       "Output a logic 1 (high)",                 TTL_OUTPUT_CMD_HIGH,   Set_TTL_High   },
   {"Low",        "Output a logic 0 (low)",                  TTL_OUTPUT_CMD_LOW,    Set_TTL_Low    },
   {"Toggle",     "Toggle the output state",                 TTL_OUTPUT_CMD_TOGGLE, Set_TTL_Toggle }
};

/**************************************************************************************************************/
/**
<summary>
main obtains and/or loads device configuration.
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t TTL_Output(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_TTL_Output(cardIndex, module, moduleID);
               }
            }
         }

         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   printf("\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}

/**************************************************************************************************************/
/**
<summary>
Run_TTL_Output prompts the user for the card, module and channel to use for the application and calls
Run_TTL_Output_Start if the card, module, channel is valid for as a TLL module.
</summary>
*/
/**************************************************************************************************************/
void Run_TTL_Output(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
   int32_t MaxChannel;

   MaxChannel = naibrd_TTL_GetChannelCount(ModuleID);

   if (MaxChannel == 0)
   {
      printf(" *** Module selection not recognized as TTL module. ***\n\n");
   }
   else
   {
      Run_TTL_Output_Start(cardIndex, module, ModuleID, MaxChannel);
   }
}

/**************************************************************************************************************/
/**
<summary>
Run_TTL_Output_Start runs the inner menu which allows the user to select a channel and an output state.
</summary>
*/
/**************************************************************************************************************/
void Run_TTL_Output_Start(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
   bool_t  bQuit = FALSE;
   bool_t  bContinue = TRUE;
   bool_t  bCmdFound = FALSE;

   int32_t chan = 0;
   int32_t defaultchan = 1;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  ttl_params;
   p_naiapp_AppParameters_t ttl_output_params = &ttl_params;
   ttl_output_params->cardIndex = cardIndex;
   ttl_output_params->module = module;

   while (bContinue)
   {
      printf("    \r\n\r\n");
      printf("Channel selection \r\n");
      printf("================= \r\n");

      defaultchan = DEF_TTL_FIRST_CHAN;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &ttl_output_params->channel);
      check_status(naibrd_TTL_SetBankVCCSource(cardIndex, module, 1, (nai_ttl_vcc_t)NAI_TTL_VCC_INTERNAL));

      /* Configure the channel for first use */
      Cfg_TTL_Setup(cardIndex, module, ModuleID, chan);

      /* Load commands from the state table and get a response*/
      naiapp_utils_LoadParamMenuCommands(TTL_OUTPUT_CMD_LAST, TTL_Output_MainMenuCmds);

      /* Ensure that we're using the internal power supply */
      check_status(naibrd_TTL_SetBankVCCSource(cardIndex, module, 1, (nai_ttl_vcc_t)NAI_TTL_VCC_INTERNAL));

      while (bContinue)
      {
         /* Display_TTL_SynchronousPreload_Channel(cardIndex, module, chan, ModuleID); */
         naiapp_display_ParamMenuCommands((int8_t *)"TTL Synchronous Preload Operation Menu");

         /* Print the state of the channel */
         Print_TTL_Channel_Header(cardIndex, module, chan);

         printf("\nType TTL command or %c to quit : ", NAI_QUIT_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                  case TTL_OUTPUT_CMD_HIGH:
                  case TTL_OUTPUT_CMD_LOW:
                  case TTL_OUTPUT_CMD_TOGGLE:
                     if (NULL != TTL_Output_MainMenuCmds[cmd].func) /* Ensure that the function pointer is valid */
                     {
                        TTL_Output_MainMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttl_output_params);
                        Print_TTL_Channel_Header(cardIndex, module, chan);
                     }
                     else
                        printf("No function is associated with the command %s.\r\n", TTL_Output_MainMenuCmds[cmd].cmdstr);

                     break;
                  default:
                     printf("Invalid command entered\n");
                     break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
}

/**************************************************************************************************************/
/**
<summary>
Print_TTL_Channel_Header Formats and prints a header which indicates the channel number, mode, and output status.
</summary>
*/
/**************************************************************************************************************/
static void Print_TTL_Channel_Header(int32_t cardIndex, int32_t module, int32_t channel)
{
   uint32_t status;

   nai_ttl_state_t state;
   nai_ttl_enhanced_mode_t mode;

   printf("    \r\n\r\n");
   printf("=======================\r\n");
   printf("    Channel Status     \r\n");
   printf("=======================\r\n");
   printf("  Ch    Mode    State  \r\n");
   printf("-----------------------\r\n");

   status = check_status(naibrd_TTL_GetOpMode(cardIndex, module, channel, &mode));
   status |= check_status(naibrd_TTL_GetOutputState(cardIndex, module, channel, &state));
   printf(" %2d     %3d       %c   \r\n", channel, (uint32_t)mode, (state == NAI_TTL_STATE_LO) ? 'L' : 'H');
}

/*============================================================================================================= */
/* Sample Code Starts Here                                                                                      */
/*============================================================================================================= */

/**************************************************************************************************************/
/**
<summary>
Cfg_TTL_Setup resets and configures the specified channel to NAI_TTL_MODE_OUTPUT mode.
</summary>
*/
/**************************************************************************************************************/
static int32_t Cfg_TTL_Setup(int32_t cardIndex, int32_t module, int32_t modid, int32_t channel)
{
   int32_t status;

   status = (int32_t)check_status(naibrd_TTL_Reset(cardIndex, module, channel, NAI_TTL_RESET_TIMER_ONLY));

   switch (modid)
   {
   case NAI_MODULE_ID_TL1:
   case NAI_MODULE_ID_TL2:
      status |= (int32_t)check_status(naibrd_TTL_SetOpMode(cardIndex, module, channel, NAI_TTL_MODE_STD_INPUT_OUTPUT));
      break;
   case NAI_MODULE_ID_D7:
      status |= (int32_t)check_status(naibrd_TTL_SetIOFormat(cardIndex, module, channel, NAI_TTL_GEN5_IOFORMAT_OUTPUT));
   }

   return status;
}

/**************************************************************************************************************/
/**
<summary>
Set_TTL_High will set the output state of the specified channel to logic 1 (High).
</summary>
*/
/**************************************************************************************************************/
nai_status_t Set_TTL_High(int32_t paramCount, int32_t* p_params)
{
   int32_t status;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t channel = p_ttl_params->channel;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   status = check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel, NAI_TTL_STATE_HI));
   if (status == NAI_SUCCESS)
      return NAI_SUCCESS;
   else
      return NAI_ERROR_UNKNOWN;
}

/**************************************************************************************************************/
/**
<summary>
Set_TTL_Low will set the output state of the specified channel to logic 0 (Low).
</summary>
*/
/**************************************************************************************************************/
nai_status_t Set_TTL_Low(int32_t paramCount, int32_t* p_params)
{
   int32_t status;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t channel = p_ttl_params->channel;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   status = check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel, NAI_TTL_STATE_LO));
   if (status == NAI_SUCCESS)
      return NAI_SUCCESS;
   else
      return NAI_ERROR_UNKNOWN;
}

/**************************************************************************************************************/
/**
<summary>
Set_TTL_Toggle will check the output state of the specified channel and will toggle it accordingly
(i.e. High -> Low, Low -> High).
</summary>
*/
/**************************************************************************************************************/
nai_status_t Set_TTL_Toggle(int32_t paramCount, int32_t* p_params)
{
   int32_t status;
   nai_ttl_state_t state;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t channel = p_ttl_params->channel;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   status = check_status(naibrd_TTL_GetOutputState(cardIndex, module, channel, &state));

   if (NAI_TTL_STATE_HI == state)
      status |= check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel, NAI_TTL_STATE_LO));
   else
      status |= check_status(naibrd_TTL_SetOutputState(cardIndex, module, channel, NAI_TTL_STATE_HI));
   if (status == NAI_SUCCESS)
      return NAI_SUCCESS;
   else
      return NAI_ERROR_UNKNOWN;
}

Help Bot

X