Commit c95797a2 authored by Claes Sjofors's avatar Claes Sjofors

Profinet configurator, fix for non consecutive modules (refs #240)

parent eb5cc397
......@@ -168,98 +168,40 @@ int pndevice_save_cb( void *sctx)
ldh_eName_Hierarchy, name, sizeof(name), &size);
if ( EVEN(sts)) goto return_now;
// Do a temporary rename all module object to avoid name collisions
#if 0
// Check that Slot attribute corresponds to the and module_oid
for ( unsigned int i = 1; i < ctx->attr->attrnav->dev_data.slot_data.size(); i++)
ctx->attr->attrnav->dev_data.slot_data[i]->module_oid = pwr_cNOid;
for ( sts = ldh_GetChild( ctx->ldhses, ctx->aref.Objid, &oid);
ODD(sts);
sts = ldh_GetNextSibling( ctx->ldhses, oid, &oid)) {
sts = ldh_ObjidToName( ctx->ldhses, oid, cdh_mName_object, name,
sizeof(name), &size);
if ( EVEN(sts)) goto return_now;
unsigned int *slotnumberp, slotnumber;
strcat( name, "__tmp");
sts = ldh_ChangeObjectName( ctx->ldhses, oid, name);
if ( EVEN(sts)) goto return_now;
sts = ldh_GetObjectPar( ctx->ldhses, oid, "RtBody",
"Slot", (char **)&slotnumberp, &size);
if ( EVEN(sts)) {
MsgWindow::message( 'E', "Not a Profinet module object", msgw_ePop_Yes, oid);
continue;
}
#endif
for ( unsigned int i = 1; i < ctx->attr->attrnav->dev_data.slot_data.size(); i++) {
GsdmlSlotData *slot = ctx->attr->attrnav->dev_data.slot_data[i];
pwr_tCid cid;
pwr_tOid prev;
pwr_tObjName mname;
int found = 0;
sprintf( mname, "M%d", slot->slot_idx);
slotnumber = *slotnumberp;
free( slotnumberp);
if ( cdh_ObjidIsNotNull( slot->module_oid)) {
// Find module object
sts = ldh_GetObjectClass( ctx->ldhses, slot->module_oid, &cid);
if ( ODD(sts)) {
if ( cid == slot->module_class) {
// Module object found and class is ok
found = 1;
// Check if name is changed
sts = ldh_ObjidToName( ctx->ldhses, slot->module_oid, cdh_mName_object, name,
sizeof(name), &size);
if ( EVEN(sts)) goto return_now;
#if 0
if ( strcmp( name, mname) != 0) {
// Change name
sts = ldh_ChangeObjectName( ctx->ldhses, slot->module_oid, mname);
if ( EVEN(sts)) goto return_now;
if ( slotnumber >= ctx->attr->attrnav->dev_data.slot_data.size()) {
MsgWindow::message( 'E', "Slot too large", msgw_ePop_Yes, oid);
continue;
}
#endif
// Check that sibling position is right
sts = ldh_GetPreviousSibling( ctx->ldhses, slot->module_oid, &prev);
if ( i == 0) {
// Should be first sibling
if ( ODD(sts)) {
// Move to first sibling
sts = ldh_MoveObject( ctx->ldhses, slot->module_oid, ctx->aref.Objid, ldh_eDest_IntoFirst);
}
}
else {
if ( (ODD(sts) &&
cdh_ObjidIsNotEqual( ctx->attr->attrnav->dev_data.slot_data[i-1]->module_oid, prev)) ||
EVEN(sts)) {
// Move to next to i-1
sts = ldh_MoveObject( ctx->ldhses, slot->module_oid,
ctx->attr->attrnav->dev_data.slot_data[i-1]->module_oid,
ldh_eDest_After);
}
}
if ( cdh_ObjidIsNotNull( ctx->attr->attrnav->dev_data.slot_data[slotnumber]->module_oid)) {
MsgWindow::message( 'E', "Slot already used", msgw_ePop_Yes, oid);
continue;
}
else {
// New class, delete current object, reuse the name
sts = ldh_ObjidToName( ctx->ldhses, slot->module_oid,
ldh_eName_Object, mname, sizeof(mname), &size);
if ( EVEN(sts)) goto return_now;
sts = ldh_DeleteObjectTree( ctx->ldhses, slot->module_oid, 0);
if ( EVEN(sts)) goto return_now;
}
}
}
if ( !found && slot->module_class != pwr_cNCid) {
// Create a new module object
if ( i == 1)
sts = ldh_CreateObject( ctx->ldhses, &slot->module_oid, mname, slot->module_class,
ctx->aref.Objid, ldh_eDest_IntoFirst);
else
sts = ldh_CreateObject( ctx->ldhses, &slot->module_oid, mname, slot->module_class,
ctx->attr->attrnav->dev_data.slot_data[i-1]->module_oid,
ldh_eDest_After);
if ( EVEN(sts)) {
printf( "Error creating module object, %d\n", sts);
sts = 0;
goto return_now;
}
}
if ( ctx->attr->attrnav->dev_data.slot_data[slotnumber]->module_class == pwr_cNCid)
// Should be removed
continue;
ctx->attr->attrnav->dev_data.slot_data[slotnumber]->module_oid = oid;
}
// Remove modules that wasn't configured any more
......@@ -287,6 +229,54 @@ int pndevice_save_cb( void *sctx)
for ( int i = 0; i < mcnt; i++)
sts = ldh_DeleteObjectTree( ctx->ldhses, moid[i], 0);
// Create new module objects
for ( unsigned int i = 0; i < ctx->attr->attrnav->dev_data.slot_data.size(); i++) {
GsdmlSlotData *slot = ctx->attr->attrnav->dev_data.slot_data[i];
if ( cdh_ObjidIsNull( slot->module_oid) && slot->module_class != pwr_cNCid) {
char mname[20];
sprintf( mname, "M%d", i);
if ( i == 1)
sts = ldh_CreateObject( ctx->ldhses, &slot->module_oid, mname, slot->module_class,
ctx->aref.Objid, ldh_eDest_IntoFirst);
else {
// Find sibling
pwr_tOid dest_oid = pwr_cNOid;
int dest_found = 0;
for ( int j = i - 1; j > 0; j--) {
if ( cdh_ObjidIsNotNull( ctx->attr->attrnav->dev_data.slot_data[j]->module_oid)) {
dest_oid = ctx->attr->attrnav->dev_data.slot_data[j]->module_oid;
dest_found = 1;
break;
}
}
if ( !dest_found)
sts = ldh_CreateObject( ctx->ldhses, &slot->module_oid, mname, slot->module_class,
ctx->aref.Objid, ldh_eDest_IntoFirst);
else
sts = ldh_CreateObject( ctx->ldhses, &slot->module_oid, mname, slot->module_class,
dest_oid, ldh_eDest_After);
}
if ( EVEN(sts)) {
MsgWindow::message( 'E', "Error creating module object", mname);
sts = 0;
goto return_now;
}
pwr_tAttrRef aaref;
pwr_tAttrRef modulearef = cdh_ObjidToAref( slot->module_oid);
// Set Slot
pwr_tUInt32 slotnumber = i;
sts = ldh_ArefANameToAref( ctx->ldhses, &modulearef, "Slot", &aaref);
if ( EVEN(sts)) goto return_now;
sts = ldh_WriteAttribute( ctx->ldhses, &aaref, &slotnumber, sizeof(slotnumber));
if ( EVEN(sts)) goto return_now;
}
}
for ( unsigned int i = 0; i < ctx->attr->attrnav->dev_data.slot_data.size(); i++) {
GsdmlSlotData *slot = ctx->attr->attrnav->dev_data.slot_data[i];
......@@ -810,12 +800,12 @@ pwr_tStatus pndevice_create_ctx( ldh_tSession ldhses, pwr_tAttrRef aref,
pwr_tStatus pndevice_init( device_sCtx *ctx)
{
pwr_tOid module_oid;
int corrupt = 1;
int corrupt = 0;
unsigned int idx;
pwr_tStatus sts;
// Identify module objects
#if 0
int size;
pwr_tObjName module_name;
......@@ -836,7 +826,7 @@ pwr_tStatus pndevice_init( device_sCtx *ctx)
}
ctx->attr->attrnav->dev_data.slot_data[idx]->module_oid = module_oid;
}
#endif
if ( corrupt) {
corrupt = 0;
......
......@@ -3840,7 +3840,7 @@ Volume Profibus $ClassVolume 0.0.250.7
Object RtBody $ObjBodyDef 1 21-APR-2009 13:41:08.17
Body SysBody 21-APR-2009 13:41:08.17
Attr StructName = "PnModule"
Attr NextAix = "_X22"
Attr NextAix = "_X23"
EndBody
!/**
! Description of this module.
......@@ -3873,6 +3873,17 @@ Volume Profibus $ClassVolume 0.0.250.7
EndBody
EndObject
!/**
! Slot number. Used by the Profinet configurator.
!*/
Object Slot $Attribute 22 09-DEC-2016 14:42:22.14
Body SysBody 09-DEC-2016 14:43:00.76
Attr PgmName = "Slot"
Attr Size = 40
Attr Flags = 1024
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
!/**
! @Summary Process that handles the module. Plc(1), rt_io_comm(2) or application process(4).
! Process that handles the module.
!
......
......@@ -628,7 +628,7 @@ usage()
{
cat << EOF
upgrade.sh Upgrade from V5.3.1 to V5.4.0
upgrade.sh Upgrade from V5.4 to V5.5
Pass
......@@ -636,7 +636,7 @@ usage()
savedirectory Save directory volume.
classvolumes Create loadfiles for classvolumes.
updateclasses Update classes.
cnvobjects Create OpPlaceWeb objects.
cnvobjects Update Profinet modules.
compile Compile all plcprograms in the database
createload Create new loadfiles.
buildnodes Build all nodes in the project.
......
!** Invisible: Script for to create OpPlaceWeb from WebHandler objects during upgrading from V5.3 to V5.4
!** Invisible: Script for upgrading Profinet modules during upgrading from V5.4 to V5.5
!
# Proview Open Source Process Control.
# Copyright (C) 2005-2016 SSAB EMEA AB.
......@@ -35,234 +35,102 @@
# General Public License plus this exception.
!
!
! Script to create OpPlaceWeb objects during upgrading from V5.3 to V5.4,
! Script for upgrading Profinet modules during upgrading from V5.4 to V5.5,
!
! Find all WebHandler objects and create an OpPlaceWeb.
! Sets the Slot attribute.
!
main()
string name;
string opname;
string aname;
string aopname;
string attrstr;
int attrint;
string child;
string prevchild;
string class;
string nchild;
string nclass;
int idx;
int sts;
verify(0);
name = GetClassListAttrRef("WebHandler");
while ( name != "")
function int is_numeric( string s)
string s1;
int ret = 0;
int len;
idx = strrchr( name, "-") - 1;
opname = extract( 1, idx, name);
opname = opname + "-OpWeb";
printf( "--\n");
printf( "-- Creating OpPlaceWeb object %s\n", opname);
printf( "--\n");
sts = CreateObject( "OpWeb", "OpPlaceWeb", name, 3);
if ( EVEN(sts))
printf( "** Unable to create object %s, sts %d\n", opname, sts);
quit
endif
s1 = extract( 1, 1, s);
aname = name + ".FileName";
aopname = opname + ".FileName";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
if ( s1 == "0" || s1 == "1" || s1 == "2" || s1 == "3" || s1 == "4" || s1 == "5" || s1 == "6" || s1 == "7" || s1 == "8" || s1 == "9")
ret = 1;
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
aname = name + ".Title";
aopname = opname + ".Title";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
len = strlen(s);
if ( len > 1)
s1 = extract( 2, 1, s);
if ( s1 == "0" || s1 == "1" || s1 == "2" || s1 == "3" || s1 == "4" || s1 == "5" || s1 == "6" || s1 == "7" || s1 == "8" || s1 == "9")
ret = 1;
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
return ret;
endfunction
aname = name + ".Text";
aopname = opname + ".Text";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
function int set_slot( string mclass)
string name;
string sname;
string snum;
int num;
string attr;
string parent;
string child;
aname = name + ".EnableLanguage";
aopname = opname + ".EnableLanguage";
attrint = GetAttribute( aname, sts);
sts = SetAttribute( aopname, attrint);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
verify(0);
aname = name + ".EnableLogin";
aopname = opname + ".EnableLogin";
attrint = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrint);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
name = GetClassList( mclass);
while ( name != "")
aname = name + ".EnableAlarmList";
aopname = opname + ".EnableAlarmList";
attrint = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrint);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
sname = CutObjectName( name, 1);
snum = extract( 2, 5, sname);
aname = name + ".EnableEventLog";
aopname = opname + ".EnableEventLog";
attrint = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrint);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
num = is_numeric( snum);
if ( num == 1)
aname = name + ".DisableHelp";
aopname = opname + ".DisableHelp";
attrint = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrint);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
num = snum;
aname = name + ".DisableProview";
aopname = opname + ".DisableProview";
attrint = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrint);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
aname = name + ".Language";
aopname = opname + ".Language";
attrint = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrint);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
attr = name + ".Slot";
SetAttribute( attr, num);
printf( "%s %d\n", name, num);
else
# Count siblings
parent = GetParent( name);
child = GetChild( parent);
num = 1;
while ( child != "")
if ( child == name)
attr = name + ".Slot";
SetAttribute( attr, num);
printf( "%s %d\n", name, num);
break;
endif
aname = name + ".StyleSheet";
aopname = opname + ".StyleSheet";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
child = GetNextSibling( child);
num++;
endwhile
endif
aname = name + ".StartURL";
aopname = opname + ".StartURL";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
name = GetNextObject( name);
aname = name + ".LoadArchives";
aopname = opname + ".LoadArchives";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
endwhile
return 1;
endfunction
aname = name + ".PwrHost";
aopname = opname + ".PwrHost";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
aname = name + ".AppletSignature";
aopname = opname + ".AppletSignature";
attrstr = GetAttribute( aname, sts);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aname);
endif
sts = SetAttribute( aopname, attrstr);
if ( EVEN(sts))
printf( "Attribute error: %s\n", aopname);
endif
main()
# Move WebGraph, WebLink, AppGraph and AppLink objects
child = GetChild( name);
prevchild = "";
while ( child != "")
class = GetObjectClass( child);
if ( class == "WebGraph" || class == "WebLink" || class == "AppGraph" || class == "AppLink")
MoveObject( child, opname, 2);
child = prevchild;
endif
if ( class == "$NodeHier")
nchild = GetChild( child);
if ( nchild != "")
nclass = GetObjectClass( nchild);
if ( nclass == "WebGraph" || nclass == "WebLink" || nclass == "AppGraph" || nclass == "AppLink")
MoveObject( child, opname, 2);
child = prevchild;
endif
endif
endif
prevchild = child;
if ( child == "")
child = GetChild( name);
else
child = GetNextSibling( child);
endif
endwhile
name = GetNextAttrRef( "WebHandler", name);
endwhile
save
set_slot( "PnModule");
set_slot( "BaseFcPPO3PnModule");
set_slot( "ABB_ACS880_PnModule");
set_slot( "Siemens_Di4_PnModule");
set_slot( "Siemens_Di2_PnModule");
set_slot( "Siemens_Do4_PnModule");
set_slot( "Siemens_Do2_PnModule");
set_slot( "Siemens_Di32_PnModule");
set_slot( "Siemens_D16_PnModule");
set_slot( "Siemens_Dx16_PnModule");
set_slot( "Siemens_Di8_PnModule");
set_slot( "Siemens_Do32_PnModule");
set_slot( "Siemens_Do16_PnModule");
set_slot( "Siemens_Do8_PnModule");
set_slot( "Siemens_Ai8_PnModule");
set_slot( "Siemens_Ai4_PnModule");
set_slot( "Siemens_Ai2_PnModule");
set_slot( "Siemens_Ao8_PnModule");
set_slot( "Siemens_Ao4_PnModule");
set_slot( "Sinamics_Tgm1_PnModule");
endmain
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