📄 phd_connect.c
字号:
/*
Program to login into PHD
PHD = Process History database, a Honeywell-database to store chemical plant data
Author : Hans Vereecken
BASF Antwerp
003235613411
hans.vereecken@notes.basant.be
Can be distributed freely.
To compile in matlab via "mex phd_connect.c netapishr.lib"
netapishr.lib is the PHD library, found under c:\program files\...
put it in the same directory as the c-file, together with all the needed headers
*/
#include "PHDUSER.H" /* PHD-header ; has to be on your harddisk */
#include "mex.h" /* Matlab header */
#include <stdio.h>
#include <string.h>
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
/* Calling convention of Matlab
nlhs : number of left hand side arguments (3 in this case)
plhs : pointer to the left hand side arguments
nrhs : number of right hand side arguments (0 in this case)
plhs : pointer to the right hand side arguments
USAGE IN MATLAB : PHD_connect(host,user,pswrd);
host, user and pswrd are strings
*/
{
int buflen;
char *input_hostname;
char *input_username;
char *input_password;
ISTAT status; /* defined in PHDUSER.H */
/*------------------------------------------------------------------------------------------*/
/* Error checking
number of arguments */
if(nrhs!=3)
mexErrMsgTxt("3 inputs required.");
else if(nlhs > 0)
mexErrMsgTxt("Too many output arguments.");
/* First input must be a string (the host-id) */
if ( mxIsChar(prhs[0]) != 1)
mexErrMsgTxt("First input must be a string.");
/* First input must be a row vector */
if (mxGetM(prhs[0])!=1)
mexErrMsgTxt("First input must be a row vector.");
/* get the length of the first input string */
buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
/* allocate memory for first input string */
input_hostname=mxCalloc(buflen, sizeof(char));
/* copy the string data from prhs[0] into a C string.*/
status = mxGetString(prhs[0], input_hostname, buflen);
if(status != 0)
mexWarnMsgTxt("Not enough space. First string is truncated.");
status=phd_sethost(input_hostname); /* sethostname ; PHD API routine */
mxFree(input_hostname); /* Free the memory*/
if(status!=0)
{
mexPrintf("Can not connect to host!\n");
return;
}
/*-------------------------------------------------------------------------*/
/* Second input must be a string (the user-id) */
if ( mxIsChar(prhs[1]) != 1)
mexErrMsgTxt("Second input must be a string.");
/* Second input must be a row vector */
if (mxGetM(prhs[1])!=1)
mexErrMsgTxt("Second input must be a row vector.");
/* Get the length of the second input string */
buflen = (mxGetM(prhs[1]) * mxGetN(prhs[1])) + 1;
/* allocate memory for input string */
input_username=mxCalloc(buflen, sizeof(char));
/* copy the string data from prhs[1] into a C string.*/
status = mxGetString(prhs[1], input_username, buflen);
if(status != 0)
mexWarnMsgTxt("Not enough space. Second string (username) is truncated.");
/* Third input must be a string (the password) */
if ( mxIsChar(prhs[2]) != 1)
mexErrMsgTxt("The third input (the password) must be a string.");
/* Third input must be a row vector */
if (mxGetM(prhs[2])!=1)
mexErrMsgTxt("Third input must be a row vector.");
/* Get the length of the third input string */
buflen = (mxGetM(prhs[2]) * mxGetN(prhs[2])) + 1;
/* allocate memory for input string */
input_password=mxCalloc(buflen, sizeof(char));
/* copy the string data from prhs[2] into a C string.*/
status = mxGetString(prhs[2], input_password, buflen);
if(status != 0)
mexWarnMsgTxt("Not enough space. third string (the password) is truncated.");
status=phd_login(input_username,input_password);
if(status!=0)
{
mexPrintf("Can not login to host. Wrong user/password!\n");
return;
}
mxFree(input_username); /* Free the memory*/
mxFree(input_password); /* Free the memory*/
/* End of login procedure */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -