
MVI-ADM ♦ 'C' Programmable Serial Port Library Functions
'C' Programmable Application Development Module Developer's Guide
ProSoft Technology, Inc. Page 259 of 342
February 20, 2013
MVIsp_GetData
Syntax
int MVIsp_GetData(int comport, BYTE *data, int *len, DWORD timeout);
Parameters
port from which data is to be received
pointer to array of bytes to receive data
number of bytes to receive / bytes received
amount of time to wait to receive character
Description
This function receives an array of bytes from a serial port. comport must be
previously opened with MVIsp_Open.
data points to an array of bytes that will receive the data.
len points to the number of bytes to receive.
MVIsp_GetData retrieves bytes from the reception queue until either the number
of bytes pointed to by len are retrieved or the timeout elapses.
All data received from a port is queued after reception from the serial port.
Therefore, some delay may occur between the time a character is received
across the serial line and the time the character is returned by MVIsp_GetData.
This function attempts to retrieve characters from the reception queue, and return
values correspond accordingly.
timeout specifies the amount of time in milliseconds to wait. If timeout is
TIMEOUT_ASAP, the function will return immediately if the queue is empty. If
timeout is TIMEOUT_FOREVER, the function will not return until an array of
bytes is retrieved from the reception queue successfully.
If the timeout elapses before the termination character or len bytes are received,
MVI_ERR_TIMEOUT is returned.
When MVIsp_GetData returns, it writes to the int pointed to by len the number of
bytes retrieved. len is written for successfully retrieved bytes as well as timeouts.
Return Value
bytes were retrieved successfully
comport has not been opened
timeout elapsed before bytes retrieved
Example
BYTE data[10];
int nn;
nn = 10;
if (MVIsp_GetData(COM1, data, &nn, 1000L) == MVI_SUCCESS)
printf("%d bytes were received\n",nn);
Kommentare zu diesen Handbüchern