Problems defintion String In C#

Hello everyone,
I’m encountering difficulties with defining a string variable in C# within Visual Studio and PLCnext Engineer.
The issue seems to be specific to PLCnext Engineer. While the build process in Visual Studio completes without errors, I encounter error codes when attempting to build it in PLCnext Engineer (as shown in the attached picture). I’m unsure about the appropriate steps to resolve this.
Could someone please offer assistance with this matter?

Kind regards

Daan van der Veeken

image.png
/*
PLCDataCheck Function Block - V1
Gemaakt op: 9-3-2024
Laatste update: 9-3-2024 om 15:04
Ontwikkelaar: Daan van der Veeken (DMF), I-sago

Beschrijving:
Deze Function Block controleert een stringinput en geeft een stringoutput
wanneer bepaalde condities zijn voldaan (zoals het ontvangen signaal hoog is).
Het houdt ook bij of het proces succesvol is en geeft foutcodes terug indien
van toepassing.

Bug Fix List:

  • [Datum] Beschrijving van de bug en oplossing
    */

using Iec61131.Engineering.Prototypes.Common;
using Iec61131.Engineering.Prototypes.Methods;
using Iec61131.Engineering.Prototypes.Pragmas;
using Iec61131.Engineering.Prototypes.Types;
using Iec61131.Engineering.Prototypes.Variables;
using System;
using System.Iec61131Lib;
using System.Runtime.InteropServices;

namespace PLCnextFirmwareLibrary1
{
// Definieer een aangepaste string structuur
[String(512)]
[StructLayout(LayoutKind.Explicit, Size = 518)]
public struct TString
{
[FieldOffset(0)]
public IecStringEx s;

public void Init()
{
s.maximumLength = 512;
s.Empty();
}
}

[FunctionBlock]
public class PLCDataCheck
{
[Input]
public TString InputString; // Aangepaste string input

[Input]
public bool Ontvangen; // Signaal of data is ontvangen

[Input]
public bool Reset; // Reset input

[Output]
public TString OutputString; // Aangepaste string output

[Output]
public bool Succesvol; // Aanduiding of proces succesvol is

[Output]
public bool Error; // Fout indicator

[Output, DataType(„DINT“)]
public int ErrorID; // Foutcode

[Initialization]
public void __Init()
{
InputString.Init();
OutputString.Init();
Succesvol = false;
Error = false;
ErrorID = 0;
}

[Execution]
public void __Process()
{
if (Reset)
{
Succesvol = false;
OutputString.Init();
return;
}

if (Ontvangen)
{
if (!InputString.s.IsEmpty)
{
IecStringEx.Copy(ref InputString.s, ref OutputString.s);
Succesvol = true;
Error = false;
ErrorID = 0;
}
else
{
Error = true;
ErrorID = 500; // Foutcode voor lege input
Succesvol = false;
}
}
}
}
}

Hello.
Are the error messages correct? Are the data types of the variables and the FB parameters different?
In the „Variables“ sheet for the program „Main“, the data types of the two variables ParametersSchoonmaak and Parameters should be PLCnextFirmwareLibrary1.TString, not TString.
I am using PLCnext Engineer version 2024.0 and this works OK.

Actually, I have now managed to reproduce this error in my previously working example.
I will need to check this with the PLCnext Engineer support team.

Hello

I am currently utilizing version 2023.6. I have made adjustments to the variables to incorporate PLCnextFirmwareLibrary1.TString. However, I am encountering persistent issues. Do I need to configure something within the data types?"

image.pngimage.png

Hello.</p>Are the error messages correct? Are the data types of the variables and the FB parameters different?</p>In the „Variables“ sheet for the program „Main“, the data types of the two variables ParametersSchoonmaak<\/code> and Parameters</code> should be PLCnextFirmwareLibrary1.TString<\/code>, not TString</code>.</p>I am using PLCnext Engineer version 2024.0 and this works OK.</p>

No, that looks OK.
It worked once for me, but now I am getting the same errors as you.
I will need to check this with the PLCnext Engineer support team.

do you have any update on the STRING definition in c# and visual studios.

I’ve asked the PLCnext Engineer support team to analyse this problem. I have confirmed that the same problem occurs in PLCnext Engineer version 2024.0.2, and I have also given them that information. I’ll send them a reminder on Monday.

Sorry for the continued delay. I am sending daily reminders to the PLCnext Engineer support team, but there is no progress to report.

Thank you for your effort and time in this case.

For some reason I eventuelly found a solution for my problem. Now i can use more characters in my string variable, and it works fine. This is my new code:

using Iec61131.Engineering.Prototypes.Common;
using Iec61131.Engineering.Prototypes.Methods;
using Iec61131.Engineering.Prototypes.Types;
using Iec61131.Engineering.Prototypes.Variables;
using System.Iec61131Lib;
using System.Runtime.InteropServices;

namespace PLCnextFirmwareLibrary1
{
/// summary
/// C# functie die controlles uitvoert of Python code succesvol de STRING variabele in de PLC heeft geschreven met een maximale lengte van 512 characters.
/// Versie: 1.0.0
/// Gemaakt op: 19-03-2024
/// @auteur: Daan van der Veeken
/// summary
/// Updates

/// Updates

[String(512)]
[StructLayout(LayoutKind.Explicit, Size = 518)]
public struct TString512
{
// Velden
[FieldOffset(0)]
public IecStringEx s; // Dit lid moet de naam ‚s‘ hebben omdat de naam wordt geëvalueerd door PLCnext Engineer!

// Methoden
///


/// Initialiseert de structuur en stelt de maximale grootte in op 512 tekens.
///

public void Init()
{
s.maximumLength = 512;
s.Empty();
}
}

///


/// Function block voor het controleren van PLC-data.
///

[FunctionBlock]
public class PLCDataCheck
{
// Ingangen
[Input]
public TString512 ParametersString; // Input string van maximaal 512 tekens.

[Input]
public bool Ontvangen; // krijgt een signaal vanuit python dat volgens python de STRING geschreven is in de PLC variabele. Activeert daarnaast de functie.

[Input]
public bool Reset; // reset functie om alle variabelen te resetten + foutcode te verwijderen.

// Uitgangen
[Output]
public bool ValidParameter; // Geeft aan of Parameters een geldige waarde bevat en succesvolis geschreven.

[Output]
public bool Error; // Geeft aan of er een probleem is met de string of wanneer deze leeg is als de fuctie wordt geactiveerd.

[Output]
public short ErrorID; // Geeft de errorID aan voor het controleren waar het probeem zit.

// Initialisatie methode
[Initialization]
public void __Init()
{
ValidParameter = false;
Error = false;
ErrorID = 0;

// Roep de Init() methode aan op het ParametersString veld.
ParametersString.Init();
}

// Uitvoering methode
[Execution]
public void __Process()
{
if (Reset) // Reset alle variabelen terug naar FALSE.
{
ValidParameter = false;
Error = false;
ErrorID = 0;
}
else if (Ontvangen) // Wannner ontvangen TRUE is, controleert de code of de waarde geschreven is
{
if (ParametersString.s.currentLength == 0) // Wanneer STRING variabele leeg is, geef dan een error en foutmelding weer. ValidParameters blijft leeg.
{
ValidParameter = false;
Error = true;
ErrorID = 500; // Foutcode voor lege string
}
else // Als variabele succesvol is geschreven en onder 512-Charachter is, dan is ValidParameter TRUE.
{
ValidParameter = true;
Error = false;
ErrorID = 0;
}
}
}
}
}

still i don’t know what i did, but maybe the support team will find out with the new information.

Kind regards,

Daan van der Veeken