Echelon OpenLDV User Manual

Page 62

Advertising
background image

54

Using the OpenLDV API

if (ldvCmdOk) {

// Build message to send to NI

m_msgOut.ni_hdr.q.queue = niNTQ;

m_msgOut.ni_hdr.q.q_cmd = niNETMGMT;

m_msgOut.ni_hdr.q.length = sizeof(ExpMsgHdr) + sizeof(ExplicitAddr) +

msgSize

;

m_msgOut.msg_hdr.exp.tag = 1; // Assume message tag 1

m_msgOut.msg_hdr.exp.auth = 0;

m_msgOut.msg_hdr.exp.response = 1; // Make it a response

m_msgOut.msg_hdr.exp.st = 3; // Make it a REQUEST

m_msgOut.msg_hdr.exp.pool = 0; // Must be zero

m_msgOut.msg_hdr.exp.alt_path = 0; // Use default path

m_msgOut.msg_hdr.exp.addr_mode = 0; // Implicit addressing

m_msgOut.msg_hdr.exp.cmpl_code = 0; // MSG_NOT_COMPL

m_msgOut.msg_hdr.exp.path = 0; // Use primary path

m_msgOut.msg_hdr.exp.priority = 0;

m_msgOut.msg_hdr.exp.length =

msgSize

;

m_msgOut.addr.snd.

lc

= NI_LOCAL;

m_msgOut.data.code = LonNdQueryStatus;

// Omitting “m_msgOut.data.data” because Query Status command has no data

// Write query status command to the network interface

rc = ldv_write(m_OpenLdvHandle, m_msgOut, offsetof(ExpAppBuffer, code) +

msgSize);

if (rc != LDV_OK) {

ldvCmdOk = FALSE; // Don’t try to read from the network interface

printf(“Could not write to network interface.\n”);

}

else {

ldvCmdOk = TRUE; // Ok to read from the network interface

}

}

if (ldvCmdOk) {

// Wait for network interface event

WaitForSingleObject (hEvent, 1000); // Wait 1 second

// Read response to query status command

rc = ldv_read(m_OpenLdvHandle, &m_msgIn, sizeof(m_msgIn));

if (rc != LDV_OK) {

printf(“Could not read from network interface.\n”);

}

else {

// Read return code from the LonNdQueryStatus command

if (m_msgIn.data.code == LonNdQueryStatusSuccess) {

// Success response from Query Status command;

// Read error log as something interesting to do

BYTE errLog = (

ND_query_status_response

*)(&m_msgIn.data.data)->

error_log

;

if (errLog == 0) printf(“No error in network interface.\n”);

else printf(“Network interface error was: %d\n”, errLog);

}

else {

// Failure response from Query Status command; do something else

printf(“Failure response from Query Status cmd: %d\n”,m_msgIn.data.code);

}

}

}

Advertising