CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Fri Oct 19, 2018 4:14 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Get string from enum
PostPosted: Thu Sep 20, 2018 2:02 pm 
Offline

Joined: Mon Jan 08, 2018 6:44 pm
Posts: 10
Hi forum,

there is a way to obtain the string of enum variables?

example:

I have this enum:
Code:
TYPE PLC_LOG_DEVICE :
(
   NONE := 0,
   
   MANDREL  := 1,
   CLAMP   := 2,
   STORE   := 3,
   
   
   LAST_DEVICE
);
END_TYPE


How can I assign to a string the value "MANDREL", "CLAMP", etc. based on enum value?

I tried to search something about and I found this https://forum.codesys.com/viewtopic.php?f=11&t=5955 but I cannot start the project, it cannot find the "sys shm library" and I don't understand how to solve this.


Top
   
 Post subject: Re: Get string from enum
PostPosted: Thu Sep 20, 2018 5:00 pm 
Offline

Joined: Thu Mar 17, 2016 1:24 pm
Posts: 94
In SP11 or higher:

Code:
{attribute 'to_string'}
TYPE PLC_LOG_DEVICE :
(
   NONE := 0,
   
   MANDREL  := 1,
   CLAMP   := 2,
   STORE   := 3,
   
   
   LAST_DEVICE
);
END_TYPE


Code:
sVar: STRING;
eVar: PLC_LOG_DEVICE;

sVar := TO_STRING(eVar);


Top
   
 Post subject: Re: Get string from enum
PostPosted: Fri Sep 21, 2018 1:58 pm 
Offline

Joined: Mon Jan 08, 2018 6:44 pm
Posts: 10
e.kislov wrote:
In SP11 or higher:

Code:
{attribute 'to_string'}
TYPE PLC_LOG_DEVICE :
(
   NONE := 0,
   
   MANDREL  := 1,
   CLAMP   := 2,
   STORE   := 3,
   
   
   LAST_DEVICE
);
END_TYPE


Code:
sVar: STRING;
eVar: PLC_LOG_DEVICE;

sVar := TO_STRING(eVar);



THANKS A LOT


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 3 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited