Binary data block transfers require that the user set up the header structure defined above, make the QNX Send call, and check the result. The following provides a simple example of how the interface can be used.
#define MAX_DATA_SIZE 80 #define MAX_MSG_SIZE sizeof(DR_ApBlkHdr_t) -1 + MAX_DATA_SIZE #define DATA_MSG_SIZE sizeof(DR_ApBlkHdr_t) -1 + sizeof(short) int ToggleOutputBit(pid_t admin_pid, unsigned short ofs, int bit) { int result=0; unsigned short *data_word; char msg [MAX_MSG_SIZE]; DR_ApBlkHdr_t *hdr; /* setup a message to read the specified 2 bytes from an output buffer */ hdr = (DR_ApBlkHdr_t *) msg; data_word = (unsigned short *)hdrcf->data; hdrcf->cmd = DR_API_BLK_RD; hdrcf->dev = 0; hdrcf->buffer = 0; hdrcf->buf_size = MAX_MSG_SIZE; hdrcf->offset = ofs; hdrcf->size = sizeof(short); result = Send (admin_pid, msg, msg, DATA_MSG_SIZE, MAX_MSG_SIZE); if (result == 0) { if (!(result = hdrcf->status)) { /* toggle the bit */ (*data_word) ^= 1<<(bit-1); /* write it back out */ hdrcf->cmd = DR_API_BLK_WR; result = Send (admin_pid, msg, msg, DATA_MSG_SIZE, MAX_MSG_SIZE); } else printf (" Driver response: %s\n", hdrcf->data); } else printf (" Error %d sending to driver pid %d\n", result, admin_pid); return (result); }
ASCII commands are sent simply using a QNX Send with the string as the message buffer (and appropriate length). The reply message buffer must contain sufficient space for the anticipated result. The ASCII reply is in the internal syntax of the driver (see Configuration), and the user is responsible for parsing the response.
If the driver determines an error condition, an error (non-zero) code is returned in the status element of the structure. In most cases, an error string is returned in the data portion of the reply, provided sufficient space is available. Error strings are formatted as
(error error_string)
where error_string contains the module the error occurred in, the error number and the error description string. See Error Handling for more details.
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.