?? com_recv.c
字號:
/*******************************************************************************
* Receive a response packet from an RS-232 communications object. *
* Syntax: [Packet, Status] = Com_Recv(Handle, Length) *
* *
* Input Parameters: *
* ================ *
* *
* Handle ------> I/O object handle (positive integer). *
* Length ------> Packet length to receive (positive integer). *
* *
* Output Parameters: *
* ================= *
* *
* Packet ------> Response packet (string). *
* Status ------> Success status (-1 = error, +1 = success). *
* *
* See also Com_Open(), Com_Close(), Com_Send(). *
* *
* Compile: mex -v com_recv.c cmApiCom.c *
* Version: 01-22-2005 *
* *
* (C) 2004 Stephan Hengstler, Stanford Wireless Sensor Networks Lab *
*******************************************************************************/
#include <stdio.h>
#include <windows.h>
#include "mex.h"
#include "cmApiCom.h"
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
char *packet;
double *result1;
HANDLE handle;
int dims[2], i, length, status;
mxChar *result0;
/* get the value(s) of the input variable(s) */
handle = (int *) (int) mxGetScalar(prhs[0]);
length = (int) mxGetScalar(prhs[1]);
/* call the respective subroutine(s) */
packet = (char *) mxCalloc(length+1, sizeof(char));
status = cmComRecv(handle, packet, length, &length);
/* set the value(s) of the output variable(s) */
dims[0] = 1;
dims[1] = length;
plhs[0] = mxCreateCharArray(2, dims);
result0 = (mxChar *) mxGetData(plhs[0]);
for (i = 0; i < length; i++)
result0[i] = packet[i];
plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
result1 = mxGetPr(plhs[1]);
*result1 = status;
/* show debug information */
if (nrhs == 3)
{
printf("Debug Information\n");
printf("handle = %d\n", handle);
printf("length = %d\n", length);
printf("packet = %s\n", packet);
printf("status = %d\n", status);
}
/* clean exit */
return;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -