op_ima_obj_attr_get_str_sized()
Abstract
Obtains the value of a string attribute in the specified object, using a sized buffer.
Syntax
op_ima_obj_attr_get_str_sized (objid, attr_name, size_ptr, value_buffer)
| Argument | Type | Description |
|---|---|---|
objid |
Objid |
object ID of the object-of-interest [An object ID can be obtained from several KPs in the Topo and Id packages: op_id_self(), op_topo_parent(), op_topo_child(), op_id_from_userid(), and op_id_from_name().] |
attr_name |
const char * |
name of the attribute-of-interest [This attribute must be of type string and defined in the specified object, or an error will occur.] |
size_ptr |
size_t * |
On call, pointer to the size of value_buffer (including space for the ending '\0').On return, the actual size of the attribute value in value_buffer. |
value_buffer |
char * |
pointer to a variable to be filled with the specified attribute’s value (maximum length of value is size_ptr – 1 characters) |
Return Type
Compcode
OPC_COMPCODE_SUCCESS if the attribute value was successfully obtained; OPC_COMPCODE_FAILURE otherwise.
Example
{
char tx_nodename [128];
char * buffer_ptr;
size_t size;
Compcode status;
buffer_ptr = tx_nodename;
size = 128;
tx_nodeid = op_id_parent (op_td_get_int (pkptr, OPC_TDA_RA_TX_OBJID));
status = op_ima_obj_attr_get_str_sized (tx_nodeid, "name", &size, tx_nodename);
}
Details
This function is similar to op_ima_obj_attr_get_str(), except that it has a size argument and will not overrun value_buffer when returning the attribute value. For string attribute values that are larger than value_buffer, a truncated string is returned.
Purpose
Provides a mechanism to dynamically obtain object attributes during the course of the simulation. This KP works identically to op_ima_obj_attr_get(), but applies only to object attributes of data type string. Refer to op_ima_obj_attr_get() for full purpose and details.
Errors
- Same as op_ima_obj_attr_get(), plus the following:
- Program Abort: Attribute (
<name>) is of type (<type>). Can’t get its value as type (string).
Reference
- Use the KPs op_ima_obj_attr_set(), op_ima_obj_attr_set_dbl(), op_ima_obj_attr_set_int32(), op_ima_obj_attr_set_objid(), op_ima_obj_attr_set_str(), and op_ima_obj_attr_set_toggle() to assign a value to an object attribute
- Use the KP op_ima_obj_attr_get_str() to obtain the value of an object attribute of type string without specifying a buffer size
- Use the KP op_ima_obj_attr_get_dbl() to obtain the value of an object attribute of type double
- Use the KP op_ima_obj_attr_get_int32() to obtain the value of an object attribute of type integer
- Use the KP op_ima_obj_attr_get_objid() to obtain the value of an object attribute of type objid
- Use the KP op_ima_obj_attr_get_toggle() to obtain the value of an object attribute of type toggle
- Use the KPs op_ima_sim_attr_get(), op_ima_sim_attr_get_dbl(), op_ima_sim_attr_get_int32(), and op_ima_sim_attr_get_str() to obtain the value of a simulation attribute
- Use the KP op_ima_obj_svar_get() to obtain the value of a process state variable
- Use the KP op_ima_obj_command() to issue a command to an object
- Use the KP op_id_self() to obtain the object ID of the surrounding processor or queue
- Use the KP op_id_from_name() to obtain the object ID of an arbitrary object