⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 com_send.c

📁 MatLab图像传感器网络仿真平台WiSNAP
💻 C
字号:
/*******************************************************************************
 * Send a command packet to an RS-232 communications object.                   *
 * Syntax: Status = Com_Send(Handle, Packet)                                   *
 *                                                                             *
 *    Input Parameters:                                                        *
 *    ================                                                         *
 *                                                                             *
 *       Handle ------> I/O object handle (positive integer).                  *
 *       Packet ------> Command packet (string).                               *
 *                                                                             *
 *    Output Parameters:                                                       *
 *    =================                                                        *
 *                                                                             *
 *       Status ------> Success status (-1 = error, +1 = success).             *
 *                                                                             *
 *    See also Com_Open(), Com_Close(), Com_Recv().                            *
 *                                                                             *
 * Compile: mex -v com_send.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		*result;
	HANDLE 		handle;
	int			length, status;

	/* get the value(s) of the input variable(s) */
	handle 		= (int *) (int) mxGetScalar(prhs[0]);
	length		= (int) mxGetN(prhs[1]);
	packet 		= (char *) mxCalloc(length+1, sizeof(char));
	status		= mxGetString(prhs[1], packet, length+1);

	/* call the respective subroutine(s) */
	status		= cmComSend(handle, packet, length);

	/* set the value(s) of the output variable(s) */
	plhs[0] 		= mxCreateDoubleMatrix(1, 1, mxREAL);
   result		= mxGetPr(plhs[0]);
	*result		= 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;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -