Hi everyone,
I’m trying to create a function block using the snfunctionblock template in the plcncli. This function block has a method that returns a string. I have done the following steps:
- create snproject using the template in the plcncli
- create a snfunctionblock with the plcncli
- add the method to the c# class:
using System;
using System.Iec61131Lib;
using System.Runtime.InteropServices;
using Eclr;
using Iec61131.Engineering.Prototypes.Types;
using Iec61131.Engineering.Prototypes.Variables;
using Iec61131.Engineering.Prototypes.Methods;
using Iec61131.Engineering.Prototypes.Common;
using Iec61131.Engineering.Prototypes.Pragmas;
namespace FetchMessageProject
{
[Native]
[FunctionBlock]
public class FBFetchMessage
{
[Initialization]
public void __Init()
{}
[Execution]
public void __Process()
{}
[User, DataType("STRING")]
public IecStringEx GetNewMessage(){ return new IecStringEx(); /*placeholder to suppress compiler warning*/}
}
}
- add the function to both headers:
class FBFetchMessage : public Object
{
// @Begin automatically generated code, do not modify inside @Begin/@End comment pair !
public:
void __Init();
void __Process();
FBFetchMessage();
void ctor();
// @End automatically generated code
// insert additional private methods and member here !
pcoslib::IecStringEx GetNewMessage();
};
- add the function to the .cpp file:
pcoslib::IecStringEx FetchMessageProject::FBFetchMessage::GetNewMessage()
{
FixedString<80> placeholder("Placeholder");
return placeholder;
}
- generate the code
- build and deploy the projec
When importing the library into Plcnext Engineer, I get a ‘CILG0001 Internal Error’. I have also tried using IecString80 instead of IecStringEx, but that also produces the error. What am I doing wrong? I’m on Engineer 2026.3.
Thanks in advance,
Lars