Commit a8bc4204 authored by Ivan Tyagov's avatar Ivan Tyagov

Extend PLC Poc to control 4 relays.

parent f6dc8932
__LOCATED_VAR(BOOL,__QX0_0_0_0,Q,X,0,0,0,0)
__LOCATED_VAR(BOOL,__QX0_0_0_0,Q,X,0,0,0,0)
__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)
This diff is collapsed.
This diff is collapsed.
......@@ -207,6 +207,7 @@ void COUNTERST_init__(COUNTERST *data__, BOOL retain) {
__INIT_VAR(data__->OUT,0,retain)
__INIT_VAR(data__->CNT,0,retain)
__INIT_EXTERNAL(INT,RESETCOUNTERVALUE,data__->RESETCOUNTERVALUE,retain)
__INIT_EXTERNAL(BOOL,RELAY0VALUE,data__->RELAY0VALUE,retain)
}
// Code part
......@@ -241,11 +242,9 @@ __end:
void PLC_PRG_init__(PLC_PRG *data__, BOOL retain) {
__INIT_VAR(data__->RESET,__BOOL_LITERAL(FALSE),retain)
__INIT_VAR(data__->CNT0,0,retain)
__INIT_VAR(data__->CNT1,0,retain)
__INIT_VAR(data__->CNT2,0,retain)
__INIT_VAR(data__->CNT3,0,retain)
__INIT_VAR(data__->CNT4,0,retain)
COUNTERST_init__(&data__->COUNTERST0,retain);
__INIT_LOCATED(BOOL,__QX0_0_0_0,data__->RELAY0VALUE,retain)
__INIT_LOCATED_VALUE(data__->RELAY0VALUE,__BOOL_LITERAL(FALSE))
}
// Code part
......
......@@ -112,6 +112,7 @@ typedef struct {
// FB private variables - TEMP, private and located variables
__DECLARE_VAR(INT,CNT)
__DECLARE_EXTERNAL(INT,RESETCOUNTERVALUE)
__DECLARE_EXTERNAL(BOOL,RELAY0VALUE)
} COUNTERST;
......@@ -124,13 +125,10 @@ typedef struct {
// PROGRAM Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,RESET)
__DECLARE_VAR(INT,CNT0)
__DECLARE_VAR(INT,CNT1)
__DECLARE_VAR(INT,CNT2)
__DECLARE_VAR(INT,CNT3)
__DECLARE_VAR(INT,CNT4)
// PROGRAM private variables - TEMP, private and located variables
COUNTERST COUNTERST0;
__DECLARE_LOCATED(BOOL,RELAY0VALUE)
} PLC_PRG;
......
......@@ -3,13 +3,13 @@
// Variables
0;VAR;CONFIG.RESETCOUNTERVALUE;CONFIG.RESETCOUNTERVALUE;INT;INT;
1;FB;CONFIG.RESOURCE1.INSTANCE0;CONFIG.RESOURCE1.INSTANCE0;PLC_PRG;;
2;VAR;CONFIG.RESOURCE1.INSTANCE0.RESET;CONFIG.RESOURCE1.INSTANCE0.RESET;BOOL;BOOL;
3;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT0;CONFIG.RESOURCE1.INSTANCE0.CNT0;INT;INT;
4;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT1;CONFIG.RESOURCE1.INSTANCE0.CNT1;INT;INT;
5;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT2;CONFIG.RESOURCE1.INSTANCE0.CNT2;INT;INT;
6;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT3;CONFIG.RESOURCE1.INSTANCE0.CNT3;INT;INT;
7;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT4;CONFIG.RESOURCE1.INSTANCE0.CNT4;INT;INT;
1;OUT;CONFIG.RELAY0VALUE;CONFIG.RELAY0VALUE;BOOL;BOOL;
2;OUT;CONFIG.RELAY1VALUE;CONFIG.RELAY1VALUE;BOOL;BOOL;
3;OUT;CONFIG.RELAY2VALUE;CONFIG.RELAY2VALUE;BOOL;BOOL;
4;OUT;CONFIG.RELAY3VALUE;CONFIG.RELAY3VALUE;BOOL;BOOL;
5;FB;CONFIG.RESOURCE1.INSTANCE0;CONFIG.RESOURCE1.INSTANCE0;PLC_PRG;;
6;VAR;CONFIG.RESOURCE1.INSTANCE0.RESET;CONFIG.RESOURCE1.INSTANCE0.RESET;BOOL;BOOL;
7;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT0;CONFIG.RESOURCE1.INSTANCE0.CNT0;INT;INT;
8;FB;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;COUNTERST;;
9;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;BOOL;BOOL;
10;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;BOOL;BOOL;
......@@ -17,6 +17,8 @@
12;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT;INT;INT;
13;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT;INT;INT;
14;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;INT;INT;
15;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY0VALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RELAY0VALUE;BOOL;BOOL;
16;OUT;CONFIG.RESOURCE1.INSTANCE0.RELAY0VALUE;CONFIG.RESOURCE1.INSTANCE0.RELAY0VALUE;BOOL;BOOL;
// Ticktime
......
......@@ -11,13 +11,29 @@
// CONFIGURATION CONFIG
__DECLARE_GLOBAL(INT,CONFIG,RESETCOUNTERVALUE)
__DECLARE_GLOBAL_LOCATION(BOOL,__QX0_0_0_0)
__DECLARE_GLOBAL_LOCATED(BOOL,CONFIG,RELAY0VALUE)
__DECLARE_GLOBAL_LOCATION(BOOL,__QX0_0_1_1)
__DECLARE_GLOBAL_LOCATED(BOOL,CONFIG,RELAY1VALUE)
__DECLARE_GLOBAL_LOCATION(BOOL,__QX0_0_2_2)
__DECLARE_GLOBAL_LOCATED(BOOL,CONFIG,RELAY2VALUE)
__DECLARE_GLOBAL_LOCATION(BOOL,__QX0_0_3_3)
__DECLARE_GLOBAL_LOCATED(BOOL,CONFIG,RELAY3VALUE)
void RESOURCE1_init__(void);
void config_init__(void) {
BOOL retain;
retain = 0;
__INIT_GLOBAL(INT,RESETCOUNTERVALUE,__INITIAL_VALUE(1000),retain)
__INIT_GLOBAL(INT,RESETCOUNTERVALUE,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY0VALUE,__QX0_0_0_0,retain)
__INIT_GLOBAL(BOOL,RELAY0VALUE,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY1VALUE,__QX0_0_1_1,retain)
__INIT_GLOBAL(BOOL,RELAY1VALUE,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY2VALUE,__QX0_0_2_2,retain)
__INIT_GLOBAL(BOOL,RELAY2VALUE,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,RELAY3VALUE,__QX0_0_3_3,retain)
__INIT_GLOBAL(BOOL,RELAY3VALUE,__INITIAL_VALUE(0),retain)
RESOURCE1_init__();
}
......
#include "beremiz.h"
__DECLARE_GLOBAL_PROTOTYPE(INT,RESETCOUNTERVALUE)
__DECLARE_GLOBAL_PROTOTYPE(BOOL,RELAY0VALUE)
__DECLARE_GLOBAL_PROTOTYPE(BOOL,RELAY1VALUE)
__DECLARE_GLOBAL_PROTOTYPE(BOOL,RELAY2VALUE)
__DECLARE_GLOBAL_PROTOTYPE(BOOL,RELAY3VALUE)
......@@ -10,6 +10,7 @@ FUNCTION_BLOCK CounterST
END_VAR
VAR_EXTERNAL
ResetCounterValue : INT;
Relay0Value : BOOL;
END_VAR
IF Reset THEN
......@@ -27,14 +28,13 @@ PROGRAM plc_prg
END_VAR
VAR_OUTPUT
Cnt0 : INT;
Cnt1 : INT;
Cnt2 : INT;
Cnt3 : INT;
Cnt4 : INT;
END_VAR
VAR
CounterST0 : CounterST;
END_VAR
VAR
Relay0Value AT %QX0.0.0.0 : BOOL;
END_VAR
CounterST0(Reset := Reset);
Cnt0 := CounterST0.Out;
......@@ -43,7 +43,11 @@ END_PROGRAM
CONFIGURATION config
VAR_GLOBAL
ResetCounterValue : INT := 1000;
ResetCounterValue : INT := 0;
Relay0Value AT %QX0.0.0.0 : BOOL := 0;
Relay1Value AT %QX0.0.1.1 : BOOL := 0;
Relay2Value AT %QX0.0.2.2 : BOOL := 0;
Relay3Value AT %QX0.0.3.3 : BOOL := 0;
END_VAR
RESOURCE resource1 ON PLC
......
cb6baca0419e9cafc6316a11a81a0317
\ No newline at end of file
7ddbf3c64169e7bffe3e5184c847f848
\ No newline at end of file
......@@ -104,6 +104,7 @@ FUNCTION_BLOCK CounterST
END_VAR
VAR_EXTERNAL
ResetCounterValue : INT;
Relay0Value : BOOL;
END_VAR
IF Reset THEN
......@@ -121,14 +122,13 @@ PROGRAM plc_prg
END_VAR
VAR_OUTPUT
Cnt0 : INT;
Cnt1 : INT;
Cnt2 : INT;
Cnt3 : INT;
Cnt4 : INT;
END_VAR
VAR
CounterST0 : CounterST;
END_VAR
VAR
Relay0Value AT %QX0.0.0.0 : BOOL;
END_VAR
CounterST0(Reset := Reset);
Cnt0 := CounterST0.Out;
......@@ -137,7 +137,11 @@ END_PROGRAM
CONFIGURATION config
VAR_GLOBAL
ResetCounterValue : INT := 1000;
ResetCounterValue : INT := 0;
Relay0Value AT %QX0.0.0.0 : BOOL := 0;
Relay1Value AT %QX0.0.1.1 : BOOL := 0;
Relay2Value AT %QX0.0.2.2 : BOOL := 0;
Relay3Value AT %QX0.0.3.3 : BOOL := 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 22
#define BUFFER_SIZE 20
/* Atomically accessed variable for buffer state */
#define BUFFER_FREE 0
......@@ -50,6 +50,10 @@ extern PLC_PRG RESOURCE1__INSTANCE0;
* Declare global variables from resources and conf
**/
extern __IEC_INT_t CONFIG__RESETCOUNTERVALUE;
extern __IEC_BOOL_p CONFIG__RELAY0VALUE;
extern __IEC_BOOL_p CONFIG__RELAY1VALUE;
extern __IEC_BOOL_p CONFIG__RELAY2VALUE;
extern __IEC_BOOL_p CONFIG__RELAY3VALUE;
extern PLC_PRG RESOURCE1__INSTANCE0;
typedef const struct {
......@@ -59,18 +63,20 @@ typedef const struct {
static dbgvardsc_t dbgvardsc[] = {
{&(CONFIG__RESETCOUNTERVALUE), INT_ENUM},
{&(CONFIG__RELAY0VALUE), BOOL_O_ENUM},
{&(CONFIG__RELAY1VALUE), BOOL_O_ENUM},
{&(CONFIG__RELAY2VALUE), BOOL_O_ENUM},
{&(CONFIG__RELAY3VALUE), BOOL_O_ENUM},
{&(RESOURCE1__INSTANCE0.RESET), BOOL_ENUM},
{&(RESOURCE1__INSTANCE0.CNT0), INT_ENUM},
{&(RESOURCE1__INSTANCE0.CNT1), INT_ENUM},
{&(RESOURCE1__INSTANCE0.CNT2), INT_ENUM},
{&(RESOURCE1__INSTANCE0.CNT3), INT_ENUM},
{&(RESOURCE1__INSTANCE0.CNT4), INT_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.EN), BOOL_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.ENO), BOOL_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RESET), BOOL_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.OUT), INT_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.CNT), INT_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RESETCOUNTERVALUE), INT_P_ENUM}
{&(RESOURCE1__INSTANCE0.COUNTERST0.RESETCOUNTERVALUE), INT_P_ENUM},
{&(RESOURCE1__INSTANCE0.COUNTERST0.RELAY0VALUE), BOOL_P_ENUM},
{&(RESOURCE1__INSTANCE0.RELAY0VALUE), BOOL_O_ENUM}
};
typedef void(*__for_each_variable_do_fp)(dbgvardsc_t*);
......
......@@ -42,6 +42,10 @@ int __init_py_ext(int argc,char **argv);
void __cleanup_py_ext(void);
void __retrieve_py_ext(void);
void __publish_py_ext(void);
int __init_0(int argc,char **argv);
void __cleanup_0(void);
void __retrieve_0(void);
void __publish_0(void);
/*
* Retrieve input variables, run PLC and publish output variables
......@@ -53,6 +57,7 @@ void __run(void)
__tick %= greatest_tick_count__;
__retrieve_py_ext();
__retrieve_0();
/*__retrieve_debug();*/
......@@ -60,6 +65,7 @@ void __run(void)
__publish_debug();
__publish_0();
__publish_py_ext();
}
......@@ -80,6 +86,7 @@ int __init(int argc,char **argv)
config_init__();
__init_debug();
init_level=1; if((res = __init_py_ext(argc,argv))){return res;}
init_level=2; if((res = __init_0(argc,argv))){return res;}
return res;
}
/*
......@@ -87,6 +94,7 @@ int __init(int argc,char **argv)
**/
void __cleanup(void)
{
if(init_level >= 2) __cleanup_0();
if(init_level >= 1) __cleanup_py_ext();
__cleanup_debug();
}
......
<?xml version='1.0' encoding='utf-8'?>
<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="ModbusRequest_0"/>
<?xml version='1.0' encoding='utf-8'?>
<ModbusRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" Write_on_change="false" SlaveID="0" Function="05 - Write Single coil"/>
<?xml version='1.0' encoding='utf-8'?>
<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="1" Name="ModbusRequest_1"/>
<?xml version='1.0' encoding='utf-8'?>
<ModbusRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" Function="05 - Write Single coil" Write_on_change="false" Start_Address="1" SlaveID="0"/>
<?xml version='1.0' encoding='utf-8'?>
<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="2" Name="ModbusRequest_2"/>
<?xml version='1.0' encoding='utf-8'?>
<ModbusRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" Function="05 - Write Single coil" Start_Address="2" SlaveID="0"/>
<?xml version='1.0' encoding='utf-8'?>
<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="3" Name="ModbusRequest_3"/>
<?xml version='1.0' encoding='utf-8'?>
<ModbusRequest xmlns:xsd="http://www.w3.org/2001/XMLSchema" Function="05 - Write Single coil" SlaveID="0" Start_Address="3"/>
<?xml version='1.0' encoding='utf-8'?>
<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="ModbusTCPclient_0"/>
<?xml version='1.0' encoding='utf-8'?>
<ModbusTCPclient xmlns:xsd="http://www.w3.org/2001/XMLSchema" Configuration_Name="Modbus TCP Client 0.0" Remote_IP_Address="192.168.0.48" Invocation_Rate_in_ms="1000"/>
<?xml version='1.0' encoding='utf-8'?>
<BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="modbus_0"/>
<?xml version='1.0' encoding='utf-8'?>
<ModbusRoot xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
<?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-05-17T11:58:28">
<contentHeader name="Counter (OSIE)" modificationDateTime="2021-05-19T14:06:39">
<coordinateInfo>
<fbd>
<scaling x="0" y="0"/>
......@@ -32,26 +32,6 @@
<INT/>
</type>
</variable>
<variable name="Cnt1">
<type>
<INT/>
</type>
</variable>
<variable name="Cnt2">
<type>
<INT/>
</type>
</variable>
<variable name="Cnt3">
<type>
<INT/>
</type>
</variable>
<variable name="Cnt4">
<type>
<INT/>
</type>
</variable>
</outputVars>
<localVars>
<variable name="CounterST0">
......@@ -60,24 +40,34 @@
</type>
</variable>
</localVars>
<localVars>
<variable name="Relay0Value" address="%QX0.0.0.0">
<type>
<BOOL/>
</type>
<documentation>
<xhtml:p><![CDATA[Relay 0 Status]]></xhtml:p>
</documentation>
</variable>
</localVars>
</interface>
<body>
<FBD>
<comment localId="1" height="143" width="201">
<position x="378" y="162"/>
<position x="566" y="75"/>
<content>
<xhtml:p><![CDATA[Test Ivan: this PLC will run an increasing counter unless a Reset is switched On (then counter will be reset).]]></xhtml:p>
</content>
</comment>
<block localId="2" typeName="CounterST" instanceName="CounterST0" executionOrderId="0" height="109" width="99">
<position x="122" y="192"/>
<position x="288" y="192"/>
<inputVariables>
<variable formalParameter="Reset">
<connectionPointIn>
<relPosition x="0" y="64"/>
<connection refLocalId="3">
<position x="122" y="256"/>
<position x="51" y="256"/>
<position x="288" y="256"/>
<position x="229" y="256"/>
</connection>
</connectionPointIn>
</variable>
......@@ -92,19 +82,19 @@
</outputVariables>
</block>
<inVariable localId="3" executionOrderId="0" height="24" width="50" negated="false">
<position x="1" y="244"/>
<position x="179" y="244"/>
<connectionPointOut>
<relPosition x="50" y="12"/>
</connectionPointOut>
<expression>Reset</expression>
</inVariable>
<outVariable localId="4" executionOrderId="0" height="24" width="42" negated="false">
<position x="284" y="244"/>
<position x="450" y="244"/>
<connectionPointIn>
<relPosition x="0" y="12"/>
<connection refLocalId="2" formalParameter="Out">
<position x="284" y="256"/>
<position x="221" y="256"/>
<position x="450" y="256"/>
<position x="387" y="256"/>
</connection>
</connectionPointIn>
<expression>Cnt0</expression>
......@@ -141,6 +131,11 @@
<INT/>
</type>
</variable>
<variable name="Relay0Value">
<type>
<BOOL/>
</type>
</variable>
</externalVars>
</interface>
<body>
......@@ -171,8 +166,52 @@ Out := Cnt;]]></xhtml:p>
<INT/>
</type>
<initialValue>
<simpleValue value="1000"/>
<simpleValue value="0"/>
</initialValue>
</variable>
<variable name="Relay0Value" address="%QX0.0.0.0">
<type>
<BOOL/>
</type>
<initialValue>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[The status of the Lime's relay0 (read over modbus)]]></xhtml:p>
</documentation>
</variable>
<variable name="Relay1Value" address="%QX0.0.1.1">
<type>
<BOOL/>
</type>
<initialValue>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[The status of the Lime's relay1 (read over modbus)]]></xhtml:p>
</documentation>
</variable>
<variable name="Relay2Value" address="%QX0.0.2.2">
<type>
<BOOL/>
</type>
<initialValue>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[The status of the Lime's relay2 (read over modbus)]]></xhtml:p>
</documentation>
</variable>
<variable name="Relay3Value" address="%QX0.0.3.3">
<type>
<BOOL/>
</type>
<initialValue>
<simpleValue value="0"/>
</initialValue>
<documentation>
<xhtml:p><![CDATA[The status of the Lime's relay3 (read over modbus)]]></xhtml:p>
</documentation>
</variable>
</globalVars>
</configuration>
......
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