14.4User Programs & API

User Programs are custom programs written in Visual C++ or Visual Basic using Microsoft Development tools. These use the Applications Programming Interface (API) supplied with WebAccess.  The API makes calls to the SCADA Node and these user programs must run on the SCADA node.

Note – there is a scripting language in WebAccess based on Tcl, which can accomplish most tasks. See Scripts for more information on Screen Scripts and Global Scripts..

User Programs using the API are recommended only for experienced Visual C++ or Visual Basic developers with Microsoft Certification. 

Most users should use Scripts in WebAccess.

You must use a tag ID number to get information from WebAccess SCADA Node using the API calls. All calls use the Tag ID number only.  You build a list of Tag ID numbers using the GetId call and the tag name.  Note that changes to the WebAccess Database will change the association of Tag ID and Tag name.  Every time you start your User Program or WebAccess Restarts, you should rebuild you Tag ID list.

 

 VdBroadWinGetId( &tag_id, tagname ) 

This call places the Tag ID in the variable tag_id for the tagname contained in tagname. 

Tagname must be an char data (character data). 

Tag_id is usually struct data or int data.  (integer)

Tagname can include field parameters.   "TIMER.SPANHI"

 

VdBroadWinGetValue( &tag_id, &tag_value, &tag_Action);

This call places the reads the SCADA node and places the current value of tag in Tag_Value and current Action state in Tag_Action. 

Tag_id is int data (integer). 

Tag_id should have been updated using VdBroadWinGetId.

tag_textvalue is fl data (floating point)

tag_Action is int data (integer)

 

The return value of VdBroadWinGetValue() is an integer.

1 or -1 means the tag type is analog.

2 and -2 means the tag type is discrete.

3 and -3 means the tag type is text.

  

A Positive value means the return data is current value of the tag (i.e. communications to field device is good). A Negative value means the tag's value is BAD (i.e. communications is BAD).

 

Analog and discrete tags can be read using VdBroadWinGetValue() to get the numeric value in union fl. The .fval in the union stores the tag's value in 'double' format.

All tag types can also be read using VdBroadWinGetValueText() to read data in text format.

  

Note - Users should not use other members of union fl.

VdBroadWinGetValueText( &tag_id, &tag_textvalue, &tag_Action);

This call places the reads the SCADA node and places the current value of tag in Tag_TextValue and current Action state in Tag_Action. 

Tag_id is int data (integer). 

Tag_id should have been updated using VdBroadWinGetId.

tag_textvalue is char data (character data)

tag_Action is int data (integer)

 

The return value of VdBroadWinGetValueText() is an integer.

1 or -1 means the tag type is analog.

2 and -2 means the tag type is discrete.

3 and -3 means the tag type is text.

  

A Positive value means the return data is current value of the tag (i.e. communications to field device is good). A Negative value means the tag's value is BAD (i.e. communications is BAD).

 

All tag types can be read using VdBroadWinGetValueText() to read data in text format. Analog and discrete tags can also be read using VdBroadWinGetValue() to get the numeric value in union fl. The .fval in the union stores the tag's value in 'double' format.

  

Note - Users should not use other members of union fl.

 VdBroadWinSetValue( &tag2_id, &tag2_value)

This changes the value of the tag in the SCADA node.  The tag must be write able (i.e. not read only).

Tag_id is int data (integer). Tag_id should have been updated using VdBroadWinGetId.

tag_value is fl data (floating point)

 

Example:

 

struct VIEWDLL_ID tag_id={0};
union fl tag_value;
int   tag_Action;
char pbuf[120];

 

 

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
   char buf[64], *tagname;
   int rc;

 

   tagname = "TIMER";

 

   rc =VdBroadWinKrlInit();
  
   if ( rc == 0 ) return 0;

 

   rc = VdBroadWinGetId( &tag_id, tagname );
   if ( tag_id.id386.id ) VdBroadWinGetValue( &tag_id, &tag_value, &tag_Action);
   sprintf( buf, "Value=%.2f", tag_value.fval );
   MessageBox( NULL, buf, tagname, MB_OK );

 

 
   rc = VdBroadWinGetId( &tag_id, "TIMER.SPANHI" );
   if ( tag_id.id386.id ) VdBroadWinGetValue( &tag_id, &tag_value, &tag_Action);
   sprintf( buf, "Span High=%.2f", tag_value.fval );
   MessageBox( NULL, buf, tagname, MB_OK );

 

   VdBroadWinKrlFree();
 return 0;
}

 

The above example uses the default Tag Group 0 which is sufficient for most applications. If no 'Tag Group' is 'Set Active", then Tag Group 0 is active.

Note - The struct VIEWDAQ_ID is intended for WebAccess View client to  read the SCADA node kernel (i.e. intended for WebAccess internal use only). Users should treat the VIEWDAQ_ID struct as a data storage.