Initializing the lontalk stack device, Periodically calling the event pump – Echelon LonTal Stack User Manual
Page 125
LonTalk Stack Developer’s Guide
113
Initializing the LonTalk Stack Device
Before your application initializes the LonTalk host stack, it must initialize the C
runtime environment and the operating system.
If your LonTalk Stack device uses a native LonTalk interface, your application
must implement the LonGetMyNetworkInterface() function in the
FtxlHandlers.c file to specify the name of the network interface to be used by
the driver. If your LonTalk Stack device uses an IP-852 interface, your
application must implement the LonGetMyIpAddress() fucntion in the
FtxlHandlers.c file to return the IP address and port to be used by the IP-852
interface.
Your application must call the LonInit() function once during device startup.
The implementation of this function is generated by the LonTalk Interface
Developer utility, and is included in the FtxlDev.c file. This function initializes
the LonTalk API, the LonTalk host stack, and the Echelon Smart Transceiver or
Neuron Chip. The main application thread must call this function before it calls
any other LonTalk API functions.
LonInit() registers the LonTalk Stack device interface data with the LonTalk
host stack. This data defines the network parameters and device interface. If
your application needs to change the network parameters or change the device
interface, it can call the LonExit() function to shut down the LonTalk host stack,
and then call the LonInit() function to restart the LonTalk host stack with the
updated interface.
Add a call the LonInit() function to the beginning of the application’s main
thread. If this function is successful, your application can begin normal
operations, including calling the event pump, as described in Periodically Calling
Example:
void myMainThread(void) {
LonApiError
sts;
sts = LonInit();
if (sts == LonApiNoError) {
// begin normal operations
}
}
Periodically Calling the Event Pump
As described in Callbacks and Events, your LonTalk Stack application must
periodically call the LonEventPump() function to check if there are any
L
ON
W
ORKS
events to process. This function calls specific API functions based on
the type of event, then calls event handler functions to notify the application
layer of these network events. You can call this function from the idle loop
within the main application thread or from any point in your application that is
processed periodically. However, you must call this function from the same
application context (task or thread) that called the LonInit() function.
The LonTalk API calls the LonEventReady() callback handler function
whenever an event has been posted. This function is typically called from a
LonTalk host stack task or thread, and you must not call the LonEventPump()
function directly from the callback. However, your application could define an