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

SER ASync Tx

SER ASync Tx Sample Application (SSK 1.x)

Overview

The SER ASync Tx sample application demonstrates how to configure a serial channel for asynchronous communication and transmit data out the physical interface using the NAI Software Support Kit (SSK 1.x). Unlike the SER ASync Loopback sample — which routes data internally for self-test — this sample sends data through the external RS-232, RS-422, or RS-485 interface to a real receiver. It is the transmit-only counterpart to the loopback sample and pairs with the SER ASync Rx sample, which handles the receive side.

This sample supports the following SER module types: P8, PC, PD, Px, KB, SC, and newer SER variants. It also works with combination modules that include serial functionality, such as CMH. It serves as a practical API reference for implementing async serial transmission using SSK 1.x.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a SER module installed (P8, PC, PD, Px, KB, SC, or newer SER variant).

  • 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.

  • An external receiver connected to the serial channel’s physical interface (RS-232, RS-422, or RS-485). Because this sample transmits over the external interface rather than loopback, an external device or cable must be present to observe the output. To verify transmit and receive without external hardware, use the SER ASync Loopback sample instead.

How to Run

Launch the SER_ASync_Tx executable from your build output directory. On startup the application looks for a configuration file (default_SerASync_Tx.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, the application queries for a channel number and interface level, then enters a transmit loop that sends one byte per iteration until you quit.

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 SER.

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_SerASync_Tx.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() and verify it is non-zero before proceeding.

  5. Call Run_SER_ASync_Tx(cardIndex, module, moduleID) to configure the channel and begin transmitting.

#if defined (__VXWORKS__)
int32_t SER_ASync_Tx_Sample(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_SER_ASync_Tx(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;
}
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 SER module. Use the board menu to verify which slots are populated.

Program Structure

The entry point is main() on most platforms, or SER_ASync_Tx_Sample() on VxWorks.

The startup flow proceeds as follows:

  1. Load the saved configuration (or present the board menu) via naiapp_RunBoardMenu().

  2. Query the user for card index, module slot, and retrieve the module ID.

  3. Call Run_SER_ASync_Tx(cardIndex, module, moduleID) to query for a channel and interface level, then transmit.

  4. Prompt the user to quit or restart.

To run the transmit operation, call Run_SER_ASync_Tx(cardIndex, module, moduleID) with three parameters:

  • cardIndex — the logical card index for the board connection.

  • module — the one-based module slot number.

  • moduleID — the module ID returned by naibrd_GetModuleID(), used to determine hardware-specific behavior.

Note
Unlike the loopback sample, this sample does not read back data. It only transmits. To observe the transmitted data, connect an external receiver (or run the SER ASync Rx sample on another channel or board).

Interface Level Selection

Before configuring the channel, the sample queries the user for the physical interface level. This is the key difference from the SER ASync Loopback sample, which hardcodes NAI_SER_INTF_LOOPBACK. In this transmit sample, the user selects the actual electrical interface that matches the external cabling.

The serial_query_interface() helper presents four options:

printf("Please select an interface type [default=1]:\n");
printf("1 - Loop-back\n");
printf("2 - RS232\n");
printf("3 - RS422\n");
printf("4 - RS485\n");

The selection maps to the corresponding nai_ser_interface_t constant:

  • 1 — NAI_SER_INTF_LOOPBACK (internal loopback, no external connection required)

  • 2 — NAI_SER_INTF_RS232 (point-to-point, single-ended)

  • 3 — NAI_SER_INTF_RS422 (point-to-point or multi-drop, differential)

  • 4 — NAI_SER_INTF_RS485 (multi-drop, differential, half-duplex)

For real-world transmit testing, select option 2, 3, or 4 to match your physical connection. The loopback option is still available for quick verification without external hardware. If the user enters an invalid choice, the function defaults to loopback and prints an error message.

Important

Common Errors

  • Interface level mismatch — if the selected interface level does not match the external receiver’s electrical standard, data will not be received correctly. For example, selecting RS-232 when the cable is wired for RS-422 will produce garbled or no output.

  • RS-485 half-duplex considerations — RS-485 shares the same differential pair for transmit and receive. In a transmit-only scenario this is not an issue, but if you later add receive logic, you must manage the transmit/receive enable timing. Consult your module manual for RS-485 direction control.

Channel Reset and FIFO Setup

Before transmitting data, reset the channel and clear both FIFOs to ensure no stale data remains from a previous operation. Leftover bytes in either FIFO can corrupt a transmission, so this step should be the first thing you do after selecting a channel.

Channel Reset

Issue a channel reset to return the channel to its default state:

naibrd_SER_ChannelReset(cardIndex, module, chanNum);

This call resets all channel configuration registers to their defaults. You must reconfigure the channel after calling this function.

Clearing the FIFOs

After the reset, explicitly clear both FIFOs:

naibrd_SER_ClearRxFifo(cardIndex, module, chanNum);
naibrd_SER_ClearTxFifo(cardIndex, module, chanNum);

These API calls request the hardware to flush the respective FIFOs. The requests are asynchronous — the hardware sets control-register bits while the clear is in progress and drops them once the operation completes.

Timeout Polling Pattern

After requesting the clear, poll the channel control register until the FIFO-clear bits are deasserted. The sample uses a 1 ms polling interval with a 1-second (1000-iteration) timeout:

nCntlValueLo = NAI_SER_CTRLLO_CLEAR_RX_FIFO | NAI_SER_CTRLLO_CLEAR_TX_FIFO;
for (i = 0; i < CLEAR_FIFO_TIMEOUT && (nCntlValueLo & (NAI_SER_CTRLLO_CLEAR_RX_FIFO | NAI_SER_CTRLLO_CLEAR_TX_FIFO)); i++)
{
   nai_ser_chanctrl chanCtrlRaw;
   naibrd_SER_GetChannelControlRaw(cardIndex, module, chanNum, &chanCtrlRaw);
   nCntlValueLo = chanCtrlRaw & 0x0000FFFF;
   nai_msDelay(1);
}
if (i == CLEAR_FIFO_TIMEOUT)
{
   printf("Unable to clear FIFOs %d\n", chanNum);
   printf("Please press Enter to exit...");
   while ((ch = getchar()) != 0x0A);
   return;
}

The loop reads the raw channel control word with naibrd_SER_GetChannelControlRaw(), masks it to the lower 16 bits, and checks whether NAI_SER_CTRLLO_CLEAR_RX_FIFO or NAI_SER_CTRLLO_CLEAR_TX_FIFO is still asserted. Each iteration sleeps 1 ms (nai_msDelay(1)), and CLEAR_FIFO_TIMEOUT is defined as 1000, giving a total wait of up to 1 second. If both bits clear before the timeout expires, the loop exits early and the application continues to channel configuration.

In your own application, implement a similar check to confirm FIFOs are cleared before proceeding. Skipping this verification can lead to data being transmitted into a FIFO that is still mid-flush, producing undefined results.

Important

Common Errors

  • FIFO clear timeout — The FIFOs did not clear within 1 second. The channel may be in an unexpected state or the hardware may not be responding. Verify the module is operational and the channel is not locked by another process.

Channel Configuration

With the channel reset and FIFOs cleared, configure the serial channel for asynchronous transmission. The configuration in this sample is identical to the loopback sample except for the interface level, which is set to the user’s selection rather than hardcoded to loopback.

Configuration APIs

The following block sets the protocol, interface level, parity, data bits, stop bits, and baud rate for the selected channel:

check_status(naibrd_SER_SetProtocol(cardIndex, module, chanNum, NAI_SER_PROTOCOL_ASYNC));       /* Async mode */
check_status(naibrd_SER_SetInterfaceLevel(cardIndex, module, chanNum, interfaceLevel));         /* User-selected interface */
check_status(naibrd_SER_SetParity(cardIndex, module, chanNum, NAI_SER_PARITY_NONE));            /* No Parity */
check_status(naibrd_SER_SetDataBits(cardIndex, module, chanNum, 8));                            /* 8 Data Bits */
check_status(naibrd_SER_SetStopBits(cardIndex, module, chanNum, 1));                            /* 1 Stop Bits */
check_status(naibrd_SER_SetBaudrate(cardIndex, module, chanNum, 9600));                         /* 9600 baud */

Each call is explained below with the sample’s default value and the available alternatives:

  • naibrd_SER_SetProtocol() — sets the channel protocol to asynchronous mode (NAI_SER_PROTOCOL_ASYNC). Other options include HDLC and additional protocol modes defined by your module. Select the protocol that matches your data-link requirements.

  • naibrd_SER_SetInterfaceLevel() — sets the physical interface level. The sample passes the interfaceLevel variable, which holds the user’s selection from serial_query_interface(). For external communication, choose RS-232, RS-422, or RS-485 as appropriate for your cabling and hardware. Consult the module manual for the interface levels your module supports.

  • naibrd_SER_SetParity() — sets the parity mode. The sample uses NAI_SER_PARITY_NONE. Other options are odd and even parity. Both endpoints in a link must agree on the same parity setting, or every received frame will flag a parity error.

  • naibrd_SER_SetDataBits() — sets the number of data bits per character. The sample uses 8, which is the most common setting. 7-bit mode is also available for legacy protocols that use 7-bit ASCII.

  • naibrd_SER_SetStopBits() — sets the number of stop bits. The sample uses 1. Use 2 stop bits when the remote device requires extra inter-character spacing.

  • naibrd_SER_SetBaudrate() — sets the baud rate. The sample uses 9600. Consult the module manual for the full list of supported baud rates on your SER module variant.

Configuration Settle Delay

After writing the configuration registers, the sample inserts a 500 ms delay before transmitting:

nai_msDelay(500);

This pause gives the hardware time to apply the configuration changes — especially the interface level switch from default to the selected electrical standard. If you shorten or remove this delay, the first transmission may occur before the interface is fully initialized.

Note
The loopback sample uses a shorter delay sequence (20 ms for GEN 2/3 modules, 50 ms for receiver readiness). This sample uses a single 500 ms delay because it does not enable a receiver and the interface level change to an external standard may require additional settling time.
Important

Common Errors

  • Configuration not taking effect — if data is not appearing on the external interface after calling the configuration APIs, verify that the 500 ms delay has elapsed and that the interface level matches your physical connection.

  • Invalid baud rate — not all baud rates are supported by every SER module variant. If the channel does not communicate at the expected speed, consult the module manual for the list of valid rates.

  • NAI_ERROR_NOT_SUPPORTED — the protocol or interface level is not available for this module type. Check your module type and consult the module manual for supported protocols and interfaces.

Data Transmission

With the channel configured, the application enters a transmit loop that sends one byte per iteration, incrementing the data value each time. This section explains the transmit sequence so you can adapt it to your own data.

Building Test Data

The sample populates a single-word buffer with an incrementing byte value on each iteration of the transmit loop:

for (nNumWordsSend = 0; nNumWordsSend < NUM_DATA_TX; nNumWordsSend++)
{
    SendData[nNumWordsSend] = (uint8_t)(nNumWordsSend + data);  /* incremental data */
    printf("data[%i] = 0x%X\n", nNumWordsSend, SendData[nNumWordsSend]);
}

NUM_DATA_TX is defined as 1, so the sample transmits one word per iteration. The data variable starts at 0x00 and increments by 1 after each transmit cycle, producing a sequence of 0x00, 0x01, 0x02, and so on. In your own application, populate the buffer with whatever payload you need to send — the API does not impose any restrictions on the data content or buffer size (up to the FIFO depth).

Transmitting

To transmit data over a configured async serial channel, call naibrd_SER_TransmitBuffer() followed by naibrd_SER_TransmitInitiate():

naibrd_SER_TransmitBuffer(cardIndex, module, chanNum, sizeof(SendData[0]), SendData, nNumWordsSend, (uint32_t*)&nNumWordsSend);
naibrd_SER_TransmitInitiate(cardIndex, module, chanNum);

The two-step process works as follows:

  1. naibrd_SER_TransmitBuffer() loads data into the transmit FIFO. The parameters are:

    • cardIndex, module, chanNum — identify the target channel.

    • sizeof(SendData[0]) — the word size in bytes. Because SendData is declared as uint32_t[], this evaluates to 4.

    • SendData — pointer to the data buffer.

    • nNumWordsSend (input) — the number of words to load.

    • (uint32_t*)&nNumWordsSend (output) — on return, updated with the number of words actually accepted. Compare the output value against the input to confirm all data was accepted.

  2. naibrd_SER_TransmitInitiate() triggers the hardware to begin shifting data out of the FIFO onto the physical interface. Without this call, data remains in the FIFO but is not transmitted.

Note
The SER ASync Loopback sample does not call naibrd_SER_TransmitInitiate() — it relies on the loopback path to deliver data immediately. When transmitting over an external interface, you must call naibrd_SER_TransmitInitiate() to start the physical transmission.

Transmit Loop

The sample wraps the transmit sequence in a do…​while loop. After each transmission, the data variable increments so the next iteration sends the next byte value:

do
{
   /* ... build SendData, transmit, initiate ... */
   data += 1;
} while (TRUE != bQuit);

Because bQuit is initialized to FALSE and never set to TRUE in the current source, the loop runs indefinitely. In practice, you would add a quit prompt (the source contains commented-out code for this) or implement your own exit condition. In your own application, replace this loop with whatever transmission schedule your system requires — single-shot, periodic, or event-driven.

Important

Common Errors

  • No data on the external interface — verify that naibrd_SER_TransmitInitiate() is called after naibrd_SER_TransmitBuffer(). Without the initiate call, data sits in the FIFO and is never transmitted.

  • Transmit count mismatch — if the output word count from naibrd_SER_TransmitBuffer() is less than the input count, the FIFO may be full. Drain or wait before sending more data.

  • No receiver observing data — this sample is transmit-only. An external receiver must be connected and configured with matching serial parameters (baud rate, data bits, parity, stop bits) to observe the output. Use the SER ASync Rx sample on the receiving end, or connect a serial terminal.

Troubleshooting Reference

This table summarizes common errors and symptoms covered in the sections above. For detailed context on each entry, refer to the relevant section. Consult your module’s manual for hardware-specific diagnostic procedures.

Error / Symptom Possible Causes Suggested Resolution

No board found or connection timeout

Board not powered, incorrect or missing configuration file, network issue

Verify hardware is powered and connected. If default_SerASync_Tx.txt exists, check that it lists the correct interface and address. If it does not exist, the board menu will appear — configure and save your connection settings.

Module not detected at selected slot

No module installed at the specified slot, incorrect module number entered

Verify hardware configuration and module slot assignment

FIFO clear timeout

Channel in an unexpected state, hardware not responding

Verify the module is operational and the channel is not locked by another process

NAI_ERROR_NOT_SUPPORTED

Protocol or interface level not available for this module type

Check your module type. Consult your module’s manual for supported protocols and interfaces.

Configuration not taking effect

Insufficient settle time, interface level mismatch

Ensure the 500 ms delay has elapsed after configuration. Verify the selected interface level matches your physical connection.

No data on external interface

naibrd_SER_TransmitInitiate() not called, wrong interface level selected, cable not connected

Verify the two-step transmit sequence (buffer then initiate). Check interface level selection and physical cabling.

Receiver does not see expected data

Baud rate, parity, data bits, or stop bits mismatch between transmitter and receiver

Verify serial settings match on both endpoints. Use the same baud rate, data bits, parity, and stop bits.

Interface level mismatch

Selected RS-232 but cabled for RS-422 (or vice versa)

Confirm the interface level passed to naibrd_SER_SetInterfaceLevel() matches the physical wiring

Transmit count less than expected

FIFO full

Wait for the FIFO to drain before sending additional data, or reduce the transmit buffer size

Invalid baud rate

Module does not support the requested baud rate

Consult your module’s manual for supported baud rates

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail.

Full Source — SER_ASync_Tx.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_ser.h"
#include "advanced/nai_ether_adv.h"

static const int8_t *CONFIG_FILE = (const int8_t *)"default_SerASync_Tx.txt";

/* Function prototypes */
void Run_SER_ASync_Tx(int32_t cardIndex, int32_t module, uint32_t moduleID);
static void serial_query_interface(nai_ser_interface_t* interfaceLevel);

#define NUM_DATA_TX  1
#define MAX_TIMEOUT  10          /* 10ms timeout */
#define CLEAR_FIFO_TIMEOUT 1000  /* 1 second */

/**************************************************************************************************************/
/** \defgroup SERAsyncTx Serial Asynchronous Transmit
The purpose of the Serial Asynchronous Transmit sample application is to illustrate the methods to call in the
naibrd library to configure a given serial channel for transmitting RS422. The application will write data to the
selected serial channel's transmit buffer and transmit it
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SER_ASync_Tx_Sample(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_SER_ASync_Tx(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;
}

/**************************************************************************************************************/
/** \ingroup SERAsyncTx
Configures a serial module for asynchronous transmitting. The user is queried for the serial channel to transmit on.
\param cardIndex (Input) Logical Card Index assigned to connection with the NAI_BOARD (0 - NAI_MAX_CARDS-1).
\param module    (Input) Module Number of the module to access (1 - [max modules for board]).
\param moduleID  (Input) The ID of the module.
*/
/**************************************************************************************************************/
void Run_SER_ASync_Tx(int32_t cardIndex, int32_t module, uint32_t moduleID)
{

   int32_t chanNum, channelCount;
   int32_t nCntlValueLo;
   int32_t ch, i;
   uint32_t SendData[NUM_DATA_TX];
   bool_t bQuit = FALSE;
   uint32_t nNumWordsSend = 0;
   int data = 0x00;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   nai_ser_interface_t interfaceLevel = NAI_SER_INTF_LOOPBACK;

   channelCount = naibrd_SER_GetChannelCount(moduleID);
   check_status(naiapp_query_ChannelNumber(channelCount, 1, &chanNum));
   serial_query_interface(&interfaceLevel);

   naibrd_SER_ChannelReset(cardIndex, module, chanNum);
   naibrd_SER_ClearRxFifo(cardIndex, module, chanNum);
   naibrd_SER_ClearTxFifo(cardIndex, module, chanNum);
   nCntlValueLo = NAI_SER_CTRLLO_CLEAR_RX_FIFO | NAI_SER_CTRLLO_CLEAR_TX_FIFO;
   for (i = 0; i < CLEAR_FIFO_TIMEOUT && (nCntlValueLo & (NAI_SER_CTRLLO_CLEAR_RX_FIFO | NAI_SER_CTRLLO_CLEAR_TX_FIFO)); i++)
   {
      nai_ser_chanctrl chanCtrlRaw;
      naibrd_SER_GetChannelControlRaw(cardIndex, module, chanNum, &chanCtrlRaw);
      nCntlValueLo = chanCtrlRaw & 0x0000FFFF;
      nai_msDelay(1);
   }
   if (i == CLEAR_FIFO_TIMEOUT)
   {
      printf("Unable to clear FIFOs %d\n", chanNum);
      printf("Please press Enter to exit...");
      while ((ch = getchar()) != 0x0A);
      return;
   }

   printf("\nSerial Channel # %d\n", chanNum);

   /* Configure for ASync on the channel selected. */
   check_status(naibrd_SER_SetProtocol(cardIndex, module, chanNum, NAI_SER_PROTOCOL_ASYNC));       /* Async mode */
   check_status(naibrd_SER_SetInterfaceLevel(cardIndex, module, chanNum, interfaceLevel));         /* Loopback, RS232, RS422, or RS485 */
   check_status(naibrd_SER_SetParity(cardIndex, module, chanNum, NAI_SER_PARITY_NONE));            /* No Parity */
   check_status(naibrd_SER_SetDataBits(cardIndex, module, chanNum, 8));                            /* 8 Data Bits */
   check_status(naibrd_SER_SetStopBits(cardIndex, module, chanNum, 1));                            /* 1 Stop Bits */
   check_status(naibrd_SER_SetBaudrate(cardIndex, module, chanNum, 9600));                         /* 9600 baud */

   /* Add a delay here for the configuration to be ready */
   nai_msDelay(500);

   do
   {
      for (nNumWordsSend = 0; nNumWordsSend < NUM_DATA_TX; nNumWordsSend++)
      {
          SendData[nNumWordsSend] = (uint8_t)(nNumWordsSend + data);  /* incremental data */
          printf("data[%i] = 0x%X\n", nNumWordsSend, SendData[nNumWordsSend]);
      }

      /* Add a delay here for the configuration to be ready */
      nai_msDelay(500);
      naibrd_SER_TransmitBuffer(cardIndex, module, chanNum, sizeof(SendData[0]), SendData, nNumWordsSend, (uint32_t*)&nNumWordsSend); /* load FIFO */
      naibrd_SER_TransmitInitiate(cardIndex, module, chanNum);   /* Initiate Transmit */

      data += 1;
   } while (TRUE != bQuit);

   return;
}

/**************************************************************************************************************/
/** \ingroup SERAsyncTx
Queries the user for the interface type.
\param interfaceLevel (Output) The selected interface level.
*/
/**************************************************************************************************************/
static void serial_query_interface(nai_ser_interface_t* interfaceLevel)
{
   int8_t inputBuffer[80];
   int32_t choice;

   printf("Please select an interface type [default=1]:\n");
   printf("1 - Loop-back\n");
   printf("2 - RS232\n");
   printf("3 - RS422\n");
   printf("4 - RS485\n");
   printf("Enter choice: ");
   fgets((char*)inputBuffer, sizeof(inputBuffer), stdin);
   choice = atoi((char*)inputBuffer);

   switch (choice)
   {
   case 1:
      *interfaceLevel = NAI_SER_INTF_LOOPBACK;
      break;
   case 2:
      *interfaceLevel = NAI_SER_INTF_RS232;
      break;
   case 3:
      *interfaceLevel = NAI_SER_INTF_RS422;
      break;
   case 4:
      *interfaceLevel = NAI_SER_INTF_RS485;
      break;
   default:
      printf("ERROR: Invalid choice. Defaulting to Loop-back.\n");
      *interfaceLevel = NAI_SER_INTF_LOOPBACK;
      break;
   }

   return;
}

Help Bot

X