Commit 8e01fe95 authored by Ivan Tyagov's avatar Ivan Tyagov

First OPC-Ua POC controling 4 relays from Beremiz.

parent edbdca82
......@@ -3,3 +3,6 @@ __LOCATED_VAR(BOOL,__QX0_0_1_1,Q,X,0,0,1,1)
__LOCATED_VAR(BOOL,__QX0_0_2_2,Q,X,0,0,2,2)
__LOCATED_VAR(BOOL,__QX0_0_3_3,Q,X,0,0,3,3)
__LOCATED_VAR(DINT,__QD1_0,Q,D,1,0)
__LOCATED_VAR(DINT,__QD1_1,Q,D,1,1)
__LOCATED_VAR(DINT,__QD1_2,Q,D,1,2)
__LOCATED_VAR(DINT,__QD1_3,Q,D,1,3)
......@@ -214,6 +214,9 @@ void COUNTERST_init__(COUNTERST *data__, BOOL retain) {
__INIT_EXTERNAL(BOOL,RELAY2VALUE,data__->RELAY2VALUE,retain)
__INIT_EXTERNAL(BOOL,RELAY3VALUE,data__->RELAY3VALUE,retain)
__INIT_EXTERNAL(DINT,RELAY3VALUE0,data__->RELAY3VALUE0,retain)
__INIT_EXTERNAL(DINT,RELAY3VALUE1,data__->RELAY3VALUE1,retain)
__INIT_EXTERNAL(DINT,RELAY3VALUE2,data__->RELAY3VALUE2,retain)
__INIT_EXTERNAL(DINT,RELAY3VALUE3,data__->RELAY3VALUE3,retain)
}
// Code part
......@@ -235,11 +238,18 @@ void COUNTERST_body__(COUNTERST *data__) {
} else {
__SET_VAR(data__->,CNT0,,(__GET_VAR(data__->CNT0,) + 1));
__SET_VAR(data__->,CNT1,,(__GET_VAR(data__->CNT1,) + 1));
if ((__GET_VAR(data__->CNT1,) == 100)) {
if ((__GET_VAR(data__->CNT1,) == 50)) {
__SET_EXTERNAL(data__->,RELAY3VALUE0,,1);
__SET_EXTERNAL(data__->,RELAY3VALUE1,,1);
__SET_EXTERNAL(data__->,RELAY3VALUE2,,1);
__SET_EXTERNAL(data__->,RELAY3VALUE3,,1);
};
if ((__GET_VAR(data__->CNT1,) == 500)) {
if ((__GET_VAR(data__->CNT1,) == 100)) {
__SET_EXTERNAL(data__->,RELAY3VALUE0,,0);
__SET_EXTERNAL(data__->,RELAY3VALUE1,,0);
__SET_EXTERNAL(data__->,RELAY3VALUE2,,0);
__SET_EXTERNAL(data__->,RELAY3VALUE3,,0);
__SET_VAR(data__->,CNT1,,0);
};
};
__SET_VAR(data__->,OUT1,,__GET_VAR(data__->CNT1,));
......
......@@ -119,6 +119,9 @@ typedef struct {
__DECLARE_EXTERNAL(BOOL,RELAY2VALUE)
__DECLARE_EXTERNAL(BOOL,RELAY3VALUE)
__DECLARE_EXTERNAL(DINT,RELAY3VALUE0)
__DECLARE_EXTERNAL(DINT,RELAY3VALUE1)
__DECLARE_EXTERNAL(DINT,RELAY3VALUE2)
__DECLARE_EXTERNAL(DINT,RELAY3VALUE3)
} COUNTERST;
......
......@@ -8,24 +8,30 @@
3;OUT;CONFIG.RELAY2VALUE;CONFIG.RELAY2VALUE;BOOL;BOOL;
4;OUT;CONFIG.RELAY3VALUE;CONFIG.RELAY3VALUE;BOOL;BOOL;
5;OUT;CONFIG.RELAY3VALUE0;CONFIG.RELAY3VALUE0;DINT;DINT;
6;FB;CONFIG.RESOURCE1.INSTANCE0;CONFIG.RESOURCE1.INSTANCE0;PLC_PRG;;
7;VAR;CONFIG.RESOURCE1.INSTANCE0.RESET;CONFIG.RESOURCE1.INSTANCE0.RESET;BOOL;BOOL;
8;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT0;CONFIG.RESOURCE1.INSTANCE0.CNT0;INT;INT;
9;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT1;CONFIG.RESOURCE1.INSTANCE0.CNT1;INT;INT;
10;FB;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;COUNTERST;;
11;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;BOOL;BOOL;
12;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;BOOL;BOOL;
13;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESET;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESET;BOOL;BOOL;
14;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT1;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT1;INT;INT;
15;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT0;INT;INT;
16;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT1;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT1;INT;INT;
17;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT0;INT;INT;
18;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;INT;INT;
19;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY0VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY0VALUE;BOOL;BOOL;
20;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY1VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY1VALUE;BOOL;BOOL;
21;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY2VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY2VALUE;BOOL;BOOL;
22;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE;BOOL;BOOL;
23;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE0;DINT;DINT;
6;OUT;CONFIG.RELAY3VALUE1;CONFIG.RELAY3VALUE1;DINT;DINT;
7;OUT;CONFIG.RELAY3VALUE2;CONFIG.RELAY3VALUE2;DINT;DINT;
8;OUT;CONFIG.RELAY3VALUE3;CONFIG.RELAY3VALUE3;DINT;DINT;
9;FB;CONFIG.RESOURCE1.INSTANCE0;CONFIG.RESOURCE1.INSTANCE0;PLC_PRG;;
10;VAR;CONFIG.RESOURCE1.INSTANCE0.RESET;CONFIG.RESOURCE1.INSTANCE0.RESET;BOOL;BOOL;
11;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT0;CONFIG.RESOURCE1.INSTANCE0.CNT0;INT;INT;
12;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT1;CONFIG.RESOURCE1.INSTANCE0.CNT1;INT;INT;
13;FB;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;COUNTERST;;
14;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;BOOL;BOOL;
15;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;BOOL;BOOL;
16;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESET;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESET;BOOL;BOOL;
17;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT1;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT1;INT;INT;
18;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT0;INT;INT;
19;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT1;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT1;INT;INT;
20;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT0;INT;INT;
21;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;INT;INT;
22;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY0VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY0VALUE;BOOL;BOOL;
23;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY1VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY1VALUE;BOOL;BOOL;
24;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY2VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY2VALUE;BOOL;BOOL;
25;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE;BOOL;BOOL;
26;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE0;DINT;DINT;
27;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE1;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE1;DINT;DINT;
28;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE2;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE2;DINT;DINT;
29;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE3;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY3VALUE3;DINT;DINT;
// Ticktime
......
......@@ -21,6 +21,12 @@ __DECLARE_GLOBAL_LOCATION(BOOL,__QX0_0_3_3)
__DECLARE_GLOBAL_LOCATED(BOOL,CONFIG,RELAY3VALUE)
__DECLARE_GLOBAL_LOCATION(DINT,__QD1_0)
__DECLARE_GLOBAL_LOCATED(DINT,CONFIG,RELAY3VALUE0)
__DECLARE_GLOBAL_LOCATION(DINT,__QD1_1)
__DECLARE_GLOBAL_LOCATED(DINT,CONFIG,RELAY3VALUE1)
__DECLARE_GLOBAL_LOCATION(DINT,__QD1_2)
__DECLARE_GLOBAL_LOCATED(DINT,CONFIG,RELAY3VALUE2)
__DECLARE_GLOBAL_LOCATION(DINT,__QD1_3)
__DECLARE_GLOBAL_LOCATED(DINT,CONFIG,RELAY3VALUE3)
void RESOURCE1_init__(void);
......@@ -38,6 +44,12 @@ void config_init__(void) {
__INIT_GLOBAL(BOOL,RELAY3VALUE,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY3VALUE0,__QD1_0,retain)
__INIT_GLOBAL(DINT,RELAY3VALUE0,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY3VALUE1,__QD1_1,retain)
__INIT_GLOBAL(DINT,RELAY3VALUE1,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY3VALUE2,__QD1_2,retain)
__INIT_GLOBAL(DINT,RELAY3VALUE2,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY3VALUE3,__QD1_3,retain)
__INIT_GLOBAL(DINT,RELAY3VALUE3,__INITIAL_VALUE(0),retain)
RESOURCE1_init__();
}
......
......@@ -5,4 +5,7 @@ __DECLARE_GLOBAL_PROTOTYPE(BOOL,RELAY1VALUE)
__DECLARE_GLOBAL_PROTOTYPE(BOOL,RELAY2VALUE)
__DECLARE_GLOBAL_PROTOTYPE(BOOL,RELAY3VALUE)
__DECLARE_GLOBAL_PROTOTYPE(DINT,RELAY3VALUE0)
__DECLARE_GLOBAL_PROTOTYPE(DINT,RELAY3VALUE1)
__DECLARE_GLOBAL_PROTOTYPE(DINT,RELAY3VALUE2)
__DECLARE_GLOBAL_PROTOTYPE(DINT,RELAY3VALUE3)
......@@ -17,6 +17,9 @@ FUNCTION_BLOCK CounterST
Relay2Value : BOOL;
Relay3Value : BOOL;
Relay3Value0 : DINT;
Relay3Value1 : DINT;
Relay3Value2 : DINT;
Relay3Value3 : DINT;
END_VAR
IF Reset THEN
......@@ -26,12 +29,19 @@ FUNCTION_BLOCK CounterST
ELSE
Cnt0 := Cnt0 + 1;
Cnt1 := Cnt1 + 1;
IF Cnt1 = 100 THEN
IF Cnt1 = 50 THEN
Relay3Value0 := 1;
Relay3Value1 := 1;
Relay3Value2 := 1;
Relay3Value3 := 1;
END_IF;
IF Cnt1 = 500 THEN
IF Cnt1 = 100 THEN
Relay3Value0 := 0;
Relay3Value1 := 0;
Relay3Value2 := 0;
Relay3Value3 := 0;
Cnt1 := 0;
END_IF;
END_IF;
......@@ -66,6 +76,9 @@ CONFIGURATION config
Relay2Value AT %QX0.0.2.2 : BOOL := 0;
Relay3Value AT %QX0.0.3.3 : BOOL := 0;
Relay3Value0 AT %QD1.0 : DINT := 0;
Relay3Value1 AT %QD1.1 : DINT := 0;
Relay3Value2 AT %QD1.2 : DINT := 0;
Relay3Value3 AT %QD1.3 : DINT := 0;
END_VAR
RESOURCE resource1 ON PLC
......
5ad2334f5cfa95cc9bb7d9400960e0df
\ No newline at end of file
649c9626fabc16ab1a46207076a4b602
\ No newline at end of file
......@@ -111,6 +111,9 @@ FUNCTION_BLOCK CounterST
Relay2Value : BOOL;
Relay3Value : BOOL;
Relay3Value0 : DINT;
Relay3Value1 : DINT;
Relay3Value2 : DINT;
Relay3Value3 : DINT;
END_VAR
IF Reset THEN
......@@ -120,12 +123,19 @@ FUNCTION_BLOCK CounterST
ELSE
Cnt0 := Cnt0 + 1;
Cnt1 := Cnt1 + 1;
IF Cnt1 = 100 THEN
IF Cnt1 = 50 THEN
Relay3Value0 := 1;
Relay3Value1 := 1;
Relay3Value2 := 1;
Relay3Value3 := 1;
END_IF;
IF Cnt1 = 500 THEN
IF Cnt1 = 100 THEN
Relay3Value0 := 0;
Relay3Value1 := 0;
Relay3Value2 := 0;
Relay3Value3 := 0;
Cnt1 := 0;
END_IF;
END_IF;
......@@ -160,6 +170,9 @@ CONFIGURATION config
Relay2Value AT %QX0.0.2.2 : BOOL := 0;
Relay3Value AT %QX0.0.3.3 : BOOL := 0;
Relay3Value0 AT %QD1.0 : DINT := 0;
Relay3Value1 AT %QD1.1 : DINT := 0;
Relay3Value2 AT %QD1.2 : DINT := 0;
Relay3Value3 AT %QD1.3 : DINT := 0;
END_VAR
RESOURCE resource1 ON PLC
......
......@@ -26,7 +26,7 @@ void __publish_debug (void){}
#include <stdio.h>
#ifndef TARGET_ONLINE_DEBUG_DISABLE
#define BUFFER_SIZE 36
#define BUFFER_SIZE 60
/* Atomically accessed variable for buffer state */
#define BUFFER_FREE 0
......@@ -55,6 +55,9 @@ extern __IEC_BOOL_p CONFIG__RELAY1VALUE;
extern __IEC_BOOL_p CONFIG__RELAY2VALUE;
extern __IEC_BOOL_p CONFIG__RELAY3VALUE;
extern __IEC_DINT_p CONFIG__RELAY3VALUE0;
extern __IEC_DINT_p CONFIG__RELAY3VALUE1;
extern __IEC_DINT_p CONFIG__RELAY3VALUE2;
extern __IEC_DINT_p CONFIG__RELAY3VALUE3;
extern PLC_PRG RESOURCE1__INSTANCE0;
typedef const struct {
......@@ -69,6 +72,9 @@ static dbgvardsc_t dbgvardsc[] = {
{&(CONFIG__RELAY2VALUE), BOOL_O_ENUM},
{&(CONFIG__RELAY3VALUE), BOOL_O_ENUM},
{&(CONFIG__RELAY3VALUE0), DINT_O_ENUM},
{&(CONFIG__RELAY3VALUE1), DINT_O_ENUM},
{&(CONFIG__RELAY3VALUE2), DINT_O_ENUM},
{&(CONFIG__RELAY3VALUE3), DINT_O_ENUM},
{&(RESOURCE1__INSTANCE0.RESET), BOOL_ENUM},
{&(RESOURCE1__INSTANCE0.CNT0), INT_ENUM},
{&(RESOURCE1__INSTANCE0.CNT1), INT_ENUM},
......@@ -84,7 +90,10 @@ static dbgvardsc_t dbgvardsc[] = {
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY1VALUE), BOOL_P_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY2VALUE), BOOL_P_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY3VALUE), BOOL_P_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY3VALUE0), DINT_P_ENUM}
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY3VALUE0), DINT_P_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY3VALUE1), DINT_P_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY3VALUE2), DINT_P_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY3VALUE3), DINT_P_ENUM}
};
typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*);
......
<?xml version='1.0' encoding='utf-8'?>
<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201">
<fileHeader companyName="Unknown" productName="Unnamed" productVersion="1" creationDateTime="2021-05-14T14:33:11"/>
<contentHeader name="Counter (OSIE)" modificationDateTime="2021-10-20T13:35:20">
<contentHeader name="Counter (OSIE)" modificationDateTime="2021-10-20T17:08:40">
<coordinateInfo>
<fbd>
<scaling x="0" y="0"/>
......@@ -179,6 +179,21 @@
<DINT/>
</type>
</variable>
<variable name="Relay3Value1">
<type>
<DINT/>
</type>
</variable>
<variable name="Relay3Value2">
<type>
<DINT/>
</type>
</variable>
<variable name="Relay3Value3">
<type>
<DINT/>
</type>
</variable>
</externalVars>
</interface>
<body>
......@@ -190,12 +205,19 @@
ELSE
Cnt0 := Cnt0 + 1;
Cnt1 := Cnt1 + 1;
IF Cnt1 = 100 THEN
IF Cnt1 = 50 THEN
Relay3Value0 := 1;
Relay3Value1 := 1;
Relay3Value2 := 1;
Relay3Value3 := 1;
END_IF;
IF Cnt1 = 500 THEN
IF Cnt1 = 100 THEN
Relay3Value0 := 0;
Relay3Value1 := 0;
Relay3Value2 := 0;
Relay3Value3 := 0;
Cnt1 := 0;
END_IF;
END_IF;
......@@ -276,7 +298,40 @@ Out0 := Cnt0;]]></xhtml:p>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[OPC-UA relay valu]]></xhtml:p>
<xhtml:p><![CDATA[OPC-UA relay 0]]></xhtml:p>
</documentation>
</variable>
<variable name="Relay3Value1" address="%QD1.1">
<type>
<DINT/>
</type>
<initialValue>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[OPC-UA relay 1]]></xhtml:p>
</documentation>
</variable>
<variable name="Relay3Value2" address="%QD1.2">
<type>
<DINT/>
</type>
<initialValue>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[OPC-UA relay 2]]></xhtml:p>
</documentation>
</variable>
<variable name="Relay3Value3" address="%QD1.3">
<type>
<DINT/>
</type>
<initialValue>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[OPC-UA relay 2]]></xhtml:p>
</documentation>
</variable>
</globalVars>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment