PB BasicOps
Edit this on GitLab
PB BasicOps Sample Application (SSK 1.x)
Overview
The PB BasicOps sample application demonstrates how to operate an NAI PROFIBUS (PB) DP Master module using the NAI Software Support Kit (SSK 1.x). PROFIBUS DP (Decentralized Peripherals) is a deterministic fieldbus widely used in process automation and factory-floor I/O. The NAI PB1 module acts as a Class 1 DP Master, managing cyclic data exchange with up to 126 slave devices across one or more physical bus segments.
This sample covers the full range of PROFIBUS master operations you will need in your own application: master state machine control (Offline, Stop, Clear, Operate), bus parameter configuration, cyclic I/O data exchange, acyclic parameter read/write (DPV1 services), slave diagnostics and alarm management, live list discovery, segment and termination control, and system time synchronization. Each menu command maps directly to one or more naibrd_PB_*() API calls that you can lift into your own code.
This sample supports the PB1 module type (NAIBRD_MODULE_ID_PB1).
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a PB1 module installed and at least one PROFIBUS DP slave device connected to a bus segment.
-
A properly terminated PROFIBUS network — the PB1 module supports software-controlled termination on each segment.
-
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 PB_BasicOps executable from your build output directory. On startup the application looks for a configuration file (default_PBBasicOps.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, a command menu lets you exercise each PROFIBUS operation.
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 PB. |
The main() function follows a standard SSK 1.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_PBBasicOps.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. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleID()so downstream code can confirm a PB module is installed at the selected slot.
#if defined (__VXWORKS__)
int32_t PB_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t moduleCnt;
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, &inputPBConfig.cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(inputPBConfig.cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &inputPBConfig.module);
if (stop != TRUE)
{
inputPBConfig.modId = naibrd_GetModuleID(inputPBConfig.cardIndex, inputPBConfig.module);
if ((inputPBConfig.modId != 0))
{
naiapp_Run_PB_BasicOps();
}
}
}
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:
|
Program Structure
Application Parameters
The sample stores the board connection context in a global PBConfig struct:
typedef struct
{
int32_t cardIndex;
int32_t module;
uint32_t modId;
} PBConfig;
PBConfig inputPBConfig;
In your own application, you will track the same values — cardIndex identifies which board you are talking to, module selects the slot containing the PB1 module, and modId confirms the module type. Every naibrd_PB_*() call requires at least cardIndex and module.
Command Menu
After connecting to the board, the sample enters naiapp_Run_PB_BasicOps(), which presents an alphabetic/numeric menu mapping each letter or digit to a specific PROFIBUS operation. The menu system is a sample convenience — in your own code, call these API functions directly.
The sample organizes 32+ operations into a flat menu (A through 9). This guide groups them into logical functional categories for easier reference.
Master State Machine Control
The PROFIBUS DP Master operates through a defined state machine. At power-up, the master is in the Offline state. To begin data exchange with slave devices, you must transition the master through these states in order: Offline → Stop → Clear → Operate. Each state serves a specific purpose in the PROFIBUS protocol:
-
Offline — the master is not participating on the bus. No token passing, no communication.
-
Stop — the master holds the token and monitors the bus but does not exchange data with slaves. Bus parameters are active.
-
Clear — the master begins polling slaves and establishing connections, but all outputs to slaves are held at zero (safe state). Input data from slaves is read normally.
-
Operate — full bidirectional data exchange. Outputs are driven to slaves, inputs are received.
The redundancy mode parameter (redMode) enables redundant master operation when set to 1. In normal (non-redundant) configurations, pass 0.
Set Offline
To take the PROFIBUS master offline and cease all bus activity, call naibrd_PB_SetOffline(). This is the most restrictive state — the master releases the token and stops participating in the bus entirely. Use this when you need to reconfigure bus parameters or safely disconnect from the network.
status = naibrd_PB_SetOffline(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
Parameters:
-
cardIndex— board index (zero-based). -
module— module slot (one-based). -
redMode— pass0for normal mode,1for redundancy mode.
Set Stop
To transition the master to the Stop state, call naibrd_PB_SetStop(). In this state the master holds the bus token and monitors traffic, but does not exchange process data with slaves. This is useful for bus diagnostics — you can observe the live list and statistics without affecting slave outputs.
status = naibrd_PB_SetStop(inputPBConfig.cardIndex, inputPBConfig.module);
Parameters:
-
cardIndex— board index (zero-based). -
module— module slot (one-based).
No additional parameters are required. The master transitions from its current state to Stop.
Set Clear
To enter the Clear state, call naibrd_PB_SetClear(). The master begins cyclic polling of configured slaves: it reads input data from them but forces all outputs to zero. This is the safe pre-operational state where you can verify that all slaves are responding before enabling real output data.
status = naibrd_PB_SetClear(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
Parameters:
-
cardIndex— board index (zero-based). -
module— module slot (one-based). -
redMode— pass0for normal mode,1for redundancy mode.
Set Operate
To enable full data exchange, call naibrd_PB_SetOperate(). The master now drives real output data to slaves and reads input data. This is the normal operational state for a running system.
status = naibrd_PB_SetOperate(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
Parameters:
-
cardIndex— board index (zero-based). -
module— module slot (one-based). -
redMode— pass0for normal mode,1for redundancy mode.
Get Operation Mode
To query the current master state and operation mode at any time, call naibrd_PB_GetOperationMode(). This returns both the master health state (OK, error conditions) and the current operation mode (Offline, Stop, Clear, Operate, or their redundant equivalents).
NAIBRD_PB_DPM_MASTER_STATE masterState;
NAIBRD_PB_DPM_OPERATION_MODE operationMode;
status = naibrd_PB_GetOperationMode(inputPBConfig.cardIndex, inputPBConfig.module, &masterState, &operationMode);
The masterState value indicates whether the master is healthy (DPM_MASTER_STATE_OK) or experiencing an error condition such as DPM_MASTER_STATE_DOUBLE_ADDRESS_ERROR, DPM_MASTER_STATE_DISTURBED_BUS_ERROR, DPM_MASTER_STATE_HARDWARE_ERROR, or DPM_MASTER_STATE_AUTOCLEAR (the master automatically returned to Clear state because a slave failed). The operationMode maps to the state machine positions described above.
|
Important
|
Common Errors
|
Bus Configuration
Before bringing the master online, you typically configure the bus parameters that govern timing, baud rate, and polling behavior. These parameters must match the physical characteristics of your PROFIBUS network (cable length, number of stations, baud rate).
Set Bus Parameters
To configure the full set of PROFIBUS bus timing parameters, call naibrd_PB_SetBusParams(). This sets all timing values at once through the NAIBRD_PB_BUS_PARAMS structure. You must set these parameters while the master is in the Offline or Stop state — they take effect when the master transitions to Clear or Operate.
NAIBRD_PB_BUS_PARAMS busParams;
busParams.tSlot = 300; /* Slot time: max wait for first response byte (37-16383) */
busParams.minTsdr = 11; /* Min station delay of responder (11-1023) */
busParams.maxTsdr = 150; /* Max station delay of responder (37-65535) */
busParams.baudrate = NAIBRD_PB_MBAUD_1_5; /* Baud rate code from naibrd_pb.h */
busParams.tQui = 0; /* Quiet time for transceiver switching (0-493) */
busParams.tSet = 1; /* Setup time / data link layer latency (1-494) */
busParams.tTrHi = 0; /* Target rotation time high word (256-16776960 combined) */
busParams.tTrLow = 5000; /* Target rotation time low word */
busParams.maxRetryLimit = 3; /* Frame retransmission count before declaring slave unavailable (0-7) */
status = naibrd_PB_SetBusParams(inputPBConfig.cardIndex, inputPBConfig.module, &busParams);
Key parameters explained:
-
tSlot — the maximum time (in bit times) the master waits for the first byte of a response after sending a request, or for a frame from the token receiver after a token exchange. If no response arrives within tSlot, the master retries or declares the responder unavailable. Valid range: 37—16383.
-
minTsdr / maxTsdr — minimum and maximum station delay of responder. These bound the time a slave may take between receiving a request and beginning its response. Valid ranges: 11—1023 and 37—65535 respectively.
-
baudrate — the physical transmission speed. Use the constants defined in
naibrd_pb.h(e.g.,NAIBRD_PB_KBAUD_9_6throughNAIBRD_PB_MBAUD_12, orNAIBRD_PB_AUTOBAUDfor auto-detection). -
tQui — quiet time during which the PROFIBUS transceiver switches between transmit and receive. Valid range: 0—493.
-
tSet — setup time representing the data link layer latency. Valid range: 1—494.
-
tTrHi / tTrLow — target rotation time (split into high and low words). This is the maximum permissible time for a complete token rotation around all masters on the bus. Valid combined range: 256—16776960.
-
maxRetryLimit — how many times the master retransmits a request before declaring the responder unavailable. Valid range: 0—7.
Set Dynamic Bus Parameters
To adjust a subset of bus timing parameters at runtime without performing a full reconfiguration, call naibrd_PB_SetDynamicBusParams(). This is useful for tuning timing on a live network, for example when adding a new station.
status = naibrd_PB_SetDynamicBusParams(inputPBConfig.cardIndex, inputPBConfig.module,
stationAddr, maxRetryLimit, tSlot, maxTsdr);
Parameters:
-
stationAddr— the station address to which these parameters apply. -
maxRetryLimit— new retry limit (0—7). -
tSlot— new slot time (37—16383). -
maxTsdr— new maximum station delay of responder (37—65535).
Bus Parameter Reconfiguration
To change individual master-level bus parameters (master address, highest station address, or minimum slave interval), call naibrd_PB_BusParamReconfiguration(). The busParam argument selects which parameter to change:
-
0— reconfigure master address. -
1— reconfigure HSA (Highest Station Address), which determines the range of addresses scanned during live list discovery. -
2— reconfigure minimum slave interval (requires both high and low bytes).
/* Example: change the master address to 1 */
status = naibrd_PB_BusParamReconfiguration(inputPBConfig.cardIndex, inputPBConfig.module,
0, /* busParam: 0=master addr */ 1, /* new master address */ 0 /* field2: unused for this param */);
Start Reconfiguration
After changing bus parameters, call naibrd_PB_StartReconfiguration() to apply the new configuration. Pass 1 to enable the reconfiguration process or 0 to cancel it.
status = naibrd_PB_StartReconfiguration(inputPBConfig.cardIndex, inputPBConfig.module, 1);
Set Poll Cycle Mode
To control whether the master polls slaves asynchronously or synchronously, call naibrd_PB_SetPollCycleMode(). In asynchronous mode (0), the master services acyclic requests between poll cycles. In synchronous mode (1), all slaves are polled in a single deterministic cycle.
status = naibrd_PB_SetPollCycleMode(inputPBConfig.cardIndex, inputPBConfig.module, pollCycleMode);
Parameters:
-
pollCycleMode—0for asynchronous (default),1for synchronous.
Set and Enable Max Cycle Counter
To configure a watchdog on the bus cycle count, call naibrd_PB_SetAndEnableMaxCycleCounter(). If the master completes the specified number of cycles without a successful data exchange on a channel, that channel is taken offline. This acts as a safety mechanism to detect stalled or unresponsive slaves.
status = naibrd_PB_SetAndEnableMaxCycleCounter(inputPBConfig.cardIndex, inputPBConfig.module, maxCycleCount);
Parameters:
-
maxCycleCount— the maximum number of bus cycles before a channel goes offline.
|
Important
|
Common Errors
|
Cyclic I/O Data Exchange
Cyclic data exchange is the core function of PROFIBUS DP. Once the master is in Clear or Operate state, it automatically polls configured slaves on every bus cycle, exchanging process data. The master maintains an input image (data read from slaves) and an output image (data written to slaves). These API calls let you read and write those images.
Read IO Data
To read process input data received from a slave device, call naibrd_PB_ReadIOData(). This reads from the master’s local input image — the data that the slave sent during the last successful poll cycle. The data is returned as a raw byte array.
int8_t data[NAIBRD_PB_MAX_PDU_LENGTH];
status = naibrd_PB_ReadIOData(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, offset, readCount, &(data[0]));
Parameters:
-
slaveAddr— the PROFIBUS station address of the slave (2—128). -
offset— byte offset into the slave’s input data area. -
readCount— number of bytes to read. -
data— buffer to receive the data (must be at leastreadCountbytes, maximumNAIBRD_PB_MAX_PDU_LENGTH= 256).
The interpretation of the raw bytes depends on the slave device’s I/O configuration. Consult the slave device documentation for the data layout.
Write IO Data
To send process output data to a slave device, call naibrd_PB_WriteIOData(). This updates the master’s local output image. The master transmits the updated data to the slave on the next poll cycle. In Clear state, outputs are forced to zero regardless of what you write — you must be in Operate state for writes to reach the slave.
int8_t bytesToWrite[2];
bytesToWrite[0] = 0x01;
bytesToWrite[1] = 0x02;
status = naibrd_PB_WriteIOData(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, offset, numBytesToWrite, bytesToWrite);
Parameters:
-
slaveAddr— the PROFIBUS station address of the slave (2—128). -
offset— byte offset into the slave’s output data area. -
numBytesToWrite— number of bytes to write. -
bytesToWrite— pointer to the data bytes.
Set New IO Configuration
To reconfigure the I/O mapping for a specific slave at runtime, call naibrd_PB_SetNewIOConfig(). This sends a new configuration data block to the slave, which can change the slave’s I/O module assignment and data lengths. The configuration data format is defined by the slave device’s GSD file.
int8_t cfgData[NAIBRD_PB_MAX_CFG_DATA_LENGTH];
/* Fill cfgData with the slave's configuration bytes from the GSD file */
status = naibrd_PB_SetNewIOConfig(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, cfgDataLength, &(cfgData[0]));
Parameters:
-
slaveAddr— the PROFIBUS station address of the slave (2—128). -
cfgDataLength— the number of configuration bytes (1—240). -
cfgData— the configuration data bytes. The format is slave-specific and defined in the slave’s GSD file.
On failure, the sample retrieves the PB-specific error code using naibrd_PB_GetLastFunctionCallStatus() for detailed diagnostics.
|
Important
|
Common Errors
|
Acyclic Data Services (DPV1)
PROFIBUS DPV1 extends the basic DP protocol with acyclic read and write services. These allow you to access slave parameters, configuration data, and diagnostic information outside of the cyclic poll cycle. Acyclic services are multiplexed between poll cycles and do not affect cyclic data timing.
Before performing acyclic reads or writes, you must establish a communication reference (connection) to the target slave.
Initiate Communication
To open an acyclic communication channel to a slave, call naibrd_PB_InitiateCommunication(). This establishes a DPV1 connection using the specified communication reference number. The timeout parameter controls how long the master waits for the slave to acknowledge the connection.
status = naibrd_PB_InitiateCommunication(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, commRef, maxTimeoutInMS);
Parameters:
-
slaveAddr— the PROFIBUS station address of the slave (2—128). -
commRef— a communication reference number that identifies this connection. Use different values for simultaneous connections to different slaves. -
maxTimeoutInMS— maximum time in milliseconds to wait for the slave to acknowledge the connection.
Acyclic Read
To read parameter or diagnostic data from a slave outside of the cyclic exchange, call naibrd_PB_AcyclicRead(). This performs a DPV1 Read service, addressing a specific slot and parameter index within the slave.
int8_t data[NAIBRD_PB_MAX_CFG_DATA_LENGTH];
int32_t dataReadCount = 0;
status = naibrd_PB_AcyclicRead(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, slotNumber, paramIndex, paramDataLength, &dataReadCount, &(data[0]));
Parameters:
-
slaveAddr— the PROFIBUS station address of the slave (2—128). -
slotNumber— the module slot within the slave device (as defined in the GSD file). -
paramIndex— the parameter index to read. -
paramDataLength— the expected data length in bytes. -
dataReadCount— receives the actual number of bytes read. -
data— buffer to receive the parameter data.
Acyclic Write
To write parameter data to a slave outside of the cyclic exchange, call naibrd_PB_AcyclicWrite(). This performs a DPV1 Write service.
int32_t paramData[NAIBRD_PB_MAX_CMD_PARAMS];
/* Fill paramData with the values to write */
status = naibrd_PB_AcyclicWrite(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, slotNumber, paramIndex, paramDataLength, &(paramData[0]));
Parameters:
-
slaveAddr— the PROFIBUS station address of the slave (2—128). -
slotNumber— the module slot within the slave device. -
paramIndex— the parameter index to write. -
paramDataLength— the number of data elements to write. -
paramData— the data values to write.
Abort Communication
To close an acyclic communication channel, call naibrd_PB_AbortCommunication(). This releases the DPV1 connection identified by the communication reference. Always abort communication when you are done with acyclic services to free resources.
status = naibrd_PB_AbortCommunication(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, commRef);
Parameters:
-
slaveAddr— the PROFIBUS station address of the slave (2—128). -
commRef— the communication reference number used when the connection was initiated.
|
Important
|
Common Errors
|
Slave Diagnostics and Alarms
PROFIBUS DP provides rich diagnostic capabilities. The master can query individual slaves for their health status, alarm history, and connection reliability. These functions are essential for monitoring a running system and detecting problems before they cause process failures.
Get MS0 Connection Status
To check the cyclic connection health of a specific slave, call naibrd_PB_GetMS0ConnectionStatus(). MS0 refers to the Class 1 Master-Slave connection used for cyclic data exchange. The returned structure tells you whether the slave is actively exchanging data and provides counters for connection restarts, missing responses, and invalid responses.
NAIBRD_PB_CONNECTION_STATUS connectionStatus;
status = naibrd_PB_GetMS0ConnectionStatus(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, &connectionStatus);
Returned fields:
-
isSlaveInDataExchange—1if the slave is actively exchanging cyclic data,0otherwise. -
numberOfRestarts— how many times the connection to this slave has been re-established since the master entered Operate. -
missingResponseCount— number of poll cycles where the slave did not respond within tSlot. -
invalidResponseCount— number of poll cycles where the slave responded with malformed data.
A healthy slave will show isSlaveInDataExchange = 1 with low or zero restart and error counts. Rising error counts indicate intermittent communication problems — check cabling, termination, and EMI shielding.
Reset MS0 Connection Counters
To zero out the connection status counters for a specific slave, call naibrd_PB_ResetMS0ConnectionCounters(). This is useful when you want to measure error rates over a specific time window.
status = naibrd_PB_ResetMS0ConnectionCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr);
Get Alarm Counters
To retrieve the accumulated alarm counts for a specific slave, call naibrd_PB_GetAlarmCounters(). PROFIBUS defines several alarm types that slaves can report to the master:
NAIBRD_PB_ALARM_COUNTERS alarmCounters;
status = naibrd_PB_GetAlarmCounters(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, &alarmCounters);
Returned fields:
-
numberDiagAlarms— diagnostic alarms (slave hardware faults, overtemperature, etc.). -
numberProcessAlarms— process alarms (measurement out of range, sensor failure). -
numberPullAlarms— a module was removed from the slave while the system was running. -
numberPlugAlarms— a module was inserted into the slave while the system was running. -
numberStatusAlarms— general status change notifications. -
numberUpdateAlarms— the slave’s configuration was updated. -
numberManufacturerAlarms— vendor-specific alarms defined by the slave manufacturer.
Reset Alarm Counters
To clear the alarm counters for a specific slave, call naibrd_PB_ResetAlarmCounters().
status = naibrd_PB_ResetAlarmCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr);
Get Last Alarm Data
To retrieve the detailed payload of the most recent alarm from a specific slave, call naibrd_PB_GetLastAlarmData(). This returns the full alarm block including type, slot number, specifier, and any diagnostic user data attached by the slave.
NAIBRD_PB_ALARM_DATA lastAlarmData;
status = naibrd_PB_GetLastAlarmData(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, &lastAlarmData);
Returned fields:
-
blockLength— total length of the alarm data block. -
type— alarm type code (diagnostic, process, pull, plug, status, update, or manufacturer). -
slotNumber— which module slot within the slave generated the alarm. -
specifier— additional alarm qualification bits. -
diagnosticUserDataCount— number of extra diagnostic bytes. -
diagnosticUserDataArray[]— the raw diagnostic payload from the slave.
Get Slave Diagnostics
To retrieve the full diagnostic record for a specific slave, call naibrd_PB_GetSlaveDiagnostics(). This returns the standard PROFIBUS diagnostic data including station status bytes, the master address the slave reports to, identity numbers, and any extended diagnostic data.
NAIBRD_PB_SLAVE_DIAGNOSTICS slaveDiagnostics;
status = naibrd_PB_GetSlaveDiagnostics(inputPBConfig.cardIndex, inputPBConfig.module,
slaveAddr, &slaveDiagnostics);
Returned fields:
-
stationStatus1/stationStatus2/stationStatus3— standard PROFIBUS status bytes. Bit definitions are specified in the PROFIBUS standard (IEC 61158). Key bits include "station not ready," "configuration fault," "extended diagnostic," and "parameter fault." -
masterAddr— the address of the master that parameterized this slave. -
identityNumberHigh/identityNumberLow— the slave’s PROFIBUS identity number (manufacturer and device ID). -
lengthOfExtraDiagData— number of additional diagnostic bytes. -
extraDiagDataArray[]— extended diagnostic data (format is slave-specific).
|
Important
|
Common Errors
|
Network Discovery and Statistics
These functions help you understand the current state of the PROFIBUS network: which devices are present, what the bus parameters are, and how the master processor is loaded.
Get Live List
To discover which devices are currently active on the PROFIBUS network, use the live list feature. This is a two-step operation: first, call naibrd_PB_KickoffGetLiveList() to initiate a bus scan. The master queries all possible station addresses. Then, after allowing time for the scan to complete, call naibrd_PB_GetLiveListResults() to retrieve the results.
/* Step 1: Kick off the scan */
status = naibrd_PB_KickoffGetLiveList(inputPBConfig.cardIndex, inputPBConfig.module);
/* Step 2: Retrieve results (call after scan completes) */
NAIBRD_PB_LIVELIST_RESULTS liveListResults;
status = naibrd_PB_GetLiveListResults(inputPBConfig.cardIndex, inputPBConfig.module, &liveListResults);
Returned fields:
-
passiveStationCount— number of passive (slave) stations found. -
activeStationCount— number of active (master) stations found. -
passiveStations[]— array of slave station addresses. -
activeStations[]— array of master station addresses.
If naibrd_PB_GetLiveListResults() returns NAI_ERROR_FUNCTION_SPECIFIC_ERROR, the scan may still be in progress. Call naibrd_PB_GetLastFunctionCallStatus() to get the PB-specific status code — NAI_PB_REQUEST_STILL_RUNNING_ERROR means you should wait and retry.
Get Statistics
To retrieve comprehensive bus statistics, call naibrd_PB_GetStatistics(). This returns the current bus parameters as negotiated on the network, along with lists of active master and slave stations.
NAIBRD_PB_STATISTICS statistics;
status = naibrd_PB_GetStatistics(inputPBConfig.cardIndex, inputPBConfig.module, &statistics);
Returned fields:
-
numMasterStations/masterStationsArray[]— count and addresses of master stations on the bus. -
numSlaveStations/slaveStationsArray[]— count and addresses of slave stations on the bus. -
stationAddress— this master’s own station address. -
baudRate— the active baud rate. -
tIdle1/tIdle2— idle time measurements. -
tSlot— active slot time. -
tTr— actual token rotation time. -
minSlaveInterval— minimum slave response interval. -
maxAcyclicServicesPerPollCycle— how many acyclic services the master can handle per poll cycle.
Get CPU Load
To monitor how heavily the PB module’s processor is loaded, call naibrd_PB_GetCPULoad(). This returns CPU utilization percentages averaged over three time windows. High CPU load may indicate that the bus configuration is too aggressive for the number of slaves or the baud rate.
NAIBRD_PB_CPU_LOAD cpuLoad;
status = naibrd_PB_GetCPULoad(inputPBConfig.cardIndex, inputPBConfig.module, &cpuLoad);
Returned fields:
-
last100ms— CPU load percentage over the last 100 milliseconds. -
last1s— CPU load percentage over the last 1 second. -
last10s— CPU load percentage over the last 10 seconds.
Get PSAK Version
To query the firmware and PSAK (PROFIBUS Stack) software version running on the PB module, call naibrd_PB_GetPSAKVersion(). This is useful for verifying firmware compatibility and for diagnostic reporting.
char firmwareVersion[NAIBRD_PB_VERSION_MAX_LENGTH];
char psakVersion[NAIBRD_PB_VERSION_MAX_LENGTH];
status = naibrd_PB_GetPSAKVersion(inputPBConfig.cardIndex, inputPBConfig.module,
NAIBRD_PB_VERSION_MAX_LENGTH, &(firmwareVersion[0]),
NAIBRD_PB_VERSION_MAX_LENGTH, &(psakVersion[0]));
|
Important
|
Common Errors
|
Segment and Termination Control
The NAI PB1 module supports up to 8 physical bus segments plus an auxiliary (AUX) port. Each segment is an independent electrical connection to a PROFIBUS cable. You can enable or disable individual segments, control their bus termination resistors, and check their lock status. This is particularly useful in redundant or multi-segment network topologies.
Enable/Disable Segment
To enable or disable a specific bus segment, call naibrd_PB_EnableSegmentForUse(). A disabled segment is electrically disconnected from the bus.
status = naibrd_PB_EnableSegmentForUse(inputPBConfig.cardIndex, inputPBConfig.module, segment, enable);
Parameters:
-
segment— segment number (1—8) or0xFF(255) for the AUX port. -
enable—TRUEto enable,FALSEto disable.
Set Termination for Segments
PROFIBUS requires proper bus termination at both physical ends of each segment. The PB1 module can apply termination resistors in software. To enable or disable termination on a segment, you read the current termination register, modify the bit for the target segment, and write the register back.
uint32_t terminationEnableRegVal;
/* Read current termination state */
status = naibrd_PB_GetTerminationEnableForSegments(inputPBConfig.cardIndex, inputPBConfig.module,
&terminationEnableRegVal);
/* Enable termination on segment 1 (bit 0) */
terminationEnableRegVal |= 0x01;
/* Write updated termination state */
status = naibrd_PB_SetTerminationEnableForSegments(inputPBConfig.cardIndex, inputPBConfig.module,
terminationEnableRegVal);
The bit mapping is: bit 0 = segment 1, bit 1 = segment 2, … bit 7 = segment 8, bit 8 = AUX port. Set a bit to enable termination, clear it to disable.
Get Lock Status for Segments
To check whether segments are locked (in use and not available for reconfiguration), call naibrd_PB_GetLockStatusForSegments(). The returned register uses the same bit mapping as the termination register.
uint32_t lockStatusRegValue;
status = naibrd_PB_GetLockStatusForSegments(inputPBConfig.cardIndex, inputPBConfig.module, &lockStatusRegValue);
A set bit indicates the segment is locked. A locked segment is actively in use for PROFIBUS communication. Do not disable or reconfigure a locked segment without first transitioning the master to Offline.
|
Important
|
Common Errors
|
System Time
PROFIBUS supports distributing a synchronized time across the network. The master can broadcast a time value to all slaves that support the PROFIBUS time synchronization service.
Set System Time
To set the PROFIBUS system time and broadcast it to the network, call naibrd_PB_SetSystemTime(). The time is specified as a Unix-epoch seconds value plus nanoseconds for sub-second precision. The clock status word controls time zone offset, daylight saving time flags, time validity, and clock resolution.
uint32_t clockStatus = 0x00; /* See naibrd_pb.h for valid combinations */
uint32_t sysTimeSeconds = 1609459200; /* Seconds since 1970-01-01 */
uint32_t sysTimeNanoSeconds = 0;
status = naibrd_PB_SetSystemTime(inputPBConfig.cardIndex, inputPBConfig.module,
clockStatus, sysTimeSeconds, sysTimeNanoSeconds);
Clock status flags (high byte — time zone correction):
-
NAIBRD_PB_DPM_TIME_CORRECTION_POS/NAIBRD_PB_DPM_TIME_CORRECTION_NEG— positive or negative UTC offset. -
NAIBRD_PB_DPM_TIME_CORRECTION_HOUR_*— time zone offset in 30-minute increments (e.g.,_HOUR_5_0for UTC+5).
Clock status flags (low byte — time attributes):
-
NAIBRD_PB_DPM_TIME_IS_VALID/NAIBRD_PB_DPM_TIME_IS_INVALID— whether the time source is considered valid. -
NAIBRD_PB_DPM_TIME_IS_SUMMER_TIME/NAIBRD_PB_DPM_TIME_IS_WINTER_TIME— daylight saving time indicator. -
NAIBRD_PB_DPM_TIME_CLOCK_RESOLUTION_*— clock resolution (1ms, 10ms, 100ms, or 1s). -
NAIBRD_PB_DPM_TIME_SYNC_OK/NAIBRD_PB_DPM_TIME_SYNC_FAILED— whether time synchronization is active.
Combine flags with bitwise OR. For example, UTC-5 with valid time at 1ms resolution in winter: NAIBRD_PB_DPM_TIME_CORRECTION_NEG | NAIBRD_PB_DPM_TIME_CORRECTION_HOUR_5_0 | NAIBRD_PB_DPM_TIME_IS_VALID | NAIBRD_PB_DPM_TIME_CLOCK_RESOLUTION_1MS | NAIBRD_PB_DPM_TIME_SYNC_OK.
|
Important
|
Common Errors
|
PB-Specific Error Handling
Many PROFIBUS operations can return NAI_ERROR_FUNCTION_SPECIFIC_ERROR as the general status. When this occurs, the actual PROFIBUS-level error code is stored separately and can be retrieved with naibrd_PB_GetLastFunctionCallStatus().
if (status == NAI_ERROR_FUNCTION_SPECIFIC_ERROR)
{
int32_t pbStatus;
status = naibrd_PB_GetLastFunctionCallStatus(inputPBConfig.cardIndex, inputPBConfig.module, &pbStatus);
/* Interpret pbStatus using the NAI_PB_* error codes */
}
PB-specific error codes:
| Error Code | Meaning |
|---|---|
|
Operation completed successfully. |
|
Internal PROFIBUS stack error. |
|
The specified channel does not exist. |
|
The master is offline and cannot perform this operation. |
|
A previous asynchronous request has not completed. |
|
A string buffer was too small. |
|
The operation timed out waiting for a response. |
|
A data array exceeded its maximum size. |
|
An invalid parameter value was passed. |
|
The module is busy processing another command. |
In your own application, always check the return status of every naibrd_PB_*() call. If the status is NAI_ERROR_FUNCTION_SPECIFIC_ERROR, call naibrd_PB_GetLastFunctionCallStatus() to obtain the PB-level error code for more detailed diagnostics.
Troubleshooting Reference
|
Note
|
This section summarizes errors covered in preceding sections and in the PB module manual. Consult the module manual for hardware-specific diagnostics. |
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found |
Board is powered off or not physically connected. Configuration file has wrong interface or address. |
Verify power and physical connections. Re-run the board menu to reconfigure. |
Connection timeout |
Network misconfiguration, firewall, or IP mismatch (Ethernet). Bus configuration error (PCI/PCIe). |
Check network settings, firewall rules, and bus configuration. |
Module not present at selected slot |
The selected module slot does not contain a PB1 module. |
Use the board menu to verify which slots are populated. |
|
Attempted an operation that requires the master to be online (Stop, Clear, or Operate) while it is in the Offline state. |
Transition the master through the state machine: Offline → Stop → Clear → Operate. |
|
Slave did not respond within the configured timeout. Network may be disconnected, slave may be powered off, or bus parameters (tSlot) may be too short. |
Verify slave power and cabling. Increase tSlot or maxTsdr. Check termination at both ends of the segment. |
|
A previous asynchronous operation (live list scan, acyclic service) has not completed. |
Wait for the previous operation to finish before issuing a new request. |
|
The PB module processor is busy handling another command. |
Retry after a short delay. If persistent, check CPU load — the bus configuration may be too demanding. |
|
A parameter value is outside its valid range. |
Check the valid ranges documented in |
Master state shows AUTOCLEAR |
A configured slave stopped responding during Operate mode. |
Check the failing slave’s connection status and diagnostics. Fix the issue and transition back to Operate. |
Master state shows DOUBLE_ADDRESS_ERROR |
Two devices on the bus have the same station address. |
Assign unique addresses to each device. Use the live list to identify conflicts. |
Live list shows no stations |
Master is in Offline state or bus is not properly terminated/connected. |
Transition to at least Stop state. Verify cabling and termination. |
CPU load consistently above 90% |
Too many slaves, baud rate too low, or cycle time too short. |
Increase target rotation time (tTr), reduce slave count, or increase baud rate. |
Bus communication fails intermittently |
Improper termination, long cable runs, EMI interference, or marginal bus timing parameters. |
Verify termination at both physical ends of each segment. Check cable quality and length against PROFIBUS specifications for the configured baud rate. |
Writes to slaves have no effect |
Master is in Clear state (outputs forced to zero) or slave is not in data exchange. |
Verify master is in Operate state. Check connection status for the target slave. |
|
A PROFIBUS-level error occurred. The general status code does not carry the detail. |
Call |
Full Source
Full Source — PB_BasicOps.c (SSK 1.x)
/**************************************************************************************************************/
/**
* <summary>
* The purpose of the PB_BasicOps is to illustrate the methods to call in the library to perform basic profibus
* operations.
* </summary>
*/
/**************************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.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_pb.h"
/**********************/
/* Application Name */
/**********************/
static const int8_t *CONFIG_FILE = (const int8_t *)"default_PBBasicOps.txt";
#define NAI_TRUE (1)
#define NAI_FALSE (0)
typedef struct
{
int32_t cardIndex;
int32_t module;
uint32_t modId;
} PBConfig;
PBConfig inputPBConfig;
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t naiapp_Run_PB_BasicOps(void);
static void printMasterState(NAIBRD_PB_DPM_MASTER_STATE masterState);
static void printOperationMode(NAIBRD_PB_DPM_OPERATION_MODE operationMode);
static void naibrd_PB_PrintPBStatus(int32_t pbStatus);
bool_t EXEC_naibrd_PB_GetMS0ConnectionStatus();
bool_t EXEC_naibrd_PB_ResetMS0ConnectionCounters();
bool_t EXEC_naibrd_PB_GetAlarmCounters();
bool_t EXEC_naibrd_PB_ResetAlarmCounters();
bool_t EXEC_naibrd_PB_GetLastAlarmData();
bool_t EXEC_naibrd_PB_GetSlaveDiagnostics();
bool_t EXEC_naibrd_PB_SetandEnableMaxCycleCounter();
bool_t EXEC_naibrd_PB_GetCPULoad();
bool_t EXEC_naibrd_PB_StartReconfiguration();
bool_t EXEC_naibrd_PB_SetSystemTime();
#if defined (_FUTURE_CAPABILITY)
bool_t EXEC_naibrd_PB_GetSystemTime();
bool_t EXEC_naibrd_PB_EnableRedundancy();
#endif
bool_t EXEC_naibrd_PB_GetLiveList();
bool_t EXEC_naibrd_PB_BusParamReconfiguration();
bool_t EXEC_naibrd_PB_GetOperationMode();
bool_t EXEC_naibrd_PB_SetPollCycleMode();
bool_t EXEC_naibrd_PB_ReadIOData();
bool_t EXEC_naibrd_PB_GetStatistics();
bool_t EXEC_naibrd_PB_SetNewIOConfig();
bool_t EXEC_naibrd_PB_GetPSAKVersion();
bool_t EXEC_naibrd_PB_WriteIOData();
bool_t EXEC_naibrd_PB_SetDynamicBusParams();
bool_t EXEC_naibrd_PB_SetBusParams();
bool_t EXEC_naibrd_PB_TestSegment();
bool_t EXEC_naibrd_PB_TestTermination();
bool_t EXEC_naibrd_PB_SetOffline();
bool_t EXEC_naibrd_PB_SetStop();
bool_t EXEC_naibrd_PB_SetClear();
bool_t EXEC_naibrd_PB_SetOperate();
bool_t EXEC_naibrd_PB_AcyclicRead();
bool_t EXEC_naibrd_PB_AcyclicWrite();
bool_t EXEC_naibrd_PB_InitiateCommunication();
bool_t EXEC_naibrd_PB_AbortCommunication();
bool_t EXEC_naibrd_PB_GetLockStatusForSegments();
/**************************************************************************************************************/
/**
* <summary>
*
* The main routine assists in gaining access to the board.
*
* The following routines from the nai_sys_cfg.c file are
* called to assist with accessing and configuring the board.
*
* - ConfigDevice
* - DisplayDeviceCfg
* - GetBoardSNModCfg
* - CheckModule
*
* </summary>
*/
/***************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t PB_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t moduleCnt;
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, &inputPBConfig.cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(inputPBConfig.cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &inputPBConfig.module);
if (stop != TRUE)
{
inputPBConfig.modId = naibrd_GetModuleID(inputPBConfig.cardIndex, inputPBConfig.module);
if ((inputPBConfig.modId != 0))
{
naiapp_Run_PB_BasicOps();
}
}
}
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;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetMS0ConnectionStatus */
bool_t EXEC_naibrd_PB_GetMS0ConnectionStatus()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetMS0ConnectionStatus\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_CONNECTION_STATUS connectionStatus;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetMS0ConnectionStatus(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &connectionStatus);
if (status == NAI_SUCCESS)
{
printf("Cyclic Connection Status for Slave Address %d: \n", slaveAddr);
printf("Is Slave in Data Exchange = %d\n", connectionStatus.isSlaveInDataExchange);
printf("Number of Restarts = %d\n", connectionStatus.numberOfRestarts);
printf("Missing Response Count = %d\n", connectionStatus.missingResponseCount);
printf("Invalid Response Count = %d\n", connectionStatus.invalidResponseCount);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetMS0ConnectionStatus - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_ResetMS0ConnectionCounters */
bool_t EXEC_naibrd_PB_ResetMS0ConnectionCounters()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("ResetMS0ConnectionCounters\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_ResetMS0ConnectionCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr);
if (status == NAI_SUCCESS)
{
printf("Reset Ms0 Connection Counters - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_ResetMS0ConnectionStatus - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetAlarmCounters */
bool_t EXEC_naibrd_PB_GetAlarmCounters()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetAlarmCounters\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_ALARM_COUNTERS alarmCounters;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetAlarmCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &alarmCounters);
if (status == NAI_SUCCESS)
{
printf("Alarm Counters for Slave Address %d: \n", slaveAddr);
printf("Number Diagnostic Alarms = %d\n", alarmCounters.numberDiagAlarms);
printf("Number Process Alarms = %d\n", alarmCounters.numberProcessAlarms);
printf("Number Pull Alarms = %d\n", alarmCounters.numberPullAlarms);
printf("Number Status Alarms = %d\n", alarmCounters.numberStatusAlarms);
printf("Number Update Alarms = %d\n", alarmCounters.numberUpdateAlarms);
printf("Number Manufacturer Alarms = %d\n", alarmCounters.numberManufacturerAlarms);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetAlarmCounters - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_ResetAlarmCounters */
bool_t EXEC_naibrd_PB_ResetAlarmCounters()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("ResetAlarmCounters\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_ResetAlarmCounters(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr);
if (status == NAI_SUCCESS)
{
printf("Reset Alarm Counters - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_ResetAlarmCounters - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetLastAlarmData */
bool_t EXEC_naibrd_PB_GetLastAlarmData()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetLastAlarmData\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_ALARM_DATA lastAlarmData;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetLastAlarmData(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &lastAlarmData);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("naibrd_PB_GetLastAlarmData - Success\n");
printf("BlockLength = %d\n", lastAlarmData.blockLength);
printf("Type = %d\n", lastAlarmData.type);
printf("SlotNumber = %d\n", lastAlarmData.slotNumber);
printf("Specifier = %d\n", lastAlarmData.specifier);
printf("Diagnostic User Data Count = %d\n", lastAlarmData.diagnosticUserDataCount);
for (i = 0; i < lastAlarmData.diagnosticUserDataCount; i++)
{
printf("DiagnosticUserDataArray[%d] = %dn", i, lastAlarmData.diagnosticUserDataArray[i]);
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetLastAlarmData - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetSlaveDiagnostics */
bool_t EXEC_naibrd_PB_GetSlaveDiagnostics()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetSlaveDiagnostics\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
NAIBRD_PB_SLAVE_DIAGNOSTICS slaveDiagnostics;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
status = naibrd_PB_GetSlaveDiagnostics(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, &slaveDiagnostics);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("Slave Diagnostic Data for Slave = 0x%x\n", slaveAddr);
printf("StationStatus1 = 0x%x\nStationStatus2 = 0x%x\nStationStatus3 = 0x%x\n", slaveDiagnostics.stationStatus1,
slaveDiagnostics.stationStatus2, slaveDiagnostics.stationStatus3);
printf("Master Address = 0x%x\nIdentity Number High Byte = 0x%x\nIdentity Number Low Byte = 0x%x\n",
slaveDiagnostics.masterAddr, slaveDiagnostics.identityNumberHigh, slaveDiagnostics.identityNumberLow);
if (slaveDiagnostics.lengthOfExtraDiagData > 0)
{
printf("\nExtra Diagnostic Data was Found!\n");
for (i = 0; i < slaveDiagnostics.lengthOfExtraDiagData; i++)
{
printf("0x%x ", slaveDiagnostics.extraDiagDataArray[i]);
}
printf("\n\n");
}
else
{
printf("No extra diagnostic data was found!\n");
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetSlaveDiagnostics - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetandEnableMaxCycleCounter */
bool_t EXEC_naibrd_PB_SetandEnableMaxCycleCounter()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetandEnableMaxCycleCounter\n");
printf("-------------------------------------------------\n");
printf("\nEnter Max Cycle Count prior to channel going offline: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxCycleCount = 0;
naiapp_query_NumberFromResponse(&maxCycleCount, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetAndEnableMaxCycleCounter(inputPBConfig.cardIndex, inputPBConfig.module, maxCycleCount);
if (status == NAI_SUCCESS)
{
printf("Set And Enable Max Cycle Count - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetAndEnableMaxCycleCounter - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetCPULoad */
bool_t EXEC_naibrd_PB_GetCPULoad()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
NAIBRD_PB_CPU_LOAD cpuLoad;
printf("-------------------------------------------------\n");
printf("GetCPULoad\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetCPULoad(inputPBConfig.cardIndex, inputPBConfig.module, &cpuLoad);
if (status == NAI_SUCCESS)
{
printf("CPU Load:\n");
printf("Last 100ms = %d%%\n", cpuLoad.last100ms);
printf("Last 1s = %d%%\n", cpuLoad.last1s);
printf("Last 10s = %d%%\n", cpuLoad.last10s);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetCPULoad - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_StartReconfiguration */
bool_t EXEC_naibrd_PB_StartReconfiguration()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("StartReconfiguration\n");
printf("-------------------------------------------------\n");
printf("\nEnter 1 to enable Start Reconfiguration or 0 to disable Start Reconfiguration: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t startReconfig = 0;
naiapp_query_NumberFromResponse(&startReconfig, inputBuffer, inputResponseCnt);
status = naibrd_PB_StartReconfiguration(inputPBConfig.cardIndex, inputPBConfig.module, startReconfig);
if (status == NAI_SUCCESS)
{
printf("Start Reconfiguration - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_StartReconfiguration - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetSystemTime */
bool_t EXEC_naibrd_PB_SetSystemTime()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetSystemTime\n");
printf("-------------------------------------------------\n");
printf("\nEnter Clock Status: (see naibrd_pb.h for valid combinations of High and Low bytes) ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
uint32_t clockStatus = 0;
naiapp_query_UnsignedNumberFromResponse(&clockStatus, inputBuffer, inputResponseCnt);
printf("\nEnter Seconds since 1970: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
uint32_t sysTimeSeconds = 0;
naiapp_query_UnsignedNumberFromResponse(&sysTimeSeconds, inputBuffer, inputResponseCnt);
printf("\nEnter Nano Seconds: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
uint32_t sysTimeNanoSeconds = 0;
naiapp_query_UnsignedNumberFromResponse(&sysTimeNanoSeconds, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetSystemTime(inputPBConfig.cardIndex, inputPBConfig.module, clockStatus, sysTimeSeconds, sysTimeNanoSeconds);
if (status == NAI_SUCCESS)
{
printf("Set System Time - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetSystemTime - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetLiveList */
bool_t EXEC_naibrd_PB_GetLiveList()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("GetLiveList\n");
printf("-------------------------------------------------\n");
printf("\nEnter 1 to make request to collect data or 0 to display data already collected: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t makeRequest = 0;
naiapp_query_NumberFromResponse(&makeRequest, inputBuffer, inputResponseCnt);
if (makeRequest)
{
status = naibrd_PB_KickoffGetLiveList(inputPBConfig.cardIndex, inputPBConfig.module);
if (status == NAI_SUCCESS)
{
printf("Kickoff Get Live List - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_KickoffGetLiveList - Status = %d\n", status);
}
}
else /* Interested in collected results */
{
NAIBRD_PB_LIVELIST_RESULTS liveListResults;
status = naibrd_PB_GetLiveListResults(inputPBConfig.cardIndex, inputPBConfig.module, &liveListResults);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("Get Live List Results - Success\n");
for (i = 0; i < liveListResults.passiveStationCount; i++)
{
printf("Found PASSIVE Station %d\n", liveListResults.passiveStations[i]);
}
for (i = 0; i < liveListResults.activeStationCount; i++)
{
printf("Found ACTIVE Station %d\n", liveListResults.activeStations[i]);
}
printf("\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetLiveListResults - Status = %d\n", status);
if (status == NAI_ERROR_FUNCTION_SPECIFIC_ERROR)
{
int32_t pbStatus;
status = naibrd_PB_GetLastFunctionCallStatus(inputPBConfig.cardIndex, inputPBConfig.module, &pbStatus);
naibrd_PB_PrintPBStatus(pbStatus);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_BusParamReconfiguration */
bool_t EXEC_naibrd_PB_BusParamReconfiguration()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("BusParamReconfiguration\n");
printf("-------------------------------------------------\n");
printf("\nEnter 0 to reconfigure Master Address\nEnter 1 to reconfigure Hsa\nEnter 2 to reconfigure Min Slave Interval: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t busParam = 0;
bool_t requiresField2 = NAI_FALSE;
naiapp_query_NumberFromResponse(&busParam, inputBuffer, inputResponseCnt);
if (busParam == 0)
{
printf("\nEnter new Master Address: ");
}
else if (busParam == 1)
{
printf("\nEnter new Hsa: ");
}
else if (busParam == 2)
{
printf("\nEnter new Min Slave Interval Hi Byte: ");
requiresField2 = NAI_TRUE;
}
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t field1Value = 0;
int32_t field2Value = 0;
naiapp_query_NumberFromResponse(&field1Value, inputBuffer, inputResponseCnt);
if (requiresField2)
{
printf("\nEnter new Min Slave Interval Lo Byte: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&field2Value, inputBuffer, inputResponseCnt);
}
}
if (!bQuit)
{
status = naibrd_PB_BusParamReconfiguration(inputPBConfig.cardIndex, inputPBConfig.module, busParam, field1Value, field2Value);
if (status == NAI_SUCCESS)
{
printf("Bus Param Reconfiguration - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_BusParamReconfiguration - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetOperationMode */
bool_t EXEC_naibrd_PB_GetOperationMode()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
NAIBRD_PB_DPM_MASTER_STATE masterState;
NAIBRD_PB_DPM_OPERATION_MODE operationMode;
printf("-------------------------------------------------\n");
printf("GetOperationMode\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetOperationMode(inputPBConfig.cardIndex, inputPBConfig.module, &masterState, &operationMode);
if (status == NAI_SUCCESS)
{
printf("Get Operation Mode - Success\n");
printMasterState(masterState);
printOperationMode(operationMode);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetOperationMode - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetPollCycleMode */
bool_t EXEC_naibrd_PB_SetPollCycleMode()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetPollCycleMode\n");
printf("-------------------------------------------------\n");
printf("\nEnter 0 for ACYCLIC mode or 1 for CYCLIC mode: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t pollCycleMode = 0;
naiapp_query_NumberFromResponse(&pollCycleMode, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetPollCycleMode(inputPBConfig.cardIndex, inputPBConfig.module, pollCycleMode);
if (status == NAI_SUCCESS)
{
printf("Set Poll Cycle Mode - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetPollCycleMode - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_ReadIOData */
bool_t EXEC_naibrd_PB_ReadIOData()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("ReadIOData\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Offset into slave: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t offset = 0;
naiapp_query_NumberFromResponse(&offset, inputBuffer, inputResponseCnt);
printf("\nPlease enter Number of Bytes to Read: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t readCount = 0;
int8_t data[NAIBRD_PB_MAX_PDU_LENGTH];
naiapp_query_NumberFromResponse(&readCount, inputBuffer, inputResponseCnt);
status = naibrd_PB_ReadIOData(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, offset, readCount, &(data[0]));
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("Read IO Data - Success\n");
printf("IO Data:\n");
for (i = 0; i < readCount; i++)
{
printf("0x%02x ", (data[i] & 0xFF));
}
printf("\n\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_ReadIOData - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetStatistics */
bool_t EXEC_naibrd_PB_GetStatistics()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
NAIBRD_PB_STATISTICS statistics;
printf("-------------------------------------------------\n");
printf("GetStatistics\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetStatistics(inputPBConfig.cardIndex, inputPBConfig.module, &statistics);
if (status == NAI_SUCCESS)
{
int32_t i = 0;
printf("naibrd_PB_GetStatistics - Success\n");
printf("NumMasterStations = %d\n", statistics.numMasterStations);
printf("Master Active Stations:\n");
for (i = 0; i < statistics.numMasterStations; i++)
{
printf("%d\n", statistics.masterStationsArray[i]);
}
printf("\n");
printf("NumSlaveStations = %d\n", statistics.numSlaveStations);
printf("Slave Active Stations:\n");
for (i = 0; i < statistics.numSlaveStations; i++)
{
printf("%d\n", statistics.slaveStationsArray[i]);
}
printf("\n");
printf("Bus Parameters:\n");
printf("\tStation Address:\t%d\n", statistics.stationAddress);
printf("\tBaudrate:\t%d\n", statistics.baudRate);
printf("\tTIdle1:\t\t%d\n", statistics.tIdle1);
printf("\tTIdle2:\t\t%d\n", statistics.tIdle2);
printf("\tTSlot:\t\t%d\n", statistics.tSlot);
printf("\tTtr:\t\t%d\n", statistics.tTr);
printf("\tMinSlaveInterval:\t\t%d\n", statistics.minSlaveInterval);
printf("\tMaxAcyclicServicesPerPollCycle:\t%d\n", statistics.maxAcyclicServicesPerPollCycle);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetStatistics - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetNewIOConfig */
bool_t EXEC_naibrd_PB_SetNewIOConfig()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetNewIOConfig\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
int32_t cfgDataLength = 0;
int8_t cfgData[NAIBRD_PB_MAX_CFG_DATA_LENGTH];
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter number of bytes of configuration (1 - %d): ", NAIBRD_PB_MAX_CFG_DATA_LENGTH);
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t i = 0;
naiapp_query_NumberFromResponse(&cfgDataLength, inputBuffer, inputResponseCnt);
/* Now prompt for data to be written */
printf("\nPlease enter configuration data in the form of 0x00");
for (i = 0; i < cfgDataLength; i++)
{
printf("\ncfgData[%d]: ", i);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit)
{
break;
}
cfgData[i] = (int8_t)strtol((char*)inputBuffer, NULL, 16);
}
if (!bQuit)
{
status = naibrd_PB_SetNewIOConfig(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, cfgDataLength, &(cfgData[0]));
if (status == NAI_SUCCESS)
{
printf("Set New IO Config - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetNewIOConfig - Status = %d\n", status);
if (status == NAI_ERROR_FUNCTION_SPECIFIC_ERROR)
{
int32_t pbStatus = NAI_PB_SUCCESS;
status = naibrd_PB_GetLastFunctionCallStatus(inputPBConfig.cardIndex, inputPBConfig.module, &pbStatus);
if (status == NAI_SUCCESS)
{
printf("PB Specific Status = %d\n", pbStatus);
}
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetPSAKVersion */
bool_t EXEC_naibrd_PB_GetPSAKVersion()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
char firmwareVersion[NAIBRD_PB_VERSION_MAX_LENGTH];
char psakVersion[NAIBRD_PB_VERSION_MAX_LENGTH];
printf("-------------------------------------------------\n");
printf("GetPSAKVersion\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetPSAKVersion(inputPBConfig.cardIndex, inputPBConfig.module, NAIBRD_PB_VERSION_MAX_LENGTH, &(firmwareVersion[0]),
NAIBRD_PB_VERSION_MAX_LENGTH, &(psakVersion[0]));
if (status == NAI_SUCCESS)
{
printf("Get PSAK Version - Success\n");
printf("Firmware Version = %s\n", firmwareVersion);
printf("PSAK Version = %s\n", psakVersion);
}
else
{
printf("ERROR Trying to execute naibrd_PB_GetPSAKVersion - Status = %d\n", status);
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_WriteIOData */
bool_t EXEC_naibrd_PB_WriteIOData()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("WriteIOData\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Offset into slave: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t offset = 0;
int8_t bytesToWrite[2];
int32_t numBytesToWrite = 0;
naiapp_query_NumberFromResponse(&offset, inputBuffer, inputResponseCnt);
printf("\nPlease enter number of bytes to be written: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t i = 0;
naiapp_query_NumberFromResponse(&numBytesToWrite, inputBuffer, inputResponseCnt);
/* Now prompt for data to be written */
printf("\nPlease enter data in the form of 0x00");
for (i = 0; i < numBytesToWrite; i++)
{
printf("\nData[%d]: ", i);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit)
{
break;
}
bytesToWrite[i] = (int8_t)strtol((char*)inputBuffer, NULL, 16);
}
if (!bQuit)
{
status = naibrd_PB_WriteIOData(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, offset, numBytesToWrite,
bytesToWrite);
if (status == NAI_SUCCESS)
{
printf("Write IO Data - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_WriteIOData - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetDynamicBusParams */
bool_t EXEC_naibrd_PB_SetDynamicBusParams()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetDynamicBusParams\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter StationAddress: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t stationAddr = 0;
naiapp_query_NumberFromResponse(&stationAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Retry Limit: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxRetryLimit = 0;
naiapp_query_NumberFromResponse(&maxRetryLimit, inputBuffer, inputResponseCnt);
printf("\nPlease enter TSlot: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t tSlot = 0;
naiapp_query_NumberFromResponse(&tSlot, inputBuffer, inputResponseCnt);
printf("\nPlease enter MaxTSDR: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxTsdr = 0;
naiapp_query_NumberFromResponse(&maxTsdr, inputBuffer, inputResponseCnt);
status = naibrd_PB_SetDynamicBusParams(inputPBConfig.cardIndex, inputPBConfig.module, stationAddr, maxRetryLimit, tSlot,
maxTsdr);
if (status == NAI_SUCCESS)
{
printf("Set Dynamic Bus Params - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetDynamicBusParams - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetBusParams */
bool_t EXEC_naibrd_PB_SetBusParams()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetBusParams\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter tSlot (Slot time - max time master has to wait for 1st byte of response or frame from token receiver after\
a token exchange) Valid values (37 - 16383): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
NAIBRD_PB_BUS_PARAMS busParams;
naiapp_query_NumberFromResponse(&(busParams.tSlot), inputBuffer, inputResponseCnt);
printf("\nPlease enter Min Tsdr (Min time delay of the slave processing a request to sending the response) Valid values \
(11 - 1023): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.minTsdr), inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Tsdr (Max time delay of the slave processing a request to sending the response) Valid values \
(37 - 65535): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.maxTsdr), inputBuffer, inputResponseCnt);
printf("\nPlease enter Baudrate: (Valid values defined in naibrd_pb.h): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.baudrate), inputBuffer, inputResponseCnt);
printf("\nPlease enter TQui (Quiet Time is the time during which the PB control logic has to close its sender and \
its receiver) Valid values (0 - 493): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tQui), inputBuffer, inputResponseCnt);
printf("\nPlease enter TSet (Setup Time - indicates the latency of the data link layer) Valid values (1 - 494): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tSet), inputBuffer, inputResponseCnt);
printf("\nPlease enter TtrHigh (Target Rotation Time - the maximum permissible rotation time of a token in the \
PB network) Valid values (256 - 16776960): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tTrHi), inputBuffer, inputResponseCnt);
printf("\nPlease enter TtrLow (Target Rotation Time - the maximum permissible rotation time of a token in \
the PB network) Valid values (256 - 16776960): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.tTrLow), inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Retry Limit (Maximum number of frame repititions indicates how often the \
master repeats a request, after the end of the slot time, before it designates the responder as \
not available) Valid values (0 - 7): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(busParams.maxRetryLimit), inputBuffer, inputResponseCnt);
status = naibrd_PB_SetBusParams(inputPBConfig.cardIndex, inputPBConfig.module, &busParams);
if (status == NAI_SUCCESS)
{
printf("Set Dynamic Bus Params - Success\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetBusParams - Status = %d\n", status);
}
}
}
}
}
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_TestSegment */
bool_t EXEC_naibrd_PB_TestSegment()
{
bool_t bQuit = NAI_FALSE;
bool_t enable = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int32_t segment = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("TestSegment\n");
printf("-------------------------------------------------\n");
printf("2 Parameters Required to Execute naibrd_PB_EnableSegmentForUse\n");
printf("\nPlease enter Segment to test. Valid values (1 - 8) and 255 for Aux port: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&segment, inputBuffer, inputResponseCnt);
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' to Enable Segment or 'N' to Disable the Segment",
(int8_t *)"Invalid value detected for Enable",
NAI_FALSE, &enable);
if (!bQuit)
{
status = naibrd_PB_EnableSegmentForUse(inputPBConfig.cardIndex, inputPBConfig.module, segment, enable);
if (status == NAI_SUCCESS)
{
if (enable)
{
printf("Segment %d is now Enabled!\n", segment);
}
else
{
printf("Segment %d is now Disabled!\n", segment);
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_EnableSegmentForUse - Status = %d\n", status);
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_TestTermination */
bool_t EXEC_naibrd_PB_TestTermination()
{
bool_t bQuit = NAI_FALSE;
bool_t enable = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int32_t segment = 0;
uint32_t terminationEnableRegVal = 0;
uint32_t segmentTermination = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("TestTermination\n");
printf("-------------------------------------------------\n");
printf("2 Parameters Required to Execute naibrd_PB_SetTerminationEnableForSegments\n");
printf("\nPlease enter Segment to test termination. Valid values (1 - 8) and 255 for Aux port: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&segment, inputBuffer, inputResponseCnt);
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' to Enable Termination or 'N' to Disable Termination",
(int8_t *)"Invalid value detected for Enable",
NAI_FALSE, &enable);
if (!bQuit)
{
status = naibrd_PB_GetTerminationEnableForSegments(inputPBConfig.cardIndex, inputPBConfig.module, &terminationEnableRegVal);
if (status == NAI_SUCCESS)
{
printf("\nCurrent value of Termination Enable register before granting request: 0x%x\n", terminationEnableRegVal);
switch (segment)
{
case SEGMENT_1:
segmentTermination = 0x01;
break;
case SEGMENT_2:
segmentTermination = 0x02;
break;
case SEGMENT_3:
segmentTermination = 0x04;
break;
case SEGMENT_4:
segmentTermination = 0x08;
break;
case SEGMENT_5:
segmentTermination = 0x10;
break;
case SEGMENT_6:
segmentTermination = 0x20;
break;
case SEGMENT_7:
segmentTermination = 0x40;
break;
case SEGMENT_8:
segmentTermination = 0x80;
break;
case SEGMENT_AUX:
segmentTermination = 0x0100;
break;
default:
status = NAI_ERROR_INVALID_RANGE;
break;
}
if (status == NAI_SUCCESS)
{
if (enable)
{
terminationEnableRegVal |= segmentTermination;
}
else
{
terminationEnableRegVal &= (~segmentTermination);
}
status = naibrd_PB_SetTerminationEnableForSegments(inputPBConfig.cardIndex, inputPBConfig.module, terminationEnableRegVal);
if (status == NAI_SUCCESS)
{
printf("New value of Termination Enable register after granting request: 0x%x\n", terminationEnableRegVal);
if (enable)
{
printf("Segment %d is now Terminated!\n", segment);
}
else
{
printf("Segment %d is now NOT Terminated!\n", segment);
}
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetTerminationEnableForSegments - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetOffline */
bool_t EXEC_naibrd_PB_SetOffline()
{
bool_t bQuit = NAI_FALSE;
bool_t redMode = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetOffline\n");
printf("-------------------------------------------------\n");
printf("1 Parameter Required to Execute naibrd_PB_SetOffline\n");
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' for Redundancy Mode or 'N' for Normal", (int8_t *)"Invalid value detected for Redundancy Mode",
NAI_FALSE, &redMode);
if (!bQuit)
{
status = naibrd_PB_SetOffline(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED OFFLINE. Please Confirm bus light is off for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetOffline - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetStop */
bool_t EXEC_naibrd_PB_SetStop()
{
nai_status_t status = NAI_SUCCESS;
printf("-------------------------------------------------\n");
printf("SetStop\n");
printf("-------------------------------------------------\n");
printf("No Parameters Required to Execute naibrd_PB_SetStop\n");
status = naibrd_PB_SetStop(inputPBConfig.cardIndex, inputPBConfig.module);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED TO STOP. Please Confirm bus light is on for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetStop - Status = %d\n", status);
}
return NAI_FALSE;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetClear */
bool_t EXEC_naibrd_PB_SetClear()
{
bool_t bQuit = NAI_FALSE;
bool_t redMode = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetClear\n");
printf("-------------------------------------------------\n");
printf("1 Parameter Required to Execute naibrd_PB_SetClear\n");
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' for Redundancy Mode or 'N' for Normal",
(int8_t *)"Invalid value detected for Redundancy Mode", NAI_FALSE, &redMode);
if (!bQuit)
{
status = naibrd_PB_SetClear(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED TO CLEAR. Please Confirm bus light is on for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetClear - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_SetOperate */
bool_t EXEC_naibrd_PB_SetOperate()
{
bool_t bQuit = NAI_FALSE;
bool_t redMode = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("SetOperate\n");
printf("-------------------------------------------------\n");
printf("1 Parameter Required to Execute naibrd_PB_SetOperate\n");
bQuit = naiapp_query_ForBinaryResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt,
(int8_t *)"Please type 'Y' for Redundancy Mode or 'N' for Normal", (int8_t *)"Invalid value detected for Redundancy Mode",
NAI_FALSE, &redMode);
if (!bQuit)
{
status = naibrd_PB_SetOperate(inputPBConfig.cardIndex, inputPBConfig.module, (redMode) ? 1 : 0);
if (status == NAI_SUCCESS)
{
printf("BUS WAS COMMANDED TO OPERATE. Please Confirm bus light is on for slave device\n");
}
else
{
printf("ERROR Trying to execute naibrd_PB_SetOperate - Status = %d\n", status);
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_AcyclicRead */
bool_t EXEC_naibrd_PB_AcyclicRead()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("AcyclicRead\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Slot Number: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slotNumber = 0;
naiapp_query_NumberFromResponse(&slotNumber, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Index: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t paramIndex = 0;
naiapp_query_NumberFromResponse(¶mIndex, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Data Length: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t paramDataLength = 0;
int8_t data[NAIBRD_PB_MAX_CFG_DATA_LENGTH];
int32_t dataReadCount = 0;
naiapp_query_NumberFromResponse(¶mDataLength, inputBuffer, inputResponseCnt);
status = naibrd_PB_AcyclicRead(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, slotNumber, paramIndex,
paramDataLength, &dataReadCount, &(data[0]));
if (status == NAI_SUCCESS)
{
int i = 0;
printf("naibrd_PB_AcyclicRead - Success\n");
printf("Acyclic Read Data:\n");
for (i = 0; i < dataReadCount; i++)
{
printf("0x%02x ", (data[i] & 0xFF));
}
printf("\n\n");
}
else
{
printf("ERROR naibrd_PB_AcyclicRead - Status = %d\n", status);
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_AcyclicWrite */
bool_t EXEC_naibrd_PB_AcyclicWrite()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("AcyclicWrite\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Slot Number: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slotNumber = 0;
naiapp_query_NumberFromResponse(&slotNumber, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Index: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t paramIndex = 0;
naiapp_query_NumberFromResponse(¶mIndex, inputBuffer, inputResponseCnt);
printf("\nPlease enter Param Data Length: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t i = 0;
int32_t paramDataLength = 0;
int32_t paramData[NAIBRD_PB_MAX_CMD_PARAMS];
naiapp_query_NumberFromResponse(¶mDataLength, inputBuffer, inputResponseCnt);
for (i = 0; i < paramDataLength; i++)
{
printf("\nEnter Value for Param Data: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
naiapp_query_NumberFromResponse(&(paramData[i]), inputBuffer, inputResponseCnt);
}
}
if (!bQuit && status == NAI_SUCCESS)
{
status = naibrd_PB_AcyclicWrite(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, slotNumber, paramIndex,
paramDataLength, &(paramData[0]));
if (status == NAI_SUCCESS)
{
printf("naibrd_PB_AcyclicRead - Success\n");
}
else
{
printf("ERROR naibrd_PB_AcyclicRead - Status = %d\n", status);
}
}
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_InitiateCommunication */
bool_t EXEC_naibrd_PB_InitiateCommunication()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("InitiateCommunication\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Comm Ref: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t commRef = 0;
naiapp_query_NumberFromResponse(&commRef, inputBuffer, inputResponseCnt);
printf("\nPlease enter Max Timeout in Milliseconds: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t maxTimeoutInMS = 0;
naiapp_query_NumberFromResponse(&maxTimeoutInMS, inputBuffer, inputResponseCnt);
status = naibrd_PB_InitiateCommunication(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, commRef, maxTimeoutInMS);
if (status == NAI_SUCCESS)
{
printf("Initiate Communication - Success\n");
}
else
{
printf("ERROR initiating communication - Status = %d\n", status);
}
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_AbortCommunication */
bool_t EXEC_naibrd_PB_AbortCommunication()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("-------------------------------------------------\n");
printf("AbortCommunication\n");
printf("-------------------------------------------------\n");
printf("\nPlease enter SlaveAddress (2 - 128): ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t slaveAddr = 0;
naiapp_query_NumberFromResponse(&slaveAddr, inputBuffer, inputResponseCnt);
printf("\nPlease enter Comm Ref: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
int32_t commRef = 0;
naiapp_query_NumberFromResponse(&commRef, inputBuffer, inputResponseCnt);
status = naibrd_PB_AbortCommunication(inputPBConfig.cardIndex, inputPBConfig.module, slaveAddr, commRef);
if (status == NAI_SUCCESS)
{
printf("Abort Communication - Success\n");
}
else
{
printf("ERROR aborting communication - Status = %d\n", status);
}
}
}
return bQuit;
}
/*****************************************************************************************************************************************/
/* Execute naibrd_PB_GetLockStatusForSegments */
bool_t EXEC_naibrd_PB_GetLockStatusForSegments()
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_SUCCESS;
uint32_t lockStatusRegValue = 0;
printf("-------------------------------------------------\n");
printf("GetLockStatusForSegment\n");
printf("-------------------------------------------------\n");
status = naibrd_PB_GetLockStatusForSegments(inputPBConfig.cardIndex, inputPBConfig.module, &lockStatusRegValue);
if (status == NAI_SUCCESS)
{
printf("Segments Lock Status = 0x%x\n", lockStatusRegValue);
if (lockStatusRegValue & 0x00000001)
printf("Segment 1 Lock Status = LOCKED\n");
else
printf("Segment 1 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000002)
printf("Segment 2 Lock Status = LOCKED\n");
else
printf("Segment 2 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000004)
printf("Segment 3 Lock Status = LOCKED\n");
else
printf("Segment 3 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000008)
printf("Segment 4 Lock Status = LOCKED\n");
else
printf("Segment 4 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000010)
printf("Segment 5 Lock Status = LOCKED\n");
else
printf("Segment 5 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000020)
printf("Segment 6 Lock Status = LOCKED\n");
else
printf("Segment 6 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000040)
printf("Segment 7 Lock Status = LOCKED\n");
else
printf("Segment 7 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000080)
printf("Segment 8 Lock Status = LOCKED\n");
else
printf("Segment 8 Lock Status = NOT LOCKED\n");
if (lockStatusRegValue & 0x00000100)
printf("Segment Aux Lock Status = LOCKED\n");
else
printf("Segment Aux Lock Status = NOT LOCKED\n");
}
else
{
printf("ERROR naibrd_PB_GetLockStatusForSegments - Status = %d\n", status);
}
return bQuit;
}
/**************************************************************************************************************/
/**
* <summary>
* naiapp_Run_PB_BasicOps illustrates...
* </summary>
*/
/**************************************************************************************************************/
static bool_t naiapp_Run_PB_BasicOps(void)
{
bool_t bQuit = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
do
{
printf("\n\n");
printf("**************************************************************************\n");
printf("* A. Execute naibrd_PB_GetMS0ConnectionStatus (Cyclic Status) *\n");
printf("* B. Execute naibrd_PB_ResetMS0ConnectionCounters (Cyclic Counters) *\n");
printf("* C. Execute naibrd_PB_GetAlarmCounters *\n");
printf("* D. Execute naibrd_PB_ResetAlarmCounters *\n");
printf("* E. Execute naibrd_PB_GetLastAlarmData *\n");
printf("* F. Execute naibrd_PB_GeSlaveDiagnostics *\n");
printf("* G. Execute naibrd_PB_SetandEnableMaxCycleCounter *\n");
printf("* H. Execute naibrd_PB_GetCPULoad *\n");
printf("* I. Execute naibrd_PB_StartReconfiguration *\n");
printf("* J. Execute naibrd_PB_SetSystemTime *\n");
#if defined (_FUTURE_CAPABILITY)
printf("* K. Execute naibrd_PB_EnableRedundancy *\n");
#else
printf("* K. *\n");
#endif
printf("* L. Execute naibrd_PB_GetLiveList *\n");
printf("* M. *\n");
printf("* N. Execute naibrd_PB_BusParamReconfiguration *\n");
printf("* O. Execute naibrd_PB_GetOperationMode *\n");
printf("* P. Execute naibrd_PB_SetPollCycleMode *\n");
printf("* Q. QUIT *\n");
printf("* R. Execute naibrd_PB_ReadIOData *\n");
printf("* S. Execute naibrd_PB_GetStatistics *\n");
printf("* T. *\n");
printf("* U. Execute naibrd_PB_SetNewIOConfig *\n");
printf("* V. Execute naibrd_PB_GetPSAKVersion *\n");
printf("* W. Execute naibrd_PB_WriteIOData *\n");
printf("* X. Execute naibrd_PB_SetDynamicBusParams *\n");
printf("* Y. Execute naibrd_PB_SetBusParams *\n");
printf("* Z. Execute naibrd_PB_SetTerminationEnableForSegments *\n");
printf("--------------------------------------------------------------------------\n");
printf("* 0. Execute naibrd_PB_EnableSegmentForUse *\n");
printf("* 1. Execute naibrd_PB_SetOffline *\n");
printf("* 2. Execute naibrd_PB_SetStop *\n");
printf("* 3. Execute naibrd_PB_SetClear *\n");
printf("* 4. Execute naibrd_PB_SetOperate *\n");
printf("* 5. Execute naibrd_PB_AcyclicRead *\n");
printf("* 6. Execute naibrd_PB_AcyclicWrite *\n");
printf("* 7. Execute naibrd_PB_InitiateCommunication *\n");
printf("* 8. Execute naibrd_PB_AbortCommunication *\n");
printf("* 9. Execute naibrd_PB_GetLockStatusForSegments *\n");
printf("**************************************************************************\n");
printf("\nPlease enter your selection: ");
memset(inputBuffer, 0x00, sizeof(inputBuffer));
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
switch (tolower(inputBuffer[0]))
{
case 'a':
bQuit = EXEC_naibrd_PB_GetMS0ConnectionStatus();
break;
case 'b':
bQuit = EXEC_naibrd_PB_ResetMS0ConnectionCounters();
break;
case 'c':
bQuit = EXEC_naibrd_PB_GetAlarmCounters();
break;
case 'd':
bQuit = EXEC_naibrd_PB_ResetAlarmCounters();
break;
case 'e':
bQuit = EXEC_naibrd_PB_GetLastAlarmData();
break;
case 'f':
bQuit = EXEC_naibrd_PB_GetSlaveDiagnostics();
break;
case 'g':
bQuit = EXEC_naibrd_PB_SetandEnableMaxCycleCounter();
break;
case 'h':
bQuit = EXEC_naibrd_PB_GetCPULoad();
break;
case 'i':
bQuit = EXEC_naibrd_PB_StartReconfiguration();
break;
case 'j':
bQuit = EXEC_naibrd_PB_SetSystemTime();
break;
case 'k':
#if defined (_FUTURE_CAPABILITY)
bQuit = EXEC_naibrd_PB_GetSystemTime();
#endif
break;
case 'l':
bQuit = EXEC_naibrd_PB_GetLiveList();
break;
case 'm':
break;
case 'n':
bQuit = EXEC_naibrd_PB_BusParamReconfiguration();
break;
case 'o':
bQuit = EXEC_naibrd_PB_GetOperationMode();
break;
case 'p':
bQuit = EXEC_naibrd_PB_SetPollCycleMode();
break;
case 'q':
bQuit = NAI_TRUE;
break;
case 'r':
bQuit = EXEC_naibrd_PB_ReadIOData();
break;
case 's':
bQuit = EXEC_naibrd_PB_GetStatistics();
break;
case 't':
break;
case 'u':
bQuit = EXEC_naibrd_PB_SetNewIOConfig();
break;
case 'v':
bQuit = EXEC_naibrd_PB_GetPSAKVersion();
break;
case 'w':
bQuit = EXEC_naibrd_PB_WriteIOData();
break;
case 'x':
bQuit = EXEC_naibrd_PB_SetDynamicBusParams();
break;
case 'y':
bQuit = EXEC_naibrd_PB_SetBusParams();
break;
case 'z':
#if defined (_FUTURE_CAPABILITY)
bQuit = EXEC_naibrd_PB_EnableRedundancy();
#endif
bQuit = EXEC_naibrd_PB_TestTermination();
break;
case '0':
bQuit = EXEC_naibrd_PB_TestSegment();
break;
case '1':
bQuit = EXEC_naibrd_PB_SetOffline();
break;
case '2':
bQuit = EXEC_naibrd_PB_SetStop();
break;
case '3':
bQuit = EXEC_naibrd_PB_SetClear();
break;
case '4':
bQuit = EXEC_naibrd_PB_SetOperate();
break;
case '5':
bQuit = EXEC_naibrd_PB_AcyclicRead();
break;
case '6':
bQuit = EXEC_naibrd_PB_AcyclicWrite();
break;
case '7':
bQuit = EXEC_naibrd_PB_InitiateCommunication();
break;
case '8':
bQuit = EXEC_naibrd_PB_AbortCommunication();
break;
case '9':
bQuit = EXEC_naibrd_PB_GetLockStatusForSegments();
break;
}
}
} while (!bQuit);
return bQuit;
}
static void printMasterState(NAIBRD_PB_DPM_MASTER_STATE masterState)
{
switch (masterState)
{
case DPM_MASTER_STATE_OK:
printf("Master state: OK\n");
break;
case DPM_MASTER_STATE_AUTOCLEAR:
printf("WARNING: Master state: AUTOCLEAR\n");
break;
case DPM_MASTER_STATE_DISTURBED_BUS_ERROR:
printf("WARNING: Master state: DISTURBED BUS ERROR\n");
break;
case DPM_MASTER_STATE_DOUBLE_ADDRESS_ERROR:
printf("WARNING: Master state: DOUBLE ADDRESS ERROR\n");
break;
case DPM_MASTER_STATE_PROTOCOL_ERROR:
printf("WARNING: Master state: PROTOCOL ERROR\n");
break;
case DPM_MASTER_STATE_HARDWARE_ERROR:
printf("WARNING: Master state: HARDWARE ERROR\n");
break;
case DPM_MASTER_STATE_APPL_WATCHDOG_EXPIRED:
printf("WARNING: Master state: APPL WATCHDOG EXPIRED\n");
break;
case DPM_MASTER_STATE_ASPC2_WATCHDOG_EXPIRED:
printf("WARNING: Master state: ASPC2 WATCHDOG EXPIRED\n");
break;
case DPM_MASTER_STATE_NO_TRAFFIC:
printf("WARNING: Master state: NO TRAFFIC\n");
break;
case DPM_MASTER_STATE_NO_FREE_ADDRESS:
printf("WARNING: Master state: NO FREE ADDRESS\n");
break;
case DPM_MASTER_STATE_NO_PARAMETERS:
printf("WARNING: Master state: NO PARAMETERS\n");
break;
case DPM_MASTER_STATE_LICENSE_ERROR:
printf("WARNING: Master state: LICENSE ERROR\n");
break;
default:
printf("UNKOWN MASTER STATE!\n");
break;
}
}
static void printOperationMode(NAIBRD_PB_DPM_OPERATION_MODE operationMode)
{
switch (operationMode)
{
case DPM_OPERATION_MODE_OFFLINE:
printf("Mode: OFFLINE\n");
break;
case DPM_OPERATION_MODE_STOP:
printf("Mode: STOP\n");
break;
case DPM_OPERATION_MODE_CLEAR:
printf("Mode: CLEAR\n");
break;
case DPM_OPERATION_MODE_OPERATE:
printf("Mode: OPERATE\n");
break;
case DPM_OPERATION_MODE_RED_CLEAR:
printf("Mode: RED CLEAR\n");
break;
case DPM_OPERATION_MODE_RED_OPERATE:
printf("Mode: RED OPERATE\n");
break;
case DPM_OPERATION_MODE_RED_OFFLINE:
printf("Mode: RED OFFLINE\n");
break;
case DPM_OPERATION_MODE_AUTOBAUD:
printf("Mode: AUTOBAUD\n");
break;
default:
printf("Mode is undefined\n");
break;
}
}
static void naibrd_PB_PrintPBStatus(int32_t pbStatus)
{
switch (pbStatus)
{
case NAI_PB_REQUEST_STILL_RUNNING_ERROR:
printf("PB Requested Operation is Still Running! Status = %d\n", pbStatus);
break;
case NAI_PB_STRING_LENGTH_ERROR:
printf("PB String Length Error! Status = %d\n", pbStatus);
break;
case NAI_PB_TIMEOUT_ERROR:
printf("PB Function Request Timed Out Prior to Completion! Status = %d\n", pbStatus);
break;
case NAI_PB_ARRAY_BOUNDS_EXCEEDED_ERROR:
printf("PB Array Bounds Were Exceeded! Status = %d\n", pbStatus);
break;
case NAI_PB_BUSY_ERROR:
printf("PB Busy Processing! Status = %d\n", pbStatus);
break;
case NAI_PB_SUCCESS:
printf("PB Success! Status = %d\n", pbStatus);
break;
default:
printf("PB UNKNOWN ERROR CODE! Status = %d\n", pbStatus);
break;
}
}