Commit af29126f authored by Claes's avatar Claes

Wb script plc editing

parent be710ebb
......@@ -9973,6 +9973,12 @@ GetRootList() <LINK> getrootlist()
GetVolumeClass() <LINK> getvolumeclass()
GetVolumeList() <LINK> getvolumelist()
SetAttribute() <LINK> setattribute()
CreateObject() <LINK> createobject()
OpenPlcPgm() <LINK> openplcpgm()
CreatePlcObject() <LINK> createplcobject()
CreatePlcConnection() <LINK> createplcconnection()
SetPlcObjectAttr() <LINK> setplcobjectattr()
PlcConnect() <LINK> plcconnect()
<h2>System functions
exit() <LINK> exit()
......@@ -10964,6 +10970,12 @@ GetRootList() <t>Get first object in root list. <LINK> getrootlist()
GetVolumeClass() <t>Get class of a volume. <LINK> getvolumeclass()
GetVolumeList() <t>Get fist volume. <LINK> getvolumelist()
SetAttribute() <t>Set attribute value. <LINK> setattribute()
CreateObject() <t>Create an object session. <LINK> createobject()
OpenPlcPgm() <t>Open a PlcPgm. <LINK> openplcpgm()
CreatePlcObject() <t>Create a plc object. <LINK> createplcobject()
CreatePlcConnection() <t>Create a plc connection. <LINK> createplcconnection()
SetPlcObjectAttr() <t>Set attribute in a plc object. <LINK> setplcobjectattr()
PlcConnect() <t>Connect a plc object. <LINK> plcconnect()
</TOPIC>
<headerlevel>
......@@ -11351,13 +11363,215 @@ Returns the status of the operation.
<b>Argument
string name attribute name.
arbitrary type value attribute value.
string <t>name <t>attribute name.
arbitrary type <t>value <t>attribute value.
<b>Example
<c> SetAttribute( "Pump-V1-Switch.Description", "Valve switch open");
</TOPIC>
<TOPIC> createobject() <style> function
CreateObject()
int CreateObject( string name, string class, string destination, int destcode)
<b>Description
Create an object.
Returns the status of the operation.
<b>Argument
string <t>name <t>object name. Without path.
string <t>class <t>object class.
string <t>destination <t>destination object. A father or sibling to the object.
int <t>destcode <t>destination code. 1 first child, 2 last child,
<t><t>3 after, 4 before.
<b>Example
<c> CreateObject( "Temperature", "BaseTempSensor", "Pump-V1", 2);
</TOPIC>
<TOPIC> openplcpgm() <style> function
OpenPlcPgm()
int OpenPlcPgm( string name)
<b>Description
Open a plc program and a plc editing session.
Returns the status of the operation.
There should not be any unsaved operations when this function is called.
Only one program can be opened concurrently.
The plc editing session should be closed with a call to ClosePlcPgm().
In the plc editing session only the plc functions CreatePlcObject(),
CreatePlcConnection(), SetPlcObjectAttr() and PlcConnect() should be
used to manipulate and create objects. Access for the previous session
is temporary set to readonly when the plc editing is active.
<b>Argument
string name name of PlcPgm object.
<b>Example
<c> OpenPlcPgm( "Pump-V1-Control");
<c> ...
<c> ClosePlcPgm();
</TOPIC>
<TOPIC> closeplcpgm() <style> function
ClosePlcPgm()
int ClosePlcPgm()
<b>Description
Closes a plc editing session.
<b>Example
<c> OpenPlcPgm( "Pump-V1-Control");
<c> ...
<c> ClosePlcPgm();
</TOPIC>
<TOPIC> createplcobject() <style> function
CreatePlcObject()
int CreatePlcObject( string name, string class, float x, float y [, string destination,
int inputmask, int outputmask, int invertmask])
<b>Description
Creates a plc function object in a plc editing session.
The function can only be used in a plc editing session started with a call to
OpenPlcPgm().
The object is positioned on the coordinates x and y. If destination, a document object,
is supplied, the coordinates are relative to this object, otherwise they are absolute.
If the masks are left out the default masks are used.
<b>Argument
string <t>name <t>Object name. Without path.
string <t>class <t>Object class.
float <t>x <t>x coordinate.
float <t>y <t>y coordinate.
string <t>destination <t>Optional. A document object. If supplied the coordinates
<t><t>are relative to this object.
int <t>inputmask <t>Optional. Mask where the bits indicate visible input pins
<t><t>in the function block.
int <t>outputmask <t>Optional. Mask where the bits indicate visible output pins
<t><t>in the function block.
int <t>invmask <t>Optional. Mask where the bits indicate inverted input pins.
<b>Example
<c> OpenPlcPgm( "Pump-V1-Control");
<c> CreatePlcObject( "Document0", "Document", 1.2, 0.0);
<c> CreatePlcObject( "And0", "And", 0.3, 0.1, "Document0", 15, 1, 3);
<c> CreatePlcObject( "V1", "BaseCValve", 0.3, 0.4, "Document0");
<c> ClosePlcPgm();
</TOPIC>
<TOPIC> createplcconnection() <style> function
CreatePlcConnection()
int CreatePlcConnection( string source, string sourceattr, string dest, string destattr [,
int feedback])
<b>Description
Creates a plc connection between the source function object and the destination
function object.
The function can only be used in a plc editing session started with a call to
OpenPlcPgm().
The pins to connect to are specified by the attributes names of the pins. If a
dashed feedback connection is to be created, this can be stated with the optional
feedback argument.
<b>Argument
string <t>source <t>Source object name. Without path.
string <t>sourceattr <t>Attribute for pin on the source object.
string <t>dest <t>Destination object name. Without path.
string <t>destattr <t>Attribute for pin on the destination object.
int <t>feedback <t>Optional. If 1 a dashed feedback connection is created.
<b>Example
<c> OpenPlcPgm( "Pump-V1-Control");
<c> ...
<c> CreatePlcObject( "And0", "And", 0.3, 0.1, "Document0", 15, 1, 3);
<c> CreatePlcObject( "And1", "And", 0.6, 0.1, "Document0", 15, 1, 3);
<c> CreatePlcConnection( "And0", "Status", "And1", "In1");
<c> # Feedback connection
<c> CreatePlcConnection( "And1", "Status", "And0", "In4", 1);
<c> ClosePlcPgm();
</TOPIC>
<TOPIC> plcconnect() <style> function
PlcConnect()
int PlcConnect( string plcobject, string connectobject)
<b>Description
Activates the plc connect function, for example to connect Get and Sto function objects to
signals and attributes in the plant hierarchy.
The function can only be used in a plc editing session started with a call to
OpenPlcPgm().
<b>Argument
string <t>plcobject <t>Name, without path, of plc function object that should
<t><t>be connected.
string <t>connectobject <t>Name of object or attribute to connect to.
<t><t>Full name with path.
<b>Example
<c> OpenPlcPgm( "Pump-V1-Control");
<c> ...
<c> CreatePlcObject( "GetDv0", "GetDv", 0.3, 0.1, "Document0");
<c> PlcConnect( "GetDv0", "Pump-V1-Active");
<c> ...
<c> ClosePlcPgm();
</TOPIC>
<TOPIC> setplcobjectattr() <style> function
SetPlcObjectAttr()
int SetPlcObjectAttr( string attribute, (arbitrary type) value)
xxx
<b>Description
Set a value in a plc object.
The function can only be used in a plc editing session started with a call to
OpenPlcPgm().
<b>Argument
string <t>name <t>attribute name. Without path.
arbitrary type <t>value <t>attribute value.
<b>Example
<c> OpenPlcPgm( "Pump-V1-Control");
<c> CreatePlcObject( "Document0", "Document", 1.3, 0.0);
<c> SetPlcObjectAttr( "Document0.DocumentOrientation", 1);
<c> SetPlcObjectAttr( "Document0.DocumentSize", 3);
<c> ...
<c> ClosePlcPgm();
</TOPIC>
</headerlevel>
<TOPIC> misc_functions <style> function
......
......@@ -690,6 +690,7 @@ static void ccm_print_error( ccm_tFileCtx filectx, int sts)
case CCM__STRINGEXCEED : strcpy( text, "Maximum string size exceeded"); break;
case CCM__ARGEXCEED : strcpy( text, "Maximum number of arguments exceeded"); break;
case CCM__ARRAYBOUNDS : strcpy( text, "Array index out of bounds"); break;
case CCM__NOACCESS : strcpy( text, "No access for operation"); break;
default : strcpy( text, "Unknown error code");
}
if ( filectx->error_row)
......
......@@ -67,7 +67,7 @@ stringexceed <maximum size of string exceeded> /error
argexceed <max number of arguments exceeded> /error
arraybounds <array index out of bounds> /error
alreadyreg <function is already registred> /info
noaccess <no access for operation> /error
......
......@@ -4304,6 +4304,239 @@ void WFoe::get_build_options_subwindow_cb( void *ctx, wb_build_opt **opt)
(foe->get_build_options_cb)( foe->parent_ctx, opt);
}
int WFoe::cmd_get_ldhses( ldh_tSesContext *ldhses)
{
*ldhses = gre->wind->hw.ldhses;
return 1;
}
int WFoe::cmd_delete_node( pwr_tOid oid)
{
vldh_t_node *nodelist;
unsigned long node_count;
int i, sts;
/* Get all nodes */
sts = vldh_get_nodes( gre->wind, &node_count, &nodelist);
if ( EVEN(sts)) return sts;
for ( i = 0; i < (int)node_count; i++) {
if ( cdh_ObjidIsEqual( nodelist[i]->ln.oid, oid)) {
gre->delete_node( nodelist[i]);
break;
}
}
free( (char *)nodelist);
return FOE__SUCCESS;
}
int WFoe::cmd_create_node( char *name, pwr_tCid cid, pwr_tOid *destoid, float x, float y, int use_default_masks,
unsigned int inputmask, unsigned int outputmask, unsigned int invertmask)
{
vldh_t_node node;
int sts;
pwr_sPlcNode *nodebuffer;
pwr_eClass eclass;
int size;
if ( destoid) {
// Coordinates are relative to destination node
vldh_t_node *nodelist;
unsigned long node_count;
vldh_t_node destnode;
float ll_x, ll_y, width, height;
sts = vldh_get_nodes( gre->wind, &node_count, &nodelist);
if ( EVEN(sts)) return sts;
int found = 0;
for ( int i = 0; i < (int)node_count; i++) {
if ( cdh_ObjidIsEqual( nodelist[i]->ln.oid, *destoid)) {
destnode = nodelist[i];
found = 1;
break;
}
}
if ( found) {
gre->measure_object( destnode, &ll_x, &ll_y, &width, &height);
x += ll_x;
y += ll_y;
}
}
disable_ldh_cb();
sts = gre->create_node( cid, x, y, &node);
enable_ldh_cb();
if ( EVEN(sts)) return sts;
sts = ldh_SetObjectName( gre->wind->hw.ldhses, node->ln.oid, name);
if ( !use_default_masks) {
sts = ldh_GetObjectBuffer( gre->wind->hw.ldhses,
node->ln.oid, "DevBody", "PlcNode", &eclass,
(char **)&nodebuffer, &size);
if ( EVEN(sts)) return sts;
nodebuffer->mask[0] = inputmask;
nodebuffer->mask[1] = outputmask;
nodebuffer->mask[2] = invertmask;
sts = ldh_SetObjectBuffer( gre->wind->hw.ldhses,
node->ln.oid, "DevBody", "PlcNode",
(char *)nodebuffer);
free( (char *)nodebuffer);
}
gre->node_update( node);
return FOE__SUCCESS;
}
int WFoe::cmd_create_con( pwr_tOid srcoid, char *srcattr, pwr_tOid destoid, char *destattr,
int feedback)
{
vldh_t_node srcnode, destnode;
vldh_t_node *nodelist;
unsigned long node_count;
int i, sts;
pwr_tCid con_class, user_class;
ldh_sParDef *bodydef;
int rows;
/* Get all nodes */
sts = vldh_get_nodes( gre->wind, &node_count, &nodelist);
if ( EVEN(sts)) return sts;
int src_found = 0;
int dest_found = 0;
for ( i = 0; i < (int)node_count; i++) {
if ( cdh_ObjidIsEqual( nodelist[i]->ln.oid, srcoid)) {
srcnode = nodelist[i];
src_found = 1;
if ( dest_found)
break;
}
else if ( cdh_ObjidIsEqual( nodelist[i]->ln.oid, destoid)) {
destnode = nodelist[i];
dest_found = 1;
if ( src_found)
break;
}
}
free( (char *)nodelist);
if ( !(src_found && dest_found))
return 0;
user_class = 0;
// Get conpoints
sts = ldh_GetObjectBodyDef( gre->wind->hw.ldhses,
srcnode->ln.cid, "RtBody", 1,
&bodydef, &rows);
if ( EVEN(sts) ) return sts;
// Find source connection point number
src_found = 0;
int src_point = -1;
unsigned int inputmask = 1;
unsigned int outputmask = 1;
for ( int i = 0; i < rows; i++) {
if ( bodydef[i].ParClass == pwr_eClass_Input) {
if ( inputmask & srcnode->ln.mask[0])
src_point++;
inputmask = inputmask << 1;
}
else if ( bodydef[i].ParClass == pwr_eClass_Output) {
if ( outputmask & srcnode->ln.mask[1])
src_point++;
outputmask = outputmask << 1;
}
if ( cdh_NoCaseStrcmp( srcattr, bodydef[i].ParName) == 0) {
src_found = 1;
break;
}
}
free( (char *)bodydef);
if ( !src_found || src_point == -1)
return 0;
// Find destination connection point number
sts = ldh_GetObjectBodyDef( gre->wind->hw.ldhses,
destnode->ln.cid, "RtBody", 1,
&bodydef, &rows);
if ( EVEN(sts) ) return sts;
dest_found = 0;
int dest_point = -1;
inputmask = 1;
outputmask = 1;
for ( int i = 0; i < rows; i++) {
if ( bodydef[i].ParClass == pwr_eClass_Input) {
if ( inputmask & destnode->ln.mask[0])
dest_point++;
inputmask = inputmask << 1;
}
else if ( bodydef[i].ParClass == pwr_eClass_Output) {
if ( outputmask & destnode->ln.mask[1])
dest_point++;
outputmask = outputmask << 1;
}
if ( cdh_NoCaseStrcmp( destattr, bodydef[i].ParName) == 0) {
dest_found = 1;
break;
}
}
free( (char *)bodydef);
if ( !dest_found || dest_point == -1)
return 0;
sts = gsx_check_connection( this, srcnode, src_point,
destnode, dest_point, &con_class, user_class);
if ( EVEN(sts)) return sts;
if ( feedback) {
// Change to corresponding feedback connection
if ( con_class == pwr_cClass_ConDigital)
con_class = pwr_cClass_ConFeedbackDigital;
else if ( con_class == pwr_cClass_ConAnalog)
con_class = pwr_cClass_ConFeedbackAnalog;
}
sts = gre->create_con( con_class, srcnode, src_point,
destnode, dest_point, con_drawtype);
return sts;
}
int WFoe::cmd_connect( pwr_tAttrRef *aref, pwr_tOid plcnode)
{
vldh_t_node node;
vldh_t_node *nodelist;
unsigned long node_count;
int sts;
/* Get all nodes */
sts = vldh_get_nodes( gre->wind, &node_count, &nodelist);
if ( EVEN(sts)) return sts;
int found = 0;
for ( int i = 0; i < (int)node_count; i++) {
if ( cdh_ObjidIsEqual( nodelist[i]->ln.oid, plcnode)) {
node = nodelist[i];
found = 1;
break;
}
}
if ( !found)
return 0;
gobj_set_select( aref);
sts = gobj_get_object( this, node, 1) ;
return sts;
}
/* API routines */
#if 0
......
......@@ -312,6 +312,13 @@ class WFoe : public WUtility {
unsigned long new_window,
foe_eFuncAccess function_access);
void get_hinactx( void **hinactx);
int cmd_get_ldhses( ldh_tSesContext *ldhses);
int cmd_create_node( char *name, pwr_tCid cid, pwr_tOid *destoid, float x, float y, int use_default_masks,
unsigned int inputmask, unsigned int outputmask, unsigned int invertmask);
int cmd_delete_node( pwr_tOid oid);
int cmd_create_con( pwr_tOid srcoid, char *srcattr, pwr_tOid destoid, char *destattr,
int feedback);
int cmd_connect( pwr_tAttrRef *aref, pwr_tOid plcnode);
static pwr_tStatus ldh_this_session_cb( void *ctx, ldh_sEvent *event);
static void error_msg( unsigned long sts);
......
......@@ -136,6 +136,9 @@ gobj_tMethod gobj_get_object_m[40] = {
gobj_get_object_m34,
};
static pwr_tAttrRef gobj_selected_aref;
static int gobj_selected_set = 0;
static int gobj_expand_m0( WFoe *foe,
vldh_t_node node,
int compress);
......@@ -147,6 +150,14 @@ static int gobj_expand_m2( WFoe *foe,
int compress);
/*_Local procedues_______________________________________________________*/
//
// Preset of selected object used by command interface
//
void gobj_set_select( pwr_tAttrRef *aref)
{
gobj_selected_set = 1;
gobj_selected_aref = *aref;
}
//
// Function used in class template PlcPgm's.
......@@ -197,9 +208,27 @@ static pwr_tStatus gobj_ref_replace( ldh_tSesContext ldhses,
static int gobj_get_select( WFoe *foe, pwr_sAttrRef *attrref, int *is_attr)
{
pwr_tStatus sts;
char str[200];
pwr_tAName str;
vldh_t_plc plc = foe->gre->wind->hw.plc;
if ( gobj_selected_set) {
// Preset select
char *np;
int size;
*attrref = gobj_selected_aref;
gobj_selected_set = 0;
sts = ldh_AttrRefToName( foe->gre->wind->hw.ldhses, attrref, ldh_eName_Hierarchy, &np, &size);
if ( ODD(sts)) {
if ( strchr( np, '.') != 0)
*is_attr = 1;
else
*is_attr = 0;
}
return FOE__SUCCESS;
}
if ( foe->nav_palette_managed) {
sts = foe->navctx->get_select( attrref, is_attr);
if ( ODD(sts))
......@@ -244,7 +273,7 @@ int gobj_get_object(
/* Fix to avoid crash if foe is started form hied */
plc = (node->hn.wind)->hw.plc;
if ( plc->hp.hinactx == 0 ) {
if ( plc->hp.hinactx == 0 && !gobj_selected_set) {
foe->message( "Foe must be started from the navigator to connect");
return FOE__SUCCESS;
}
......
......@@ -50,4 +50,7 @@ int gobj_get_object(
int gobj_expand( WFoe *foe,
vldh_t_node node,
int compress);
void gobj_set_select( pwr_tAttrRef *aref);
#endif
This diff is collapsed.
......@@ -36,10 +36,13 @@
/* wb_wccm.h -- Buildtin script functions for wb */
class WNav;
void wccm_store_ldhses( void *client_data, ldh_tSesContext ldhsession);
void wccm_store_client( void *client_data);
int wccm_get_ldhses( ldh_tSesContext *ldhses);
int wccm_register(
int (* get_wbctx_cb)( void *, ldh_tWBContext *),
int (* get_ldhsession_cb)( void *, ldh_tSesContext *));
int (* get_ldhsession_cb)( void *, ldh_tSesContext *),
int (* get_wnav_cb)( void *, WNav **));
void wccm_set_status( pwr_tStatus sts);
......@@ -106,6 +106,7 @@ static int wnav_cnt = 0;
static int wnav_wccm_get_ldhsession_cb( void *ctx, ldh_tWBContext *wbctx);
static int wnav_wccm_get_wbctx_cb( void *ctx, ldh_tSesContext *ldhses);
static int wnav_wccm_get_wnav_cb( void *ctx, WNav **wnav);
static char *wnav_VolumeIdToStr( pwr_tVolumeId volumeid);
static int wnav_help_func( void *client_data,
......@@ -7001,7 +7002,7 @@ int WNav::readcmdfile( char *incommand)
ccm_func_registred = 1;
// Register wb standard functions
wccm_register( wnav_wccm_get_wbctx_cb, wnav_wccm_get_ldhsession_cb);
wccm_register( wnav_wccm_get_wbctx_cb, wnav_wccm_get_ldhsession_cb, wnav_wccm_get_wnav_cb);
}
strcpy( input_str, incommand);
......@@ -7357,6 +7358,12 @@ static int wnav_wccm_get_wbctx_cb( void *ctx, ldh_tWBContext *wbctx)
return 1;
}
static int wnav_wccm_get_wnav_cb( void *ctx, WNav **wnav)
{
*wnav = (WNav *)ctx;
return 1;
}
char *wnav_VolumeIdToStr( pwr_tVolumeId volumeid)
{
static char str[80];
......
......@@ -3068,7 +3068,7 @@ int Graph::readcmdfile( char *incommand)
// Register wb standard functions
#if LDH
wccm_register( graph_wccm_get_wbctx_cb, graph_wccm_get_ldhsession_cb);
wccm_register( graph_wccm_get_wbctx_cb, graph_wccm_get_ldhsession_cb, 0);
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment