Echelon OpenLDV User Manual
Page 61

OpenLDV Programmer’s Guide
53
// Include the header file from the OpenLDV API Example
// (contains definitions for ExpMsgHdr, ExpAppBuffer, niNTQ, niNETMGMT)
#include "OpenLdvDefinitions.h"
// Define Network Management commands
// from ISO/IEC 14908 Control Networking Protocol spec
#define LonNdQueryStatus 0x51 // Query Status command
#define LonNdQueryStatusSuccess 0x31 // Success Response for Query Status
//
// Variable Definitions
//
// Handle for Windows event calls
HANDLE
hEvent = NULL;
// Return code for ldv_* calls.
LDVCode
rc = LDV_OK; // Assume OK result
// Handle used for ldv_* calls. -1 (minus 1) if not valid.
short
m_OpenLdvHandle;
// Flag to signal whether it’s Ok to work with the network interface
Bool
ldvCmdOk = TRUE; // Assume OK result
// Input and output buffers:
ExpAppBuffer
m_msgIn; // Incoming message buffer
ExpAppBuffer
m_msgOut; // Outgoing message buffer
// Size of the message to send
short
msgsize = sizeof(m_msgOut.data.code);
//
// Set Up Windows Event
//
hEvent = CreateEvent(NULL, FALSE, TRUE, NULL);
//
// Application Code
//
// Open the network interface; assume LON1
rc = ldv_open(“LON1”, &m_OpenLdvHandle);
if (rc != LDV_OK) {
m_OpenLdvHandle = -1; // Mark handle invalid
ldvCmdOk = FALSE; // Don’t try to work with the network interface
printf(“Could not open the network interface.\n”);
}
else {
// Register Windows event with this network interface
rc = ldv_register_event(m_OpenLdvHandle, hEvent);
if (rc != LDV_OK) {
ldvCmdOk = FALSE; // Don’t try to work with the network interface
printf(“Could not register an event for the network interface.\n”);
}
else {
ldvCmdOk = TRUE; // Ok to work with the network interface
}
}