Please, help to make dession to chose Go (interesting case))

I am building PLC IDE. Traditionally PLC is programmed with one of the 5 IEC 61131-3 standard languages. My IDE will support only one of those which is ST (Structured Text) that looks like Pascal and actually based on it.

There is no ST compilers or interpreter out there. Only privately owned by companies like 3S (Codesys), Siemens, … My first idea was to transpile ST program to C/C++, then I thought about transpiling it to nodejs. But recently I investigated GO and it looks like a perfect candidate.

I know that for most of you, one example may tell about a language more than long article so here is and example how ST program might look like

TYPE Shelf :
STRUCT
	TemperatureIN:     POINTER TO WORD;
	Temperature:       INT;
	TemperatureHMI:    POINTER TO WORD;
	TemperatureStatus: POINTER TO BYTE;
	OutByte:           POINTER TO WORD;
	ByteNum:           USINT;
	Correction:        POINTER TO WORD;
END_STRUCT
END_TYPE

FUNCTION_BLOCK TON_M
    VAR_INPUT
    	IN: BOOL;
    	PT: TIME;
    	RS: BOOL;
    END_VAR
    VAR_OUTPUT
    	Q: BOOL;
    	TP: WORD;
    	TW: TIME;
    END_VAR
    VAR
    	TON1: TON;
    	SR1: SR;
    	RT1:R_TRIG;
    	TimeWorked : TIME;
    	xProcess :BOOL;
    END_VAR

    IF pt = T#0S THEN
    	Q := TRUE;
    	RETURN;
    END_IF

    IF RS OR (TimeWorked > PT) THEN
    	TimeWorked := T#0S;
    	TON1(IN := FALSE);
    	RETURN;
    END_IF

    IF NOT TON1.Q AND NOT IN THEN
    	TimeWorked := TimeWorked + TON1.ET;
    END_IF

    TON1(IN := IN, PT := SEL(IN, T#0MS, PT - TimeWorked), Q => Q);

    TW := TimeWorked + TON1.ET;
    TP := REAL_TO_WORD(TIME_TO_REAL(TW) * 100.0 / TIME_TO_REAL(PT));
END_FUNCTION_BLOCK

So, my question, am I on the right track of using GO?

There PLC Runtime later might be based on Linux or perhaps based on simply STM32 chip (but this is not likely) primarily it is developed to run on Linux based PLC as hardware as softPLCs on online servers.

Would it be a smart choice to select GO?

Another thing that I’ll have to have in online monitoring. It is when I can run code and see what variables what values have as it is right now in PLC. But that is eventually but not now.

Hello,

Not a direct answer to your question but i’d use. I am using go to communicate with plcs. I have modbus tcp and s7 libraries which i am using for web based data acquisition applications. Go makes it easy for me to communicate with devices and publish data via http server.

1 Like

Code generation with go is a thing and more or less build in. Go has a templating engine so you can define some structure and fill in the blanks using logic (or other templates). If anything I’d look in that direction.
I think everyone in here will agree go is a good fit for almost everything :slightly_smiling_face: So that’s probably the wrong question to ask - whether Go is a good candidate for this task.

So it will be relatively simple yo use GO to transpil or generate GO programm from ST script?

Okay, let me be honest. I thought you wanted to generate ST, which, to me, is a far less daunting task! :slight_smile:

I’ve never used it and I’m not sure if it’s the right tool for the job, but you might be able to utilize the “go” package to compile ST as Go. But I’m out of my comfort zone here!

Me either. That is why I ask. May be I was nt clear but I want users to write PLC program using ST, but when they compile it, I want to transpilу it to Go and then compile. Because thought to create ST compiler is even more scary to me.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.