Commit 269cd605 authored by Claes Sjofors's avatar Claes Sjofors

Plc object EnumToStr added

parent 44ef941a
......@@ -444,3 +444,34 @@ void StoIpPtr_exec( plc_sThread *tp,
*o->Ptr = *o->InP;
}
/*_*
ENUMTOSTR
@aref enumtostr ENUMTOSTR
*/
void EnumToStr_init( pwr_sClass_EnumToStr *o)
{
if ( EVEN( gdh_GetEnumValueDef( o->TypeId, (gdh_sValueDef **)&o->EnumDefP, (int *)&o->EnumDefRows)))
o->EnumDefP = 0;
}
void EnumToStr_exec( plc_sThread *tp,
pwr_sClass_EnumToStr *o)
{
int i;
int found = 0;
if ( !o->EnumDefP)
return;
for ( i = 0; i < o->EnumDefRows; i++) {
if ( ((gdh_sValueDef *)o->EnumDefP)[i].Value->Value == *o->InP) {
strncpy( o->ActVal, ((gdh_sValueDef *)o->EnumDefP)[i].Value->Text, sizeof(o->ActVal));
found = 1;
break;
}
}
if ( !found)
strcpy( o->ActVal, "");
}
......@@ -28,7 +28,7 @@ SObject pwrb:Class
! @image orm_dtostr_fo.gif
!
! The DtoStr object converts the value of the digital input to
! at string stored in ActVal.
! a string stored in ActVal.
!
! Note that an erroneous format specification may cause the
! plcprogram to terminate. The size of the output of the conversion should
......
!
! Proview $Id: pwrb_c_dtostr.wb_load,v 1.9 2005-09-01 14:58:01 claes Exp $
! Copyright (C) 2005 SSAB Oxelsund AB.
!
! This program is free software; you can redistribute it and/or
! modify it under the terms of the GNU General Public License as
! published by the Free Software Foundation, either version 2 of
! the License, or (at your option) any later version.
!
! This program is distributed in the hope that it will be useful
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with the program, if not, write to the Free Software
! Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!
! pwrb_c_enumtostr.wb_load -- Defines the class EnumToStr.
!
SObject pwrb:Class
!/**
! @Version 1.0
! @Code rt_plc_io.c
! @Group Plc,PlcString,PlcConversion
! @Summary Convert enumeration value to string
! Convert enumeration value to string.
! @image orm_enumtostr_fo.png
!
! The EnumToStr object converts the value of the enumeration input to
! the associated string.
!
! The enumeration value can be fetched as an integer, eg with a GetIp
! connected to the input pin.
!
! The enumeration type is specified in the TypeId attribute.
!*/
Object EnumToStr $ClassDef 543
Body SysBody
Attr Editor = pwr_eEditor_PlcEd
Attr Method = pwr_eMethod_Connections
Attr PopEditor = 2
EndBody
Object RtBody $ObjBodyDef 1
Body SysBody
Attr StructName = "EnumToStr"
EndBody
!/**
! Emumeration input that will be converted to string.
!*/
Object In $Input 1
Body SysBody
Attr TypeRef = "pwrs:Type-$Int32"
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_RTVIRTUAL
Attr Flags |= PWR_MASK_NOEDIT
Attr Flags |= PWR_MASK_NOREMOVE
Attr GraphName = "In"
EndBody
EndObject
!/**
! Enumeration type id, eg pwrb:Type-PIDModeEnum.
!*/
Object TypeId $Intern 2
Body SysBody
Attr TypeRef = "pwrs:Type-$TypeId"
EndBody
EndObject
!/**
! Pointer to the enum definition.
!*/
Object EnumDefP $Intern 3
Body SysBody
Attr Flags |= PWR_MASK_POINTER
Attr Flags |= PWR_MASK_PRIVATE
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_NOEDIT
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
!/**
! Size of enum definition.
!*/
Object EnumDefRows $Intern 4
Body SysBody
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_NOEDIT
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
!/**
! Output that contains the string.
!*/
Object ActVal $Output 5
Body SysBody
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_NOEDIT
Attr TypeRef = "pwrs:Type-$String80"
Attr GraphName = "Val"
EndBody
EndObject
EndObject
Object DevBody $ObjBodyDef 2
Object PlcNode $Buffer 1
Body SysBody
Attr Class = pwr_eClass_PlcNode
Attr Flags |= PWR_MASK_INVISIBLE
EndBody
EndObject
EndObject
Object GraphPlcNode $GraphPlcNode
Body SysBody
Attr object_type = 11
Attr parameters[0] = 1
Attr parameters[1] = 3
Attr parameters[2] = 1
Attr parameters[3] = 0
Attr subwindows = 0
Attr graphmethod = 1
Attr graphindex = 0
Attr default_mask[0] = 1
Attr default_mask[1] = 1
Attr segname_annotation = 1
Attr compmethod = 35
Attr compindex = 0
Attr tracemethod = 0
Attr traceindex = 0
Attr executeordermethod = 2
Attr objname = "EnumToStr"
Attr graphname = "EnumToStr"
EndBody
EndObject
Object Template EnumToStr
Body RtBody
EndBody
EndObject
EndObject
EndSObject
......@@ -874,6 +874,7 @@ palette PlcEditorPalette
class DtoEnum
class DtoStr
class EnumToD
class EnumToStr
class Float64ToA
class Gray
class Int64toI
......
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