Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

convert string to actual io?

sarathbabu
2014-07-04
2014-07-09
  • sarathbabu - 2014-07-04

    Hi

    am trying to convert string to an Io

    eg heatertemperature %iw23 real

    check:=concat('heater'+'temperarture')
    check2:=string_to_real(check2);

    Is it possible?

     
  • shooter - 2014-07-06

    you have a WORD not a REAL coming from the inputcard.
    there are no direct inputs with real.
    conversion is possible with word_to_real (value is 10 times the measured value)
    so your setpoint is a real, not a string.
    and you can not have 1 var (check2) double declared

     
  • sarathbabu - 2014-07-07

    well then for bool

    eg heateron: bool(This boolean not from hardware)

    check:=concat('heater'+'on')
    check2:=string_to_real(check2);

    Is it possible?

     
  • shooter - 2014-07-07

    so
    check :STRING(30):='23.45';
    check2:REAL;

    use oscat.de FLOAT_TO_REAL function
    check2:=FLOAT_TO_REAL(check);
    however no output is in real, but you can use REAL_TO_WORD.

    in boolean it is simpler
    IF (check= '23.45') THEN heateron:=TRUE;END_IF

     
  • sarathbabu - 2014-07-08

    Is there no way to convert a string to the desired variable name we declare no matter what sort of declaration it is

    for eg: r_codesys:real;
    b_codesys:bool;
    i_codesys:int;

    string_to_real('r_codesys')
    string_to_bool('b_codesys')
    string_to_int('i_codesys')

    is not the above things possible?

    Are need to write my own code to make it work like this?

     
  • shooter - 2014-07-08

    NO, you can not make variablenames inside your code, as the code is compiled all this info is lost again.

    however you can make a automatic declarationtable (in any textmaker like NPP).
    sorry for the misunderstanding.

    what are you trying to do?
    look for data types here you can make types and structures

     
  • sarathbabu - 2014-07-08

    Actually I want to use

    Test1:bool
    Test2:bool
    Test3:bool

    to

    for i=1 t0 3
    test:=concat('Test'+int_to_string('i'))
    end_for

    i do not want to use if else statement

    its compiling yet am not seeing any output

     
  • shooter - 2014-07-08

    no what you are trying is not possible, however you can use an array if it are a lot of bools.
    like test[1]:=true;
    etc.
    but you have to make it in advance as it is impossible to change the variable list in a running program

    however i/o must be in global list with all %QX0.0 in writing.
    (you can automate this with a textmaker.

     
  • sarathbabu - 2014-07-09

    Am gonna create a function to do this stuff

    Thanks

     

Log in to post a comment.