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

Umwandlung STRUCT zu STRING

jauer
2021-10-27
2021-10-27
  • jauer - 2021-10-27

    Hallo zusammen,

    ich habe folgendes Problem:

    Ich möchte mehrere Fehlerfälle in meinem Programm definieren, die, wenn sie auftreten, mit Häufigkeit, Bezeichnung und Zeitstempel. Dazu habe ich eine Struktur erzeugt (siehe Screenshot), in der diese definiert sind. Tritt der Fehler auf, werden die passenden Werte in die Bestandteile der Structure geschrieben und in einem Array gespeichert.
    Allerdings habe ich das Problem, dass ich beim Schreiben des Arrays den Typ "Structure" nicht in einen String umwandeln kann, wenn ich es zusammengefügt über die CONCAT-Funktion, über die SysFile-Bibliothek in eine Textdatei speichern möchte.

    Vielleicht könnt ihr mir ja weiterhelfen. Danke für eure Antworten :)

     
  • jauer - 2021-10-27

    Hier noch der zugehörige Code:

    TYPE Struct_Error :
    STRUCT
    ErrorCount : INT;
    ErrorName : STRING;
    ActiveTime : TIME;
    TimeStamp : TIME;

    END_STRUCT
    END_TYPE


    {attribute 'qualified_only'}
    VAR_GLOBAL
    ec1_transmission_error : INT := 1;
    ec2_bit_op_error : INT := 2;
    ec3_integer_op_error : INT := 3;
    ec4_floating_op_error : INT := 4;
    ec5_RunTime_error : INT := 5;

    ec1_time                :   TIME := T#1MS;
    ec2_time                :   TIME := T#2MS;
    ec3_time                :   TIME := T#3MS;
    ec4_time                :   TIME := T#4MS;
    ec5_time                :   TIME := T#5MS;
    
    active_time             :   TIME := T#1M1S1MS;
    
    ec1_name                :   STRING  :=  'ec1_transmission_error';
    ec2_name                :   STRING  :=  'ec2_bit_op_error';
    ec3_name                :   STRING  :=  'ec3_integer_op_error';
    ec4_name                :   STRING  :=  'ec1_floating_op_error';
    ec5_name                :   STRING  :=  'ec1_RunTime_error';
    

    END_VAR


    FUNCTION_BLOCK FB_Struct_Error
    VAR_INPUT
    END_VAR
    VAR_OUTPUT
    END_VAR
    VAR
    StructArray : ARRAY[0..4] OF Struct_Error;
    END_VAR


    //init
    StructArray[0].ErrorCount := .GVL.ec1_transmission_error;
    StructArray[0].ErrorName := .GVL.ec1_name;
    StructArray[0].ActiveTime := .GVL.active_time;
    StructArray[0].TimeStamp := .GVL.ec1_time;

    StructArray[1].ErrorCount   :=  .GVL.ec2_bit_op_error;
    StructArray[1].ErrorName    :=  .GVL.ec2_name;
    StructArray[1].ActiveTime   :=  .GVL.active_time;
    StructArray[1].TimeStamp    :=  .GVL.ec2_time;
    
    StructArray[2].ErrorCount   :=  .GVL.ec3_integer_op_error;
    StructArray[2].ErrorName    :=  .GVL.ec3_name;
    StructArray[2].ActiveTime   :=  .GVL.active_time;
    StructArray[2].TimeStamp    :=  .GVL.ec3_time;
    
    StructArray[3].ErrorCount   :=  .GVL.ec4_floating_op_error;
    StructArray[3].ErrorName    :=  .GVL.ec4_name;
    StructArray[3].ActiveTime   :=  .GVL.active_time;
    StructArray[3].TimeStamp    :=  .GVL.ec4_time;
    
    StructArray[4].ErrorCount   :=  .GVL.ec5_RunTime_error;
    StructArray[4].ErrorName    :=  .GVL.ec5_name;
    StructArray[4].ActiveTime   :=  .GVL.active_time;
    StructArray[4].TimeStamp    :=  .GVL.ec5_time;
    _____________________________________________________________________________________
    
    Error: Typ 'ARRAY[0..4] OF Struct_Error' kann nicht in Typ 'STRING(255)' konvertiert werden
    
     

Log in to post a comment.