Instructions:
Operator inputs are generated automatically in WinCC by using the I/O fields if you have set the "Operator Input Yes" property when configuring the I/O field.
However, there are often requests that operator inputs should be able to be set by pressing a button or another object. This is possible using some of the functions of the WinCC Open Development Kit (WinCC ODK).
This entry shows how to use the ODK functions "MSRTCreateMsg()" and "MSRTSetComment()" to generate operator inputs at runtime. You can use these functions in up to and including WinCC V6.0 SP4. From WinCC V6.2, you must use the ODK function "MSRTCreateMsgInstanceWithComment()" (see Entry ID 24325381).
Warning! When you migrate an old project, you might have to replace the function calls of "MSRTCreateMsg()" and "MSRTSetComment()" with "MSRTCreateMsgInstanceWithComment()".
The structure of the operator input in this example is predefined by the system. At runtime, the C script of this entry generates an operator input with message number 12508141, which displays the old value and new value in process value_2 and process value_3 respectively as well as a message comment.
These API calls have been grouped together and supplied in the function "OpInputB" such that the same functionality as the operator input of an I/O field is achieved.
1. Supplying the "OpInputB" function
If the function is called by a "mouse-click" event on a button or other object, then it can be supplied as follows:
double value_old=0;
double value_new=1;
char* comment="Operation of button33";
OpInputB(comment,value_old,value_new);
or
char* comment="Operation of button10";
OpInputB(comment,0,0);
The function must be supplied with the comment string and the new value and old value, where these values can also be transferred simply with 0 if no tags are written.
Transfer of the tag ID as used for the I/O field is not provided for, since it cannot be determined.
No entry is made in the logbook for this function.
2. The "BedienMeldB" function
#pragma code ("Kernel32.DLL");
BOOL GetComputerNameA(LPSTR Computername, LPDWORD size);
BOOL GetLocalTime(SYSTEMTIME* stTime);
#pragma code();
#include "M_GLOBAL.H"
#include "msrtapi.h"
// =======================================================
// Function: BedienMeldB()
// =======================================================
// Description: Function to create user specific operator messages
// Call e.g. released by a button: BedienMeldB(CommentText,W_old,W_new);
// =======================================================
void BedienMeldB( char* CommentText,double doValueOld, double doValueNew)
{
CMN_ERROR g_sErr;
LPCMN_ERROR pError = &g_sErr; /* Global Error Block */
BOOL fRet = TRUE;
DWORD dwBufSize;
static DWORD l_svID = 0;
//Connection ID to Alarmlogging
DWORD dwVarID=0;
// Tag-ID set to 0
MSG_RTCREATE_STRUCT MsgCreate;
MSG_COMMENT_STRUCT MsgComment;
SYSTEMTIME stTime;
GetLocalTime( &stTime );
// Get time/date
MsgCreate.dwMsgNr = MSG_SINGLE_OPERATION;
// Operator Message Number
MsgComment.dwMsgNr = MSG_SINGLE_OPERATION;
// Operator Message Number
MsgCreate.stMsgTime = stTime;
MsgComment.stTime = stTime;
MsgCreate.wPValueUsed = 7;
// 3 Process Tags( 0..2 )
MsgCreate.dPValue[0] = dwVarID;
// Tag-ID
MsgCreate.dPValue[1] = doValueOld;
// previous value
MsgCreate.dPValue[2] = doValueNew;
// current value
MsgCreate.dwMsgState = MSG_STATE_COME;
// state "COME"
strcpy( MsgComment.szText, CommentText );
strcpy( MsgComment.szUser, GetTagChar("@CurrentUser"));
// assign logged user
// get computer name
dwBufSize = sizeof( MsgComment.szComputerName );
GetComputerNameA( MsgComment.szComputerName, &dwBufSize );
printf("ComputerName: %s \r\n",MsgComment.szComputerName);
do {
if( l_svID==0) {
fRet= MSRTStartMsgService( &l_svID, NULL, NULL, 0, NULL, pError );
// activate service
if(!fRet) break;
printf( "Alarm Connected %d \r\n", l_svID );
}
fRet = MSRTCreateMsg( l_svID, &MsgCreate, pError ) ;
// create message
// Create comment
if(fRet == FALSE ){
printf("MSRTCreateMsg_Error %s \r\n",pError->szErrorText);
}
else {
MSRTSetComment( l_svID, &MsgComment, pError );
}
break;
} while(TRUE);
fRet=MSRTStopMsgService(l_svID,pError);
// cancel service
printf("StopMsgService %d %s \r\n",fRet,pError->szErrorText);
if (fRet==TRUE)
l_svID=0;
}
Note:
There is a function in the WinCC ODK which permits the server to be transferred as call parameter. The default server is used in the example above.
Information on the ODK is available in Entry ID 9652128.
Also refer to Entry ID 24325381.
|