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 HDLC Tx

SER HDLC Tx Sample Application (SSK 1.x)

Overview

The SER HDLC Tx sample application demonstrates how to configure a serial channel for synchronous HDLC communication and transmit data out the physical interface using the NAI Software Support Kit (SSK 1.x). Unlike the SER HDLC Loopback sample — which routes data internally for self-test — this sample sends HDLC frames 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 HDLC Rx sample, which handles the receive side.

HDLC is a frame-oriented synchronous protocol. The hardware automatically wraps your payload with sync characters and a CRC — your application provides only the raw data bytes and the hardware handles all framing details. For background on how HDLC framing works at the hardware level, see the SER HDLC Loopback guide’s "Hardware-Managed HDLC Framing" section.

This sample supports the following SER module types: P8, PC, PD, Px, KB, SC5, 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 synchronous HDLC 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, SC5, 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-422 is the default in this sample). Because this sample transmits over the external interface rather than loopback, an external device or cable must be present to observe the output. To pair with a receiver, run the SER HDLC Rx sample on the receiving end. To verify transmit and receive without external hardware, use the SER HDLC Loopback sample instead.

How to Run

Launch the SER_HDLC_Tx executable from your build output directory. On startup the application looks for a configuration file (default_SerHDLC_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, configures the channel for HDLC transmission, and enters a loop that sends a 4-word test payload each time you press Enter.

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_SerHDLC_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_HDLC_Tx(cardIndex, module, moduleID) to configure the channel and begin transmitting.

#if defined (__VXWORKS__)
int32_t SER_HDLC_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_HDLC_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 application entry point is main() on most platforms, or SER_HDLC_Tx_Sample() on VxWorks. After the board connection is established, main() retrieves the module ID and calls Run_SER_HDLC_Tx() to configure the channel and transmit data.

Interface Selection

Before configuring the channel, the application calls serial_query_interface() to prompt the user for a physical interface level. The available options are:

  • 1 — Loopback (NAI_SER_INTF_LOOPBACK) — routes transmitted data back to the receiver internally. Useful for self-test without external wiring, though the SER HDLC Loopback sample is better suited for loopback testing.

  • 2 — RS-232 (NAI_SER_INTF_RS232)

  • 3 — RS-422 (NAI_SER_INTF_RS422) — the recommended interface for HDLC communication.

  • 4 — RS-485 (NAI_SER_INTF_RS485)

The default is loopback if the user enters an invalid choice. In your own application, call naibrd_SER_SetInterfaceLevel() directly with the desired interface constant — the menu is a sample convenience.

Linear Flow

The transmit routine follows a straight-line sequence:

  1. Query — select a channel number and interface level.

  2. Reset — reset the channel and clear FIFOs.

  3. Configure — set HDLC protocol, interface level, clock mode, baud rate, sync character, and address recognition.

  4. Transmit — load test data into the Tx FIFO and initiate transmission in a loop.

FIFO Setup

Before configuring protocol parameters, the application resets the channel and clears its Rx and Tx FIFOs. The clear operation is asynchronous — the hardware sets control-register bits while the clear is in progress — so the application must poll until those bits drop or a timeout expires.

To prepare the channel for transmission in your own application, follow this sequence:

  1. Call naibrd_SER_ChannelReset() to reset the channel to a known state.

  2. Call naibrd_SER_ClearRxFifo() and naibrd_SER_ClearTxFifo() to request FIFO clears.

  3. Poll naibrd_SER_GetChannelControlRaw() in a loop, checking NAI_SER_CTRLLO_CLEAR_RX_FIFO | NAI_SER_CTRLLO_CLEAR_TX_FIFO in the low 16 bits. The loop sleeps 1 ms per iteration (nai_msDelay(1)) and gives up after 1,000 iterations (a 1-second timeout defined by CLEAR_FIFO_TIMEOUT).

naibrd_SER_ChannelReset(cardIndex, modNum, chanNum);
naibrd_SER_ClearRxFifo(cardIndex, modNum, chanNum);
naibrd_SER_ClearTxFifo(cardIndex, modNum, 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, modNum, 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;
}

Even though this sample only transmits, both the Rx and Tx FIFOs are cleared to ensure the channel starts in a clean state. This is important if the channel was previously used for loopback or bidirectional communication.

Important
  • FIFO clear timeout — if the polling loop reaches 1,000 iterations without the clear bits dropping, the channel may be in use or the hardware is not responding. The application prints an error and returns. Check that the module is seated correctly and that no other process holds the channel open.

Channel Configuration

After the FIFOs are cleared, the application configures the channel for HDLC transmission. Each parameter must be set before data is loaded into the Tx FIFO.

/* Configure for HDLC on the channel selected. */
check_status(naibrd_SER_SetProtocol(cardIndex, modNum, chanNum, NAI_SER_PROTOCOL_HDLC));        /* HDLC mode */
check_status(naibrd_SER_SetInterfaceLevel(cardIndex, modNum, chanNum, interfaceLevel));         /* Loopback, RS232, RS422, or RS485 */
check_status(naibrd_SER_SetClockMode(cardIndex, modNum, chanNum, TXINT_RXINT));                 /* Tx and Rx internal clock */
check_status(naibrd_SER_SetBaudrate(cardIndex, modNum, chanNum, 115200));                       /* 115,200b */
check_status(naibrd_SER_SetTxHdlcAddrsSyncChar(cardIndex, modNum, chanNum, 0x247A));            /* xmit sync char */
nConfigWordLo = (NAI_SER_CFGLO_ADDR_LEN_16 | NAI_SER_CFGLO_ADDR_REC);                           /* 16-bit HDLC addr recognition */
check_status(naibrd_SER_SetChannelConfigRaw(cardIndex, modNum, chanNum, nConfigWordLo));

/* 100 millisecond wait for initialization to complete */
nai_msDelay(100);

The calls break down as follows:

  • SetProtocol(NAI_SER_PROTOCOL_HDLC) — selects synchronous HDLC mode. This tells the hardware to use frame-oriented communication with automatic sync character insertion and CRC generation.

  • SetInterfaceLevel(interfaceLevel) — sets the physical interface to the user’s selection (loopback, RS-232, RS-422, or RS-485). For external transmission, RS-422 is typical. The receiving end must be configured for the same interface level.

  • SetClockMode(TXINT_RXINT) — both the transmit and receive clocks are generated internally by the module. This is the standard configuration when the module is the clock source. If an external clock source is driving the line, use TXEXT_RXEXT instead. Consult your module’s manual for supported clock modes.

  • SetBaudrate(115200) — sets the synchronous line rate to 115,200 bps. The receiving end must be configured to the same baud rate.

  • SetTxHdlcAddrsSyncChar(0x247A) — programs the transmit sync character (also used as the HDLC address). The receiving end must call naibrd_SER_SetRxHdlcAddrsSyncChar() with the same value (0x247A) for the receiver to detect valid frame boundaries.

  • SetChannelConfigRaw(NAI_SER_CFGLO_ADDR_LEN_16 | NAI_SER_CFGLO_ADDR_REC) — enables 16-bit HDLC address recognition. This must match the receiver’s configuration.

  • nai_msDelay(100) — a 100 ms wait to allow the hardware to complete initialization before the application begins transmitting.

Matching the Receiver Configuration

When pairing this sample with the SER HDLC Rx sample (or your own receiver), the following parameters must match on both sides:

  • Protocol — both channels must be set to NAI_SER_PROTOCOL_HDLC.

  • Baud rate — both channels must use the same line rate (115,200 bps in this sample).

  • Sync character — the Tx sync character set by SetTxHdlcAddrsSyncChar() must match the Rx sync character set by SetRxHdlcAddrsSyncChar() on the receiver. If these differ, the receiver will never synchronize to the transmitted frames.

  • Address length and recognition — the configuration word (NAI_SER_CFGLO_ADDR_LEN_16 | NAI_SER_CFGLO_ADDR_REC) must be the same on both sides.

  • Interface level — both channels must use the same electrical interface (RS-422, etc.).

Important
  • Sync character mismatch — the Tx sync character programmed here must match the Rx sync character on the receiving channel. If the values differ, the receiver will never detect valid frame boundaries and no data will be received.

  • Clock mode mismatch — this sample uses internal clocking (TXINT_RXINT). Ensure the receiver is also configured for a compatible clock mode. If the receiver expects an external clock, it must be wired to receive the transmitter’s clock signal.

  • Baud rate mismatch — the transmitter and receiver must agree on the line rate. A mismatch causes framing errors and corrupted data.

  • NAI_ERROR_NOT_SUPPORTED — the selected module or channel does not support the requested protocol or interface level. Verify that the module is a supported SER type and that HDLC mode is available. SC3 modules do not support synchronous serial communications.

Data Transmission

After configuration, the application builds a 4-word test payload and enters a transmit loop. Each press of Enter sends the same payload again.

Building the Test Data

The sample creates an array of NUM_DATA_TX (4) words with incrementing values starting at 0x31 (ASCII 1):

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

This produces the values 0x31, 0x32, 0x33, 0x34. In your own application, replace this with whatever payload data you need to transmit.

Transmitting

To transmit HDLC data, load the payload into the Tx FIFO with naibrd_SER_TransmitBuffer() and then trigger the transmission with naibrd_SER_TransmitInitiate():

printf("Sending %d words ...", nNumWordsSend);
naibrd_SER_TransmitBuffer(cardIndex, modNum, chanNum, sizeof(SendData[0]), SendData, nNumWordsSend, (uint32_t*)&nNumWordsSend); /* load FIFO */
naibrd_SER_TransmitInitiate(cardIndex, modNum, chanNum);   /* Initiate Transmit */
printf(" %d words sent\n", nNumWordsSend);
  • naibrd_SER_TransmitBuffer(cardIndex, modNum, chanNum, sizeof(SendData[0]), SendData, nNumWordsSend, &nNumWordsSend) — loads the raw data bytes into the channel’s Tx FIFO. The sizeof(SendData[0]) parameter specifies the size of each data element (4 bytes for uint32_t). The final parameter returns the number of words actually written.

  • naibrd_SER_TransmitInitiate(cardIndex, modNum, chanNum) — tells the hardware to begin transmission. The hardware automatically wraps the data in a complete HDLC frame — sync characters, payload, and CRC. Your application provides only the raw data bytes; it never constructs framing or computes CRC values.

The application loops, sending the same payload each time the user presses Enter, until the user types the quit character to exit.

What Appears on the Wire

When TransmitInitiate() fires, the hardware transmits a complete HDLC frame on the physical interface:

  1. Sync characters — the hardware inserts the sync character (0x247A) at the beginning of the frame.

  2. Payload — the 4 data bytes (0x31, 0x32, 0x33, 0x34) are transmitted as the frame body.

  3. CRC — the hardware computes and appends a CRC at the end of the frame for error detection.

A receiver configured with matching parameters (same protocol, baud rate, sync character, and address configuration) will detect the frame boundaries, validate the CRC, and deliver the payload bytes to the receiving application. See the SER HDLC Rx guide for details on the receive side, or the SER HDLC Loopback guide for details on HDLC status byte decoding.

Important
  • No data appears on the wire — verify that TransmitInitiate() is called after TransmitBuffer(). Loading the FIFO alone does not start transmission. Also confirm the interface level is not set to loopback if you intend to send data externally.

  • Receiver reports CRC errors — the Tx and Rx sync characters, baud rate, and address configuration must match. A mismatch in any of these causes the receiver to misinterpret frame boundaries, resulting in CRC failures.

  • Fewer words sent than expected — if the Tx FIFO is full, TransmitBuffer() writes only as many words as will fit. Check the returned word count and retransmit any remaining data.

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, missing configuration file, network or bus misconfiguration

Verify power, cabling, and configuration file. Check IP settings for Ethernet connections.

Invalid card or module index

Zero-based card index or one-based module index out of range

Confirm the indices match your hardware layout using the board menu.

Module not present at selected slot

No SER module installed in the selected slot

Use the board menu to verify which slots are populated.

FIFO clear timeout

Channel in use by another process, hardware not responding

Verify the module is seated correctly. Close any other applications using the channel.

NAI_ERROR_NOT_SUPPORTED

Module does not support HDLC or the requested interface level

Verify the module type supports synchronous serial. SC3 does not support HDLC.

No data on the wire

TransmitInitiate() not called, interface set to loopback, cable not connected

Ensure TransmitInitiate() follows TransmitBuffer(). Confirm the interface level is RS-422 (or RS-232/RS-485) and the cable is connected.

Receiver does not detect frames

Sync character mismatch between Tx and Rx, baud rate mismatch, address config mismatch

Ensure the Tx sync character matches the Rx sync character. Verify both sides use the same baud rate and address recognition settings.

Receiver reports CRC errors

Baud rate mismatch, clock mode incompatibility, noisy cable

Verify baud rate and clock mode match. Check cable integrity and shielding.

Fewer words sent than expected

Tx FIFO full

Check the returned word count from TransmitBuffer(). Retransmit remaining data after the current frame completes.

Full Source

Full Source — SER_HDLC_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_SerHDLC_Tx.txt";

/* Function prototypes */
void Run_SER_HDLC_Tx(int32_t cardIndex, int32_t modNum, uint32_t modid);
static void serial_query_interface(nai_ser_interface_t* interfaceLevel);

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

/**************************************************************************************************************/
/** \defgroup SERHDLCTx Serial Synchronous Transmit
The purpose of the Serial Synchronous Transmit sample application is to illustrate the methods to call in the
naibrd library to configure a given serial channel for transmitting. The SER_HDLC_Rx application can be run in
unison to this application to receive serial data.
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SER_HDLC_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_HDLC_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 SERHDLCTx
Configures a serial module for synchronous 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 modNum    (Input) Module Number of the module to access (1 - [max modules for board]).
\param modid  (Input) The ID of the module.
*/
/**************************************************************************************************************/
void Run_SER_HDLC_Tx(int32_t cardIndex, int32_t modNum, uint32_t modid)
{
   int32_t ch, i;
   int32_t channelCount;
   int32_t chanNum;
   int32_t nCntlValueLo, nConfigWordLo;
   int32_t nNumWordsSend = 0;
   bool_t bQuit = FALSE;
   uint32_t SendData[NUM_DATA_TX];
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   nai_ser_interface_t interfaceLevel = NAI_SER_INTF_LOOPBACK;

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

   naibrd_SER_ChannelReset(cardIndex, modNum, chanNum);
   naibrd_SER_ClearRxFifo(cardIndex, modNum, chanNum);
   naibrd_SER_ClearTxFifo(cardIndex, modNum, 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, modNum, 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 HDLC on the channel selected. */
   check_status(naibrd_SER_SetProtocol(cardIndex, modNum, chanNum, NAI_SER_PROTOCOL_HDLC));        /* HDLC mode */
   check_status(naibrd_SER_SetInterfaceLevel(cardIndex, modNum, chanNum, interfaceLevel));         /* Loopback, RS232, RS422, or RS485 */
   check_status(naibrd_SER_SetClockMode(cardIndex, modNum, chanNum, TXINT_RXINT));                 /* Tx and Rx internal clock */
   check_status(naibrd_SER_SetBaudrate(cardIndex, modNum, chanNum, 115200));                       /* 115,200b */
   check_status(naibrd_SER_SetTxHdlcAddrsSyncChar(cardIndex, modNum, chanNum, 0x247A));            /* xmit sync char - must be same as recv for loopback */
   nConfigWordLo = (NAI_SER_CFGLO_ADDR_LEN_16 | NAI_SER_CFGLO_ADDR_REC);                           /* 16-bit HDLC addr recognition */
   check_status(naibrd_SER_SetChannelConfigRaw(cardIndex, modNum, chanNum, nConfigWordLo));

   /* 100 millisecond wait for initialization to complete */
   nai_msDelay(100);

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

   do
   {
      printf("Sending %d words ...", nNumWordsSend);
      naibrd_SER_TransmitBuffer(cardIndex, modNum, chanNum, sizeof(SendData[0]), SendData, nNumWordsSend, (uint32_t*)&nNumWordsSend); /* load FIFO */
      naibrd_SER_TransmitInitiate(cardIndex, modNum, chanNum);   /* Initiate Transmit */
      printf(" %d words sent\n", nNumWordsSend);

      printf("Press ENTER to transmit again, or '%c' to exit program : ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   } while (TRUE != bQuit);

   return;
}

/**************************************************************************************************************/
/** \ingroup SERHDLCTx
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