Commit a92222b5 authored by Claes Sjofors's avatar Claes Sjofors

wb command GetIoDeviceData and SetIoDeviceData added

parent 879fc238
......@@ -255,6 +255,97 @@ int GsdmlDeviceData::paste_slot( unsigned int slot_idx)
return PB__SUCCESS;
}
int GsdmlDeviceData::modify_value( const char *attr, const char *value)
{
char attrvect[10][80];
int num;
int ival, num2;
num = dcli_parse( attr, "-", "", (char *)attrvect,
sizeof( attrvect) / sizeof( attrvect[0]), sizeof( attrvect[0]), 0);
if ( strcmp( attrvect[0], "NetworkSettings") == 0) {
if ( num < 2)
return 0;
if ( strcmp( attrvect[1], "DeviceName") == 0)
strncpy( device_name, value, sizeof(device_name));
else if ( strcmp( attrvect[1], "IP Address") == 0)
strncpy( ip_address, value, sizeof(ip_address));
else if ( strcmp( attrvect[1], "Subnet Mask") == 0)
strncpy( subnet_mask, value, sizeof(subnet_mask));
else if ( strcmp( attrvect[1], "MAC Address") == 0)
strncpy( mac_address, value, sizeof(mac_address));
else if ( strcmp( attrvect[1], "SendClock") == 0) {
num2 = sscanf( value, "%d", &ival);
if ( num2 != 1)
return 0;
for ( unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->send_clock_factor = ival;
}
else if ( strcmp( attrvect[1], "ReductionRatio") == 0) {
num2 = sscanf( value, "%d", &ival);
if ( num2 != 1)
return 0;
for ( unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->reduction_ratio = ival;
}
else if ( strcmp( attrvect[1], "Phase") == 0) {
num2 = sscanf( value, "%d", &ival);
if ( num2 != 1)
return 0;
for ( unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->phase = ival;
}
else if ( strcmp( attrvect[1], "API") == 0) {
num2 = sscanf( value, "%d", &ival);
if ( num2 != 1)
return 0;
for ( unsigned int i = 0; i < iocr_data.size(); i++)
iocr_data[i]->api = ival;
}
else
return 0;
}
else
return 0;
return 1;
}
int GsdmlDeviceData::get_value( const char *attr, char *buf, int bufsize)
{
char attrvect[10][80];
int num;
num = dcli_parse( attr, "-", "", (char *)attrvect,
sizeof( attrvect) / sizeof( attrvect[0]), sizeof( attrvect[0]), 0);
if ( strcmp( attrvect[0], "NetworkSettings") == 0) {
if ( num < 2)
return 0;
if ( strcmp( attrvect[1], "DeviceName") == 0)
strncpy( buf, device_name, bufsize);
else if ( strcmp( attrvect[1], "IP Address") == 0)
strncpy( buf, ip_address, bufsize);
else if ( strcmp( attrvect[1], "Subnet Mask") == 0)
strncpy( buf, subnet_mask, bufsize);
else if ( strcmp( attrvect[1], "MAC Address") == 0)
strncpy( buf, mac_address, bufsize);
else if ( strcmp( attrvect[1], "SendClock") == 0)
snprintf( buf, bufsize, "%d", iocr_data[0]->send_clock_factor);
else if ( strcmp( attrvect[1], "ReductionRatio") == 0)
snprintf( buf, bufsize, "%d", iocr_data[0]->reduction_ratio);
else if ( strcmp( attrvect[1], "Phase") == 0)
snprintf( buf, bufsize, "%d", iocr_data[0]->phase);
else if ( strcmp( attrvect[1], "API") == 0)
snprintf( buf, bufsize, "%d", iocr_data[0]->api);
else
return 0;
}
else
return 0;
return 1;
}
int GsdmlDataReader::tag_name_to_id( const char *name, unsigned int *id)
{
if ( strcmp( name, "PnDevice") == 0)
......
......@@ -174,6 +174,8 @@ class GsdmlDeviceData {
int copy_slot( unsigned int slot_idx);
int cut_slot( unsigned int slot_idx);
int paste_slot( unsigned int slot_idx);
int modify_value( const char *attr, const char *value);
int get_value( const char *attr, char *buf, int bufsize);
};
class GsdmlDataReader : public co_xml_interpreter {
......
......@@ -136,6 +136,59 @@ static pwr_tStatus SyntaxCheck (
return wsx_CheckIoDevice( Session, Object, ErrorCount, WarningCount, wsx_mCardOption_None);
}
//
// Get value.
//
static pwr_tStatus GetIoDeviceData (
pwr_tAttrRef Object,
const char *Attr,
char *Buf,
int BufSize
) {
pwr_tFileName datafile;
pwr_tStatus sts;
sprintf( datafile, "$pwrp_load/pwr_pn_%s.xml", id_to_string( Object.Objid));
dcli_translate_filename( datafile, datafile);
GsdmlDeviceData *data = new GsdmlDeviceData();
sts = data->read( datafile);
if ( EVEN(sts)) return sts;
sts = data->get_value( Attr, Buf, BufSize);
delete data;
return sts;
}
static pwr_tStatus SetIoDeviceData (
pwr_tAttrRef Object,
const char *Attr,
const char *Value
) {
pwr_tFileName datafile;
pwr_tStatus sts;
sprintf( datafile, "$pwrp_load/pwr_pn_%s.xml", id_to_string( Object.Objid));
dcli_translate_filename( datafile, datafile);
GsdmlDeviceData *data = new GsdmlDeviceData();
sts = data->read( datafile);
if ( EVEN(sts)) return sts;
sts = data->modify_value( Attr, Value);
if ( ODD(sts))
data->print( datafile);
delete data;
return sts;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
......@@ -144,6 +197,8 @@ pwr_dExport pwr_BindMethods(PnDevice) = {
pwr_BindMethod(Configure),
pwr_BindMethod(ConfigureFilter),
pwr_BindMethod(SyntaxCheck),
pwr_BindMethod(GetIoDeviceData),
pwr_BindMethod(SetIoDeviceData),
pwr_NullMethod
};
......
......@@ -9139,6 +9139,8 @@ PromptDialog() <LINK> promptdialog()
OpenGraph() <LINK> opengraph()
CloseGraph() <LINK> closegraph()
SetSubwindow() <LINK> setsubwindow()
GetIoDeviceData() <LINK> getiodevicedata()
SetIoDeviceData() <LINK> setiodevicedata()
</TOPIC>
<TOPIC> execute script
......@@ -10463,10 +10465,82 @@ string <t>windowname <t>Name of the window object in which
string <t>source <t>Name of the graph that is to be opened
<t> <t>in the window object.
int <t>modal <t>Modal.
<b>Exempel
<b>Example
<c> SetSubwindow( "pwr_wizard_frame", "Window1", "MyGraph", 1);
</TOPIC>
<TOPIC> getiodevicedata() <style> function
GetIoDeviceData()
int GetIoDeviceData( string object, string parameter, string value)
<b>Description
Get data from IO configuration.
Returns status of operation, odd if success and even is error.
This command uses methods and has to be executed in pwrs. It does not
work in pwrc.
The supported parameters for Profinet devices are
NetworkSettings-DeviceName
NetworkSettings-IP Address
NetworkSettings-Subnet Mask
NetworkSettings-MAC Address
NetworkSettings-SendClock
NetworkSettings-ReductionRatio
NetworkSettings-Phase
NetworkSettings-API
<b>Argument
string <t>object <t>Name device object.
string <t>parameter <t>Parameter name for data.
string <t>value <t>Returned parameter value.
<b>Example
<c> sts = SetIoDeviceData( "Nodes-MyNode-PN-D1", "NetworkSettings-DeviceName", "ET200M-D1");
</TOPIC>
<TOPIC> setiodevicedata() <style> function
SetIoDeviceData()
int SetIoDeviceData( string object, string parameter, string value)
<b>Description
Set data from IO configuration.
Returns status of operation, odd if success and even is error.
This command uses methods and has to be executed in pwrs. It does not
work in pwrc.
The supported parameters for Profinet devices are
NetworkSettings-DeviceName
NetworkSettings-IP Address
NetworkSettings-Subnet Mask
NetworkSettings-MAC Address
NetworkSettings-SendClock
NetworkSettings-ReductionRatio
NetworkSettings-Phase
NetworkSettings-API
<b>Argument
string <t>object <t>Name device object.
string <t>parameter <t>Parameter name for data.
string <t>value <t>Value to set.
<b>Example
<c> sts = SetIoDeviceData( "Nodes-MyNode-PN-D1", "NetworkSettings-DeviceName", "ET200M-D1");
</TOPIC>
</chapter>
......
......@@ -84,6 +84,8 @@ typedef pwr_tStatus (* wb_tMethodAnteUnadopt)(ldh_tSesContext, pwr_tOid, pwr_tOi
typedef pwr_tStatus (* wb_tMethodPostUnadopt)(ldh_tSesContext, pwr_tOid, pwr_tOid, pwr_tCid);
typedef pwr_tStatus (* wb_tMethodPostRename) (ldh_tSesContext, pwr_tOid);
typedef pwr_tStatus (* wb_tMethodSyntaxCheck)(ldh_tSesContext, pwr_tAttrRef, int *, int *);
typedef pwr_tStatus (* wb_tMethodGetIoDeviceData)(pwr_tAttrRef, const char *, char *, int);
typedef pwr_tStatus (* wb_tMethodSetIoDeviceData)(pwr_tAttrRef, const char *, const char *);
#if defined OS_VMS
......
......@@ -5972,6 +5972,141 @@ static int wnav_ccm_errormessage_func( char *msg, int severity, void *client_dat
return 1;
}
static int wnav_getiodevicedata_func(
void *filectx,
ccm_sArg *arg_list,
int arg_count,
int *return_decl,
ccm_tFloat *return_float,
ccm_tInt *return_int,
char *return_string)
{
WNav *wnav;
pwr_tStatus sts;
char method_name[80];
wb_tMethod method;
ccm_sArg *arg_p2;
ccm_sArg *arg_p3;
pwr_tAttrRef aref;
if ( arg_count != 3)
return CCM__ARGMISM;
arg_p2 = arg_list->next;
arg_p3 = arg_p2->next;
if ( arg_list->value_decl != CCM_DECL_STRING)
return CCM__VARTYPE;
if ( arg_p2->value_decl != CCM_DECL_STRING)
return CCM__VARTYPE;
if ( arg_p3->value_decl != CCM_DECL_STRING)
return CCM__VARTYPE;
wnav_get_stored_wnav( &wnav);
sts = wnav_wccm_get_ldhsession_cb( wnav, &wnav->ldhses);
try {
wb_name n( arg_list->value_string);
if ( !n)
sts = n.sts();
else {
wb_session *sp = (wb_session *)wnav->ldhses;
wb_attribute a = sp->attribute( n);
if ( !a)
sts = a.sts();
else {
wb_vrep *vrep = ((wb_orep *)a)->vrep();
// Call object method, or inherited method TODO
for ( wb_cdef cd = sp->cdef( a.tid()); cd; cd = cd.super()) {
sprintf( method_name, "%s-GetIoDeviceData", cd.name());
vrep->erep()->method(&sts, method_name, &method);
if ( ODD(sts)) {
aref = a.aref();
sts = ((wb_tMethodGetIoDeviceData) (method))( aref, arg_p2->value_string,
arg_p3->value_string, K_STRING_SIZE);
arg_p3->value_returned = 1;
break;
}
}
}
}
}
catch ( wb_error &e) {
sts = e.sts();
}
*return_decl = CCM_DECL_INT;
*return_int = sts;
return 1;
}
static int wnav_setiodevicedata_func(
void *filectx,
ccm_sArg *arg_list,
int arg_count,
int *return_decl,
ccm_tFloat *return_float,
ccm_tInt *return_int,
char *return_string)
{
WNav *wnav;
pwr_tStatus sts;
char method_name[80];
wb_tMethod method;
ccm_sArg *arg_p2;
ccm_sArg *arg_p3;
pwr_tAttrRef aref;
if ( arg_count != 3)
return CCM__ARGMISM;
arg_p2 = arg_list->next;
arg_p3 = arg_p2->next;
if ( arg_list->value_decl != CCM_DECL_STRING)
return CCM__VARTYPE;
if ( arg_p2->value_decl != CCM_DECL_STRING)
return CCM__VARTYPE;
if ( arg_p3->value_decl != CCM_DECL_STRING)
return CCM__VARTYPE;
wnav_get_stored_wnav( &wnav);
sts = wnav_wccm_get_ldhsession_cb( wnav, &wnav->ldhses);
try {
wb_name n( arg_list->value_string);
if ( !n)
sts = n.sts();
else {
wb_session *sp = (wb_session *)wnav->ldhses;
wb_attribute a = sp->attribute( n);
if ( !a)
sts = a.sts();
else {
wb_vrep *vrep = ((wb_orep *)a)->vrep();
// Call object method, or inherited method TODO
for ( wb_cdef cd = sp->cdef( a.tid()); cd; cd = cd.super()) {
sprintf( method_name, "%s-SetIoDeviceData", cd.name());
vrep->erep()->method(&sts, method_name, &method);
if ( ODD(sts)) {
aref = a.aref();
sts = ((wb_tMethodSetIoDeviceData) (method))( aref, arg_p2->value_string,
arg_p3->value_string);
break;
}
}
}
}
}
catch ( wb_error &e) {
sts = e.sts();
}
*return_decl = CCM_DECL_INT;
*return_int = sts;
return 1;
}
int wnav_externcmd_func( char *cmd, void *client_data)
{
WNav *wnav = (WNav *) client_data;
......@@ -6035,6 +6170,10 @@ int WNav::readcmdfile( char *incommand)
if ( EVEN(sts)) return sts;
sts = ccm_register_function( "SetSubwindow", wnav_setsubwindow_func);
if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetIoDeviceData", wnav_getiodevicedata_func);
if ( EVEN(sts)) return sts;
sts = ccm_register_function( "SetIoDeviceData", wnav_setiodevicedata_func);
if ( EVEN(sts)) return sts;
ccm_func_registred = 1;
......
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