Commit 5ca48d3b authored by Ivan Tyagov's avatar Ivan Tyagov

Rename.

parent 45be5af0
__LOCATED_VAR(LREAL,__IL1_2,I,L,1,2)
__LOCATED_VAR(DINT,__QD0_0,Q,D,0,0)
__LOCATED_VAR(DINT,__QD0_1,Q,D,0,1)
__LOCATED_VAR(LINT,__IL2_2,I,L,2,2)
__LOCATED_VAR(LINT,__QL2_2,Q,L,2,2)
This diff is collapsed.
#include "beremiz.h"
#ifndef __POUS_H
#define __POUS_H
#include "accessor.h"
#include "iec_std_lib.h"
__DECLARE_ENUMERATED_TYPE(LOGLEVEL,
LOGLEVEL__CRITICAL,
LOGLEVEL__WARNING,
LOGLEVEL__INFO,
LOGLEVEL__DEBUG
)
// FUNCTION_BLOCK LOGGER
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(BOOL,TRIG)
__DECLARE_VAR(STRING,MSG)
__DECLARE_VAR(LOGLEVEL,LEVEL)
// FB private variables - TEMP, private and located variables
__DECLARE_VAR(BOOL,TRIG0)
} LOGGER;
void LOGGER_init__(LOGGER *data__, BOOL retain);
// Code part
void LOGGER_body__(LOGGER *data__);
// FUNCTION_BLOCK PYTHON_EVAL
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(BOOL,TRIG)
__DECLARE_VAR(STRING,CODE)
__DECLARE_VAR(BOOL,ACK)
__DECLARE_VAR(STRING,RESULT)
// FB private variables - TEMP, private and located variables
__DECLARE_VAR(DWORD,STATE)
__DECLARE_VAR(STRING,BUFFER)
__DECLARE_VAR(STRING,PREBUFFER)
__DECLARE_VAR(BOOL,TRIGM1)
__DECLARE_VAR(BOOL,TRIGGED)
} PYTHON_EVAL;
void PYTHON_EVAL_init__(PYTHON_EVAL *data__, BOOL retain);
// Code part
void PYTHON_EVAL_body__(PYTHON_EVAL *data__);
// FUNCTION_BLOCK CSV_READ_BY_STRING
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(BOOL,ACK)
__DECLARE_VAR(STRING,RESULT)
__DECLARE_VAR(STRING,FILE_NAME)
__DECLARE_VAR(STRING,ROW)
__DECLARE_VAR(STRING,COLUMN)
// FB private variables - TEMP, private and located variables
__DECLARE_EXTERNAL(BOOL,PYEXT_CSV_UPDATE)
__DECLARE_VAR(STRING,OLDCODE)
PYTHON_EVAL PY_EVAL;
R_TRIG R_TRIG0;
R_TRIG R_TRIG1;
SR SR0;
__DECLARE_VAR(STRING,_TMP_CONCAT7_OUT)
__DECLARE_VAR(BOOL,_TMP_NE16_OUT)
__DECLARE_VAR(STRING,_TMP_SEL18_OUT)
__DECLARE_VAR(BOOL,_TMP_OR15_OUT)
__DECLARE_VAR(STRING,_TMP_LEFT33_OUT)
__DECLARE_VAR(BOOL,_TMP_NE34_OUT)
__DECLARE_VAR(BOOL,_TMP_AND39_OUT)
R_TRIG R_TRIG2;
} CSV_READ_BY_STRING;
void CSV_READ_BY_STRING_init__(CSV_READ_BY_STRING *data__, BOOL retain);
// Code part
void CSV_READ_BY_STRING_body__(CSV_READ_BY_STRING *data__);
// FUNCTION_BLOCK PYTHON_GEAR
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(UINT,N)
__DECLARE_VAR(BOOL,TRIG)
__DECLARE_VAR(STRING,CODE)
__DECLARE_VAR(BOOL,ACK)
__DECLARE_VAR(STRING,RESULT)
// FB private variables - TEMP, private and located variables
PYTHON_EVAL PY_EVAL;
__DECLARE_VAR(UINT,COUNTER)
__DECLARE_VAR(UINT,_TMP_ADD10_OUT)
__DECLARE_VAR(BOOL,_TMP_EQ13_OUT)
__DECLARE_VAR(UINT,_TMP_SEL15_OUT)
__DECLARE_VAR(BOOL,_TMP_AND7_OUT)
} PYTHON_GEAR;
void PYTHON_GEAR_init__(PYTHON_GEAR *data__, BOOL retain);
// Code part
void PYTHON_GEAR_body__(PYTHON_GEAR *data__);
// FUNCTION_BLOCK CSV_RELOAD
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(BOOL,ACK)
__DECLARE_VAR(STRING,RESULT)
__DECLARE_VAR(BOOL,TRIG)
// FB private variables - TEMP, private and located variables
__DECLARE_EXTERNAL(BOOL,PYEXT_CSV_UPDATE)
PYTHON_EVAL PY_EVAL;
R_TRIG R_TRIG0;
F_TRIG F_TRIG0;
__DECLARE_VAR(BOOL,_TMP_OR11_OUT)
__DECLARE_VAR(BOOL,_TMP_NOT13_OUT)
__DECLARE_VAR(BOOL,_TMP_MOVE12_ENO)
__DECLARE_VAR(BOOL,_TMP_MOVE12_OUT)
} CSV_RELOAD;
void CSV_RELOAD_init__(CSV_RELOAD *data__, BOOL retain);
// Code part
void CSV_RELOAD_body__(CSV_RELOAD *data__);
// FUNCTION_BLOCK CSV_READ_BY_INT
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(BOOL,ACK)
__DECLARE_VAR(STRING,RESULT)
__DECLARE_VAR(STRING,FILE_NAME)
__DECLARE_VAR(INT,ROW)
__DECLARE_VAR(INT,COLUMN)
// FB private variables - TEMP, private and located variables
__DECLARE_EXTERNAL(BOOL,PYEXT_CSV_UPDATE)
__DECLARE_VAR(STRING,OLDCODE)
PYTHON_EVAL PY_EVAL0;
R_TRIG R_TRIG1;
R_TRIG R_TRIG2;
SR SR0;
__DECLARE_VAR(STRING,_TMP_INT_TO_STRING31_OUT)
__DECLARE_VAR(STRING,_TMP_INT_TO_STRING2_OUT)
__DECLARE_VAR(STRING,_TMP_CONCAT7_OUT)
__DECLARE_VAR(BOOL,_TMP_NE16_OUT)
__DECLARE_VAR(STRING,_TMP_SEL18_OUT)
__DECLARE_VAR(BOOL,_TMP_OR15_OUT)
__DECLARE_VAR(STRING,_TMP_LEFT33_OUT)
__DECLARE_VAR(BOOL,_TMP_NE34_OUT)
__DECLARE_VAR(BOOL,_TMP_AND39_OUT)
R_TRIG R_TRIG3;
} CSV_READ_BY_INT;
void CSV_READ_BY_INT_init__(CSV_READ_BY_INT *data__, BOOL retain);
// Code part
void CSV_READ_BY_INT_body__(CSV_READ_BY_INT *data__);
// FUNCTION_BLOCK PYTHON_POLL
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(BOOL,TRIG)
__DECLARE_VAR(STRING,CODE)
__DECLARE_VAR(BOOL,ACK)
__DECLARE_VAR(STRING,RESULT)
// FB private variables - TEMP, private and located variables
__DECLARE_VAR(DWORD,STATE)
__DECLARE_VAR(STRING,BUFFER)
__DECLARE_VAR(STRING,PREBUFFER)
__DECLARE_VAR(BOOL,TRIGM1)
__DECLARE_VAR(BOOL,TRIGGED)
} PYTHON_POLL;
void PYTHON_POLL_init__(PYTHON_POLL *data__, BOOL retain);
// Code part
void PYTHON_POLL_body__(PYTHON_POLL *data__);
// FUNCTION_BLOCK COUNTERST
// Data part
typedef struct {
// FB Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,EN)
__DECLARE_VAR(BOOL,ENO)
__DECLARE_VAR(BOOL,RESET)
__DECLARE_VAR(INT,OUT1)
__DECLARE_VAR(INT,OUT0)
// FB private variables - TEMP, private and located variables
__DECLARE_VAR(INT,CNT0)
__DECLARE_EXTERNAL(INT,RESETCOUNTERVALUE)
__DECLARE_EXTERNAL(LREAL,OI_SENSOR_COUNTER)
__DECLARE_EXTERNAL(DINT,VFD_RELAY0)
__DECLARE_EXTERNAL(DINT,AIR_VALVE_RELAY0)
__DECLARE_EXTERNAL(LINT,MES5_INT_COUNTER_IN)
__DECLARE_EXTERNAL(LINT,MES5_INT_COUNTER_OUT)
} COUNTERST;
void COUNTERST_init__(COUNTERST *data__, BOOL retain);
// Code part
void COUNTERST_body__(COUNTERST *data__);
// PROGRAM PLC_PRG
// Data part
typedef struct {
// PROGRAM Interface - IN, OUT, IN_OUT variables
__DECLARE_VAR(BOOL,RESET)
__DECLARE_VAR(INT,CNT0)
__DECLARE_VAR(INT,CNT1)
// PROGRAM private variables - TEMP, private and located variables
COUNTERST COUNTERST0;
} PLC_PRG;
void PLC_PRG_init__(PLC_PRG *data__, BOOL retain);
// Code part
void PLC_PRG_body__(PLC_PRG *data__);
#endif //__POUS_H
// Programs
0;CONFIG.RESOURCE1.INSTANCE0;PLC_PRG;
// Variables
0;VAR;CONFIG.RESETCOUNTERVALUE;CONFIG.RESETCOUNTERVALUE;INT;INT;0;
1;IN;CONFIG.OI_SENSOR_COUNTER;CONFIG.OI_SENSOR_COUNTER;LREAL;LREAL;0;
2;OUT;CONFIG.VFD_RELAY0;CONFIG.VFD_RELAY0;DINT;DINT;0;
3;OUT;CONFIG.AIR_VALVE_RELAY0;CONFIG.AIR_VALVE_RELAY0;DINT;DINT;0;
4;IN;CONFIG.MES5_INT_COUNTER_IN;CONFIG.MES5_INT_COUNTER_IN;LINT;LINT;0;
5;OUT;CONFIG.MES5_INT_COUNTER_OUT;CONFIG.MES5_INT_COUNTER_OUT;LINT;LINT;0;
6;VAR;CONFIG.PYEXT_CSV_UPDATE;CONFIG.PYEXT_CSV_UPDATE;BOOL;BOOL;0;
7;FB;CONFIG.RESOURCE1.INSTANCE0;CONFIG.RESOURCE1.INSTANCE0;PLC_PRG;;0;
8;VAR;CONFIG.RESOURCE1.INSTANCE0.RESET;CONFIG.RESOURCE1.INSTANCE0.RESET;BOOL;BOOL;0;
9;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT0;CONFIG.RESOURCE1.INSTANCE0.CNT0;INT;INT;0;
10;VAR;CONFIG.RESOURCE1.INSTANCE0.CNT1;CONFIG.RESOURCE1.INSTANCE0.CNT1;INT;INT;0;
11;FB;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0;COUNTERST;;0;
12;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.EN;BOOL;BOOL;0;
13;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.ENO;BOOL;BOOL;0;
14;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESET;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESET;BOOL;BOOL;0;
15;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT1;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT1;INT;INT;0;
16;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OUT0;INT;INT;0;
17;VAR;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.CNT0;INT;INT;0;
18;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.RESETCOUNTERVALUE;INT;INT;0;
19;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OI_SENSOR_COUNTER;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.OI_SENSOR_COUNTER;LREAL;LREAL;0;
20;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.VFD_RELAY0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.VFD_RELAY0;DINT;DINT;0;
21;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.AIR_VALVE_RELAY0;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.AIR_VALVE_RELAY0;DINT;DINT;0;
22;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.MES5_INT_COUNTER_IN;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.MES5_INT_COUNTER_IN;LINT;LINT;0;
23;EXT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.MES5_INT_COUNTER_OUT;CONFIG.RESOURCE1.INSTANCE0.COUNTERST0.MES5_INT_COUNTER_OUT;LINT;LINT;0;
// Ticktime
50000000
#ifndef _BEREMIZ_H_
#define _BEREMIZ_H_
/* Beremiz' header file for use by extensions */
#include "iec_types.h"
#define LOG_LEVELS 4
#define LOG_CRITICAL 0
#define LOG_WARNING 1
#define LOG_INFO 2
#define LOG_DEBUG 3
extern unsigned long long common_ticktime__;
#ifdef TARGET_LOGGING_DISABLE
static inline int LogMessage(uint8_t level, char* buf, uint32_t size)
{
(void)level;
(void)buf;
(void)size;
return 0;
}
#else
int LogMessage(uint8_t level, char* buf, uint32_t size);
#endif
long AtomicCompareExchange(long* atomicvar,long compared, long exchange);
void *create_RT_to_nRT_signal(char* name);
void delete_RT_to_nRT_signal(void* handle);
int wait_RT_to_nRT_signal(void* handle);
int unblock_RT_to_nRT_signal(void* handle);
void nRT_reschedule(void);
#ifdef REALTIME_LINUX
#ifndef PLC_THREAD_PRIORITY
#define PLC_THREAD_PRIORITY 80
#endif
#endif
#endif
/*******************************************/
/* FILE GENERATED BY iec2c */
/* Editing this file is not recommended... */
/*******************************************/
#include "iec_std_lib.h"
#include "accessor.h"
#include "POUS.h"
// CONFIGURATION CONFIG
__DECLARE_GLOBAL(INT,CONFIG,RESETCOUNTERVALUE)
__DECLARE_GLOBAL_LOCATION(LREAL,__IL1_2)
__DECLARE_GLOBAL_LOCATED(LREAL,CONFIG,OI_SENSOR_COUNTER)
__DECLARE_GLOBAL_LOCATION(DINT,__QD0_0)
__DECLARE_GLOBAL_LOCATED(DINT,CONFIG,VFD_RELAY0)
__DECLARE_GLOBAL_LOCATION(DINT,__QD0_1)
__DECLARE_GLOBAL_LOCATED(DINT,CONFIG,AIR_VALVE_RELAY0)
__DECLARE_GLOBAL_LOCATION(LINT,__IL2_2)
__DECLARE_GLOBAL_LOCATED(LINT,CONFIG,MES5_INT_COUNTER_IN)
__DECLARE_GLOBAL_LOCATION(LINT,__QL2_2)
__DECLARE_GLOBAL_LOCATED(LINT,CONFIG,MES5_INT_COUNTER_OUT)
__DECLARE_GLOBAL(BOOL,CONFIG,PYEXT_CSV_UPDATE)
void RESOURCE1_init__(void);
void config_init__(void) {
BOOL retain;
retain = 0;
__INIT_GLOBAL(INT,RESETCOUNTERVALUE,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,OI_SENSOR_COUNTER,__IL1_2,retain)
__INIT_GLOBAL(LREAL,OI_SENSOR_COUNTER,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,VFD_RELAY0,__QD0_0,retain)
__INIT_GLOBAL(DINT,VFD_RELAY0,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,AIR_VALVE_RELAY0,__QD0_1,retain)
__INIT_GLOBAL(DINT,AIR_VALVE_RELAY0,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,MES5_INT_COUNTER_IN,__IL2_2,retain)
__INIT_GLOBAL(LINT,MES5_INT_COUNTER_IN,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL_LOCATED(CONFIG,MES5_INT_COUNTER_OUT,__QL2_2,retain)
__INIT_GLOBAL(LINT,MES5_INT_COUNTER_OUT,__INITIAL_VALUE(0),retain)
__INIT_GLOBAL(BOOL,PYEXT_CSV_UPDATE,__INITIAL_VALUE(__BOOL_LITERAL(TRUE)),retain)
RESOURCE1_init__();
}
void RESOURCE1_run__(unsigned long tick);
void config_run__(unsigned long tick) {
RESOURCE1_run__(tick);
}
unsigned long long common_ticktime__ = 50000000ULL * 1ULL; /*ns*/
unsigned long greatest_tick_count__ = (unsigned long)0UL; /*tick*/
#include "beremiz.h"
__DECLARE_GLOBAL_PROTOTYPE(INT,RESETCOUNTERVALUE)
__DECLARE_GLOBAL_PROTOTYPE(LREAL,OI_SENSOR_COUNTER)
__DECLARE_GLOBAL_PROTOTYPE(DINT,VFD_RELAY0)
__DECLARE_GLOBAL_PROTOTYPE(DINT,AIR_VALVE_RELAY0)
__DECLARE_GLOBAL_PROTOTYPE(LINT,MES5_INT_COUNTER_IN)
__DECLARE_GLOBAL_PROTOTYPE(LINT,MES5_INT_COUNTER_OUT)
__DECLARE_GLOBAL_PROTOTYPE(BOOL,PYEXT_CSV_UPDATE)
import csv
from collections import OrderedDict
csv_int_files = {}
def CSVRdInt(fname, rowidx, colidx):
"""
Return value at row/column pointed by integer indexes
Assumes data starts at first row and first column, no headers.
"""
global csv_int_files
data = csv_int_files.get(fname, None)
if data is None:
data = list()
try:
csvfile = open(fname, 'rb')
except IOError:
return "#FILE_NOT_FOUND"
try:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
for row in reader:
data.append(row)
except csv.Error:
return "#CSV_ERROR"
finally:
csvfile.close()
csv_int_files[fname] = data
try:
row = data[rowidx]
except IndexError:
return "#ROW_NOT_FOUND"
try:
return row[colidx]
except IndexError:
return "#COL_NOT_FOUND"
csv_str_files = {}
def CSVRdStr(fname, rowname, colname):
"""
Return value at row/column pointed by a pair of names as string
Assumes first row is column headers and first column is row name.
"""
global csv_str_files
entry = csv_str_files.get(fname, None)
if entry is None:
data = dict()
try:
csvfile = open(fname, 'rb')
except IOError:
return "#FILE_NOT_FOUND"
try:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
headers = dict([(name, index) for index, name in enumerate(reader.next()[1:])])
for row in reader:
data[row[0]] = row[1:]
except csv.Error:
return "#CSV_ERROR"
finally:
csvfile.close()
csv_str_files[fname] = (headers, data)
else:
headers, data = entry
try:
row = data[rowname]
except KeyError:
return "#ROW_NOT_FOUND"
try:
colidx = headers[colname]
except KeyError:
return "#COL_NOT_FOUND"
try:
return row[colidx]
except IndexError:
return "#COL_NOT_FOUND"
def pyext_csv_reload():
global csv_int_files, csv_str_files
csv_int_files.clear()
csv_str_files.clear()
FUNCTION_BLOCK CounterST
VAR_INPUT
Reset : BOOL;
END_VAR
VAR_OUTPUT
Out1 : INT;
Out0 : INT;
END_VAR
VAR
Cnt0 : INT;
END_VAR
VAR_EXTERNAL
ResetCounterValue : INT;
OI_sensor_counter : LREAL;
VFD_relay0 : DINT;
Air_Valve_Relay0 : DINT;
MES5_int_counter_in : LINT;
MES5_int_counter_out : LINT;
END_VAR
(* this will always switch on VFD_relay0 which controls conveyor line*)
VFD_relay0 := 1;
IF OI_sensor_counter=2.0 THEN
(* a rectangle was recognized thus switch ON air valve *)
Air_Valve_Relay0 := 1;
(* read from MES5 counter value so we continue from where we were. In this case
increment blow counter at MES5*)
MES5_int_counter_in := MES5_int_counter_in + 1;
(* set to MES5 the counter value so it is kept permanently *)
MES5_int_counter_out := MES5_int_counter_in;
END_IF;
IF OI_sensor_counter=0.0 OR OI_sensor_counter=1.0 OR OI_sensor_counter=3.0 THEN
(* a circle / triangle or nothing was recognized thus switch OFF air valve *)
Air_Valve_Relay0 := 0;
END_IF;
END_FUNCTION_BLOCK
PROGRAM plc_prg
VAR_INPUT
Reset : BOOL;
END_VAR
VAR_OUTPUT
Cnt0 : INT;
Cnt1 : INT;
END_VAR
VAR
CounterST0 : CounterST;
END_VAR
CounterST0(Reset := Reset);
Cnt1 := CounterST0.Out1;
Cnt0 := CounterST0.Out0;
END_PROGRAM
CONFIGURATION config
VAR_GLOBAL
ResetCounterValue : INT := 0;
OI_sensor_counter AT %IL1.2 : LREAL;
VFD_relay0 AT %QD0.0 : DINT;
Air_Valve_Relay0 AT %QD0.1 : DINT;
MES5_int_counter_in AT %IL2.2 : LINT;
MES5_int_counter_out AT %QL2.2 : LINT;
END_VAR
VAR_GLOBAL
pyext_csv_update : BOOL := TRUE;
END_VAR
RESOURCE resource1 ON PLC
TASK task0(INTERVAL := T#50ms,PRIORITY := 0);
PROGRAM instance0 WITH task0 : plc_prg;
END_RESOURCE
END_CONFIGURATION
e68d19e5f7e402decececb757d5ae127
\ No newline at end of file
#include "beremiz.h"
/* code generated by beremiz OPC-UA extension */
#include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/plugin/securitypolicy.h>
#include <open62541/plugin/securitypolicy_default.h>
#include <open62541/types.h>
#include <open62541/types_generated_handling.h>
#define _Log(level, ...) \
{ \
char mstr[256]; \
snprintf(mstr, 255, __VA_ARGS__); \
LogMessage(level, mstr, strlen(mstr)); \
}
#define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__);
#define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__);
#define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__);
static UA_INLINE UA_ByteString
loadFile(const char *const path) {
UA_ByteString fileContents = UA_STRING_NULL;
FILE *fp = fopen(path, "rb");
if(!fp) {
errno = 0;
LogError("OPC-UA could not open %s", path);
return fileContents;
}
fseek(fp, 0, SEEK_END);
fileContents.length = (size_t)ftell(fp);
fileContents.data = (UA_Byte *)UA_malloc(fileContents.length * sizeof(UA_Byte));
if(fileContents.data) {
fseek(fp, 0, SEEK_SET);
size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
if(read != fileContents.length){
UA_ByteString_clear(&fileContents);
LogError("OPC-UA could not read %s", path);
}
} else {
fileContents.length = 0;
LogError("OPC-UA Not enough memoty to load %s", path);
}
fclose(fp);
return fileContents;
}
static UA_Client *client;
static UA_ClientConfig *cc;
#define DECL_VAR(ua_type, C_type, c_loc_name) \
static UA_Variant c_loc_name##_variant; \
static C_type c_loc_name##_buf = 0; \
C_type *c_loc_name = &c_loc_name##_buf;
DECL_VAR(UA_Int32, uint32_t, __ID0_0)
DECL_VAR(UA_Int32, uint32_t, __ID0_1)
DECL_VAR(UA_Int32, uint32_t, __QD0_0)
DECL_VAR(UA_Int32, uint32_t, __QD0_1)
void __cleanup_0(void)
{
UA_Client_disconnect(client);
UA_Client_delete(client);
}
#define INIT_NoAuth() \
LogInfo("OPC-UA Init no auth"); \
UA_ClientConfig_setDefault(cc); \
retval = UA_Client_connect(client, uri);
/* Note : Single policy is enforced here, by default open62541 client supports all policies */
#define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate) \
LogInfo("OPC-UA Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate); \
\
UA_ByteString certificate = loadFile(Certificate); \
UA_ByteString privateKey = loadFile(PrivateKey); \
\
cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode; \
\
/* replacement for default behaviour */ \
/* UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0); */ \
do{ \
retval = UA_ClientConfig_setDefault(cc); \
if(retval != UA_STATUSCODE_GOOD) \
break; \
\
UA_SecurityPolicy *sp = (UA_SecurityPolicy*) \
UA_realloc(cc->securityPolicies, sizeof(UA_SecurityPolicy) * 2); \
if(!sp){ \
retval = UA_STATUSCODE_BADOUTOFMEMORY; \
break; \
} \
cc->securityPolicies = sp; \
\
retval = UA_SecurityPolicy_##Policy(&cc->securityPolicies[cc->securityPoliciesSize], \
certificate, privateKey, &cc->logger); \
if(retval != UA_STATUSCODE_GOOD) { \
UA_LOG_WARNING(&cc->logger, UA_LOGCATEGORY_USERLAND, \
"Could not add SecurityPolicy Policy with error code %s", \
UA_StatusCode_name(retval)); \
UA_free(cc->securityPolicies); \
cc->securityPolicies = NULL; \
break; \
} \
\
++cc->securityPoliciesSize; \
} while(0); \
\
retval = UA_Client_connect(client, uri); \
\
UA_ByteString_clear(&certificate); \
UA_ByteString_clear(&privateKey);
#define INIT_UserPassword(User, Password) \
LogInfo("OPC-UA Init UserPassword %s,%s", User, Password); \
UA_ClientConfig_setDefault(cc); \
retval = UA_Client_connectUsername(client, uri, User, Password);
#define INIT_READ_VARIANT(ua_type, c_loc_name) \
UA_Variant_init(&c_loc_name##_variant);
#define INIT_WRITE_VARIANT(ua_type, ua_type_enum, c_loc_name) \
UA_Variant_setScalar(&c_loc_name##_variant, (ua_type*)c_loc_name, &UA_TYPES[ua_type_enum]);
int __init_0(int argc,char **argv)
{
UA_StatusCode retval;
client = UA_Client_new();
cc = UA_Client_getConfig(client);
char *uri = "opc.tcp://192.168.0.135:4840";
INIT_NoAuth()
INIT_READ_VARIANT(UA_Int32, __ID0_0)
INIT_READ_VARIANT(UA_Int32, __ID0_1)
INIT_WRITE_VARIANT(UA_Int32, UA_TYPES_INT32, __QD0_0)
INIT_WRITE_VARIANT(UA_Int32, UA_TYPES_INT32, __QD0_1)
if(retval != UA_STATUSCODE_GOOD) {
LogError("OPC-UA Init Failed %d", retval);
UA_Client_delete(client);
return EXIT_FAILURE;
}
return 0;
}
#define READ_VALUE(ua_type, ua_type_enum, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \
retval = UA_Client_readValueAttribute( \
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); \
if(retval == UA_STATUSCODE_GOOD && UA_Variant_isScalar(&c_loc_name##_variant) && \
c_loc_name##_variant.type == &UA_TYPES[ua_type_enum]) { \
c_loc_name##_buf = *(ua_type*)c_loc_name##_variant.data; \
UA_Variant_clear(&c_loc_name##_variant); /* Unalloc requiered on each read ! */ \
}
void __retrieve_0(void)
{
UA_StatusCode retval;
READ_VALUE(UA_Int32, UA_TYPES_INT32, __ID0_0, UA_NODEID_STRING, 1, "i2c0.relay0")
READ_VALUE(UA_Int32, UA_TYPES_INT32, __ID0_1, UA_NODEID_STRING, 1, "i2c0.relay1")
}
#define WRITE_VALUE(ua_type, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \
UA_Client_writeValueAttribute( \
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant);
void __publish_0(void)
{
WRITE_VALUE(UA_Int32, __QD0_0, UA_NODEID_STRING, 1, "i2c0.relay0")
WRITE_VALUE(UA_Int32, __QD0_1, UA_NODEID_STRING, 1, "i2c0.relay1")
}
#include "beremiz.h"
/* code generated by beremiz OPC-UA extension */
#include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/plugin/securitypolicy.h>
#include <open62541/plugin/securitypolicy_default.h>
#include <open62541/types.h>
#include <open62541/types_generated_handling.h>
#define _Log(level, ...) \
{ \
char mstr[256]; \
snprintf(mstr, 255, __VA_ARGS__); \
LogMessage(level, mstr, strlen(mstr)); \
}
#define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__);
#define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__);
#define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__);
static UA_INLINE UA_ByteString
loadFile(const char *const path) {
UA_ByteString fileContents = UA_STRING_NULL;
FILE *fp = fopen(path, "rb");
if(!fp) {
errno = 0;
LogError("OPC-UA could not open %s", path);
return fileContents;
}
fseek(fp, 0, SEEK_END);
fileContents.length = (size_t)ftell(fp);
fileContents.data = (UA_Byte *)UA_malloc(fileContents.length * sizeof(UA_Byte));
if(fileContents.data) {
fseek(fp, 0, SEEK_SET);
size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
if(read != fileContents.length){
UA_ByteString_clear(&fileContents);
LogError("OPC-UA could not read %s", path);
}
} else {
fileContents.length = 0;
LogError("OPC-UA Not enough memoty to load %s", path);
}
fclose(fp);
return fileContents;
}
static UA_Client *client;
static UA_ClientConfig *cc;
#define DECL_VAR(ua_type, C_type, c_loc_name) \
static UA_Variant c_loc_name##_variant; \
static C_type c_loc_name##_buf = 0; \
C_type *c_loc_name = &c_loc_name##_buf;
DECL_VAR(UA_Double, double, __IL1_2)
DECL_VAR(UA_Double, double, __QL1_2)
void __cleanup_1(void)
{
UA_Client_disconnect(client);
UA_Client_delete(client);
}
#define INIT_NoAuth() \
LogInfo("OPC-UA Init no auth"); \
UA_ClientConfig_setDefault(cc); \
retval = UA_Client_connect(client, uri);
/* Note : Single policy is enforced here, by default open62541 client supports all policies */
#define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate) \
LogInfo("OPC-UA Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate); \
\
UA_ByteString certificate = loadFile(Certificate); \
UA_ByteString privateKey = loadFile(PrivateKey); \
\
cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode; \
\
/* replacement for default behaviour */ \
/* UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0); */ \
do{ \
retval = UA_ClientConfig_setDefault(cc); \
if(retval != UA_STATUSCODE_GOOD) \
break; \
\
UA_SecurityPolicy *sp = (UA_SecurityPolicy*) \
UA_realloc(cc->securityPolicies, sizeof(UA_SecurityPolicy) * 2); \
if(!sp){ \
retval = UA_STATUSCODE_BADOUTOFMEMORY; \
break; \
} \
cc->securityPolicies = sp; \
\
retval = UA_SecurityPolicy_##Policy(&cc->securityPolicies[cc->securityPoliciesSize], \
certificate, privateKey, &cc->logger); \
if(retval != UA_STATUSCODE_GOOD) { \
UA_LOG_WARNING(&cc->logger, UA_LOGCATEGORY_USERLAND, \
"Could not add SecurityPolicy Policy with error code %s", \
UA_StatusCode_name(retval)); \
UA_free(cc->securityPolicies); \
cc->securityPolicies = NULL; \
break; \
} \
\
++cc->securityPoliciesSize; \
} while(0); \
\
retval = UA_Client_connect(client, uri); \
\
UA_ByteString_clear(&certificate); \
UA_ByteString_clear(&privateKey);
#define INIT_UserPassword(User, Password) \
LogInfo("OPC-UA Init UserPassword %s,%s", User, Password); \
UA_ClientConfig_setDefault(cc); \
retval = UA_Client_connectUsername(client, uri, User, Password);
#define INIT_READ_VARIANT(ua_type, c_loc_name) \
UA_Variant_init(&c_loc_name##_variant);
#define INIT_WRITE_VARIANT(ua_type, ua_type_enum, c_loc_name) \
UA_Variant_setScalar(&c_loc_name##_variant, (ua_type*)c_loc_name, &UA_TYPES[ua_type_enum]);
int __init_1(int argc,char **argv)
{
UA_StatusCode retval;
client = UA_Client_new();
cc = UA_Client_getConfig(client);
char *uri = "opc.tcp://192.168.0.118:4840";
INIT_NoAuth()
INIT_READ_VARIANT(UA_Double, __IL1_2)
INIT_WRITE_VARIANT(UA_Double, UA_TYPES_DOUBLE, __QL1_2)
if(retval != UA_STATUSCODE_GOOD) {
LogError("OPC-UA Init Failed %d", retval);
UA_Client_delete(client);
return EXIT_FAILURE;
}
return 0;
}
#define READ_VALUE(ua_type, ua_type_enum, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \
retval = UA_Client_readValueAttribute( \
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); \
if(retval == UA_STATUSCODE_GOOD && UA_Variant_isScalar(&c_loc_name##_variant) && \
c_loc_name##_variant.type == &UA_TYPES[ua_type_enum]) { \
c_loc_name##_buf = *(ua_type*)c_loc_name##_variant.data; \
UA_Variant_clear(&c_loc_name##_variant); /* Unalloc requiered on each read ! */ \
}
void __retrieve_1(void)
{
UA_StatusCode retval;
READ_VALUE(UA_Double, UA_TYPES_DOUBLE, __IL1_2, UA_NODEID_NUMERIC, 2, 2)
}
#define WRITE_VALUE(ua_type, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \
UA_Client_writeValueAttribute( \
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant);
void __publish_1(void)
{
WRITE_VALUE(UA_Double, __QL1_2, UA_NODEID_NUMERIC, 2, 2)
}
#include "beremiz.h"
/* code generated by beremiz OPC-UA extension */
#include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>
#include <open62541/plugin/log_stdout.h>
#include <open62541/plugin/securitypolicy.h>
#include <open62541/plugin/securitypolicy_default.h>
#include <open62541/types.h>
#include <open62541/types_generated_handling.h>
#define _Log(level, ...) \
{ \
char mstr[256]; \
snprintf(mstr, 255, __VA_ARGS__); \
LogMessage(level, mstr, strlen(mstr)); \
}
#define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__);
#define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__);
#define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__);
static UA_INLINE UA_ByteString
loadFile(const char *const path) {
UA_ByteString fileContents = UA_STRING_NULL;
FILE *fp = fopen(path, "rb");
if(!fp) {
errno = 0;
LogError("OPC-UA could not open %s", path);
return fileContents;
}
fseek(fp, 0, SEEK_END);
fileContents.length = (size_t)ftell(fp);
fileContents.data = (UA_Byte *)UA_malloc(fileContents.length * sizeof(UA_Byte));
if(fileContents.data) {
fseek(fp, 0, SEEK_SET);
size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
if(read != fileContents.length){
UA_ByteString_clear(&fileContents);
LogError("OPC-UA could not read %s", path);
}
} else {
fileContents.length = 0;
LogError("OPC-UA Not enough memoty to load %s", path);
}
fclose(fp);
return fileContents;
}
static UA_Client *client;
static UA_ClientConfig *cc;
#define DECL_VAR(ua_type, C_type, c_loc_name) \
static UA_Variant c_loc_name##_variant; \
static C_type c_loc_name##_buf = 0; \
C_type *c_loc_name = &c_loc_name##_buf;
DECL_VAR(UA_Int64, int64_t, __IL2_2)
DECL_VAR(UA_Int64, int64_t, __QL2_2)
void __cleanup_2(void)
{
UA_Client_disconnect(client);
UA_Client_delete(client);
}
#define INIT_NoAuth() \
LogInfo("OPC-UA Init no auth"); \
UA_ClientConfig_setDefault(cc); \
retval = UA_Client_connect(client, uri);
/* Note : Single policy is enforced here, by default open62541 client supports all policies */
#define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate) \
LogInfo("OPC-UA Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate); \
\
UA_ByteString certificate = loadFile(Certificate); \
UA_ByteString privateKey = loadFile(PrivateKey); \
\
cc->securityMode = UA_MESSAGESECURITYMODE_##UpperCaseMode; \
\
/* replacement for default behaviour */ \
/* UA_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0); */ \
do{ \
retval = UA_ClientConfig_setDefault(cc); \
if(retval != UA_STATUSCODE_GOOD) \
break; \
\
UA_SecurityPolicy *sp = (UA_SecurityPolicy*) \
UA_realloc(cc->securityPolicies, sizeof(UA_SecurityPolicy) * 2); \
if(!sp){ \
retval = UA_STATUSCODE_BADOUTOFMEMORY; \
break; \
} \
cc->securityPolicies = sp; \
\
retval = UA_SecurityPolicy_##Policy(&cc->securityPolicies[cc->securityPoliciesSize], \
certificate, privateKey, &cc->logger); \
if(retval != UA_STATUSCODE_GOOD) { \
UA_LOG_WARNING(&cc->logger, UA_LOGCATEGORY_USERLAND, \
"Could not add SecurityPolicy Policy with error code %s", \
UA_StatusCode_name(retval)); \
UA_free(cc->securityPolicies); \
cc->securityPolicies = NULL; \
break; \
} \
\
++cc->securityPoliciesSize; \
} while(0); \
\
retval = UA_Client_connect(client, uri); \
\
UA_ByteString_clear(&certificate); \
UA_ByteString_clear(&privateKey);
#define INIT_UserPassword(User, Password) \
LogInfo("OPC-UA Init UserPassword %s,%s", User, Password); \
UA_ClientConfig_setDefault(cc); \
retval = UA_Client_connectUsername(client, uri, User, Password);
#define INIT_READ_VARIANT(ua_type, c_loc_name) \
UA_Variant_init(&c_loc_name##_variant);
#define INIT_WRITE_VARIANT(ua_type, ua_type_enum, c_loc_name) \
UA_Variant_setScalar(&c_loc_name##_variant, (ua_type*)c_loc_name, &UA_TYPES[ua_type_enum]);
int __init_2(int argc,char **argv)
{
UA_StatusCode retval;
client = UA_Client_new();
cc = UA_Client_getConfig(client);
char *uri = "opc.tcp://192.168.0.118:4841";
INIT_NoAuth()
INIT_READ_VARIANT(UA_Int64, __IL2_2)
INIT_WRITE_VARIANT(UA_Int64, UA_TYPES_INT64, __QL2_2)
if(retval != UA_STATUSCODE_GOOD) {
LogError("OPC-UA Init Failed %d", retval);
UA_Client_delete(client);
return EXIT_FAILURE;
}
return 0;
}
#define READ_VALUE(ua_type, ua_type_enum, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \
retval = UA_Client_readValueAttribute( \
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); \
if(retval == UA_STATUSCODE_GOOD && UA_Variant_isScalar(&c_loc_name##_variant) && \
c_loc_name##_variant.type == &UA_TYPES[ua_type_enum]) { \
c_loc_name##_buf = *(ua_type*)c_loc_name##_variant.data; \
UA_Variant_clear(&c_loc_name##_variant); /* Unalloc requiered on each read ! */ \
}
void __retrieve_2(void)
{
UA_StatusCode retval;
READ_VALUE(UA_Int64, UA_TYPES_INT64, __IL2_2, UA_NODEID_NUMERIC, 2, 2)
}
#define WRITE_VALUE(ua_type, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \
UA_Client_writeValueAttribute( \
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant);
void __publish_2(void)
{
WRITE_VALUE(UA_Int64, __QL2_2, UA_NODEID_NUMERIC, 2, 2)
}
TYPE
LOGLEVEL : (CRITICAL, WARNING, INFO, DEBUG) := INFO;
END_TYPE
FUNCTION_BLOCK LOGGER
VAR_INPUT
TRIG : BOOL;
MSG : STRING;
LEVEL : LOGLEVEL := INFO;
END_VAR
VAR
TRIG0 : BOOL;
END_VAR
IF TRIG AND NOT TRIG0 THEN
{{
LogMessage(GetFbVar(LEVEL),(char*)GetFbVar(MSG, .body),GetFbVar(MSG, .len));
}}
END_IF;
TRIG0:=TRIG;
END_FUNCTION_BLOCK
FUNCTION_BLOCK python_eval
VAR_INPUT
TRIG : BOOL;
CODE : STRING;
END_VAR
VAR_OUTPUT
ACK : BOOL;
RESULT : STRING;
END_VAR
VAR
STATE : DWORD;
BUFFER : STRING;
PREBUFFER : STRING;
TRIGM1 : BOOL;
TRIGGED : BOOL;
END_VAR
{extern void __PythonEvalFB(int, PYTHON_EVAL*);__PythonEvalFB(0, data__);}
END_FUNCTION_BLOCK
FUNCTION_BLOCK csv_read_by_string
VAR_EXTERNAL
pyext_csv_update : BOOL;
END_VAR
VAR_OUTPUT
ACK : BOOL;
RESULT : STRING;
END_VAR
VAR_INPUT
FILE_NAME : STRING;
ROW : STRING;
COLUMN : STRING;
END_VAR
VAR
OLDCODE : STRING;
py_eval : python_eval;
R_TRIG0 : R_TRIG;
R_TRIG1 : R_TRIG;
SR0 : SR;
_TMP_CONCAT7_OUT : STRING;
_TMP_NE16_OUT : BOOL;
_TMP_SEL18_OUT : STRING;
_TMP_OR15_OUT : BOOL;
_TMP_LEFT33_OUT : STRING;
_TMP_NE34_OUT : BOOL;
_TMP_AND39_OUT : BOOL;
R_TRIG2 : R_TRIG;
END_VAR
_TMP_CONCAT7_OUT := CONCAT('CSVRdStr("', FILE_NAME, '","', ROW, '","', COLUMN, '")');
_TMP_NE16_OUT := NE(_TMP_CONCAT7_OUT, OLDCODE);
_TMP_SEL18_OUT := SEL(_TMP_NE16_OUT, OLDCODE, _TMP_CONCAT7_OUT);
OLDCODE := _TMP_SEL18_OUT;
R_TRIG0(CLK := pyext_csv_update);
_TMP_OR15_OUT := OR(R_TRIG0.Q, _TMP_NE16_OUT);
py_eval(TRIG := _TMP_OR15_OUT, CODE := _TMP_CONCAT7_OUT);
R_TRIG1(CLK := py_eval.ACK);
_TMP_LEFT33_OUT := LEFT(py_eval.RESULT, 1);
_TMP_NE34_OUT := NE(_TMP_LEFT33_OUT, '#');
_TMP_AND39_OUT := AND(R_TRIG1.Q, _TMP_NE34_OUT);
R_TRIG2(CLK := _TMP_OR15_OUT);
SR0(S1 := _TMP_AND39_OUT, R := R_TRIG2.Q);
ACK := SR0.Q1;
RESULT := py_eval.RESULT;
END_FUNCTION_BLOCK
FUNCTION_BLOCK python_gear
VAR_INPUT
N : UINT;
TRIG : BOOL;
CODE : STRING;
END_VAR
VAR_OUTPUT
ACK : BOOL;
RESULT : STRING;
END_VAR
VAR
py_eval : python_eval;
COUNTER : UINT;
_TMP_ADD10_OUT : UINT;
_TMP_EQ13_OUT : BOOL;
_TMP_SEL15_OUT : UINT;
_TMP_AND7_OUT : BOOL;
END_VAR
_TMP_ADD10_OUT := ADD(COUNTER, 1);
_TMP_EQ13_OUT := EQ(N, _TMP_ADD10_OUT);
_TMP_SEL15_OUT := SEL(_TMP_EQ13_OUT, _TMP_ADD10_OUT, 0);
COUNTER := _TMP_SEL15_OUT;
_TMP_AND7_OUT := AND(_TMP_EQ13_OUT, TRIG);
py_eval(TRIG := _TMP_AND7_OUT, CODE := CODE);
ACK := py_eval.ACK;
RESULT := py_eval.RESULT;
END_FUNCTION_BLOCK
FUNCTION_BLOCK csv_reload
VAR_EXTERNAL
pyext_csv_update : BOOL;
END_VAR
VAR_OUTPUT
ACK : BOOL;
RESULT : STRING;
END_VAR
VAR
py_eval : python_eval;
END_VAR
VAR_INPUT
TRIG : BOOL;
END_VAR
VAR
R_TRIG0 : R_TRIG;
F_TRIG0 : F_TRIG;
_TMP_OR11_OUT : BOOL;
_TMP_NOT13_OUT : BOOL;
_TMP_MOVE12_ENO : BOOL;
_TMP_MOVE12_OUT : BOOL;
END_VAR
py_eval(TRIG := TRIG, CODE := 'pyext_csv_reload()');
R_TRIG0(CLK := py_eval.ACK);
F_TRIG0(CLK := py_eval.ACK);
_TMP_OR11_OUT := OR(R_TRIG0.Q, F_TRIG0.Q);
_TMP_NOT13_OUT := NOT(R_TRIG0.Q);
_TMP_MOVE12_OUT := MOVE(EN := _TMP_OR11_OUT, IN := _TMP_NOT13_OUT, ENO => _TMP_MOVE12_ENO);
IF _TMP_MOVE12_ENO THEN
pyext_csv_update := _TMP_MOVE12_OUT;
END_IF;
ACK := py_eval.ACK;
RESULT := py_eval.RESULT;
END_FUNCTION_BLOCK
FUNCTION_BLOCK csv_read_by_int
VAR_EXTERNAL
pyext_csv_update : BOOL;
END_VAR
VAR_OUTPUT
ACK : BOOL;
RESULT : STRING;
END_VAR
VAR_INPUT
FILE_NAME : STRING;
ROW : INT;
COLUMN : INT;
END_VAR
VAR
OLDCODE : STRING;
py_eval0 : python_eval;
R_TRIG1 : R_TRIG;
R_TRIG2 : R_TRIG;
SR0 : SR;
_TMP_INT_TO_STRING31_OUT : STRING;
_TMP_INT_TO_STRING2_OUT : STRING;
_TMP_CONCAT7_OUT : STRING;
_TMP_NE16_OUT : BOOL;
_TMP_SEL18_OUT : STRING;
_TMP_OR15_OUT : BOOL;
_TMP_LEFT33_OUT : STRING;
_TMP_NE34_OUT : BOOL;
_TMP_AND39_OUT : BOOL;
R_TRIG3 : R_TRIG;
END_VAR
_TMP_INT_TO_STRING31_OUT := INT_TO_STRING(ROW);
_TMP_INT_TO_STRING2_OUT := INT_TO_STRING(COLUMN);
_TMP_CONCAT7_OUT := CONCAT('CSVRdInt("', FILE_NAME, '",', _TMP_INT_TO_STRING31_OUT, ',', _TMP_INT_TO_STRING2_OUT, ')');
_TMP_NE16_OUT := NE(_TMP_CONCAT7_OUT, OLDCODE);
_TMP_SEL18_OUT := SEL(_TMP_NE16_OUT, OLDCODE, _TMP_CONCAT7_OUT);
OLDCODE := _TMP_SEL18_OUT;
R_TRIG1(CLK := pyext_csv_update);
_TMP_OR15_OUT := OR(R_TRIG1.Q, _TMP_NE16_OUT);
py_eval0(TRIG := _TMP_OR15_OUT, CODE := _TMP_CONCAT7_OUT);
R_TRIG2(CLK := py_eval0.ACK);
_TMP_LEFT33_OUT := LEFT(py_eval0.RESULT, 1);
_TMP_NE34_OUT := NE(_TMP_LEFT33_OUT, '#');
_TMP_AND39_OUT := AND(R_TRIG2.Q, _TMP_NE34_OUT);
R_TRIG3(CLK := _TMP_OR15_OUT);
SR0(S1 := _TMP_AND39_OUT, R := R_TRIG3.Q);
ACK := SR0.Q1;
RESULT := py_eval0.RESULT;
END_FUNCTION_BLOCK
FUNCTION_BLOCK python_poll
VAR_INPUT
TRIG : BOOL;
CODE : STRING;
END_VAR
VAR_OUTPUT
ACK : BOOL;
RESULT : STRING;
END_VAR
VAR
STATE : DWORD;
BUFFER : STRING;
PREBUFFER : STRING;
TRIGM1 : BOOL;
TRIGGED : BOOL;
END_VAR
{extern void __PythonEvalFB(int, PYTHON_EVAL*);__PythonEvalFB(1,(PYTHON_EVAL*)(void*)data__);}
END_FUNCTION_BLOCK
FUNCTION_BLOCK CounterST
VAR_INPUT
Reset : BOOL;
END_VAR
VAR_OUTPUT
Out1 : INT;
Out0 : INT;
END_VAR
VAR
Cnt0 : INT;
END_VAR
VAR_EXTERNAL
ResetCounterValue : INT;
OI_sensor_counter : LREAL;
VFD_relay0 : DINT;
Air_Valve_Relay0 : DINT;
MES5_int_counter_in : LINT;
MES5_int_counter_out : LINT;
END_VAR
(* this will always switch on VFD_relay0 which controls conveyor line*)
VFD_relay0 := 1;
IF OI_sensor_counter=2.0 THEN
(* a rectangle was recognized thus switch ON air valve *)
Air_Valve_Relay0 := 1;
(* read from MES5 counter value so we continue from where we were. In this case
increment blow counter at MES5*)
MES5_int_counter_in := MES5_int_counter_in + 1;
(* set to MES5 the counter value so it is kept permanently *)
MES5_int_counter_out := MES5_int_counter_in;
END_IF;
IF OI_sensor_counter=0.0 OR OI_sensor_counter=1.0 OR OI_sensor_counter=3.0 THEN
(* a circle / triangle or nothing was recognized thus switch OFF air valve *)
Air_Valve_Relay0 := 0;
END_IF;
END_FUNCTION_BLOCK
PROGRAM plc_prg
VAR_INPUT
Reset : BOOL;
END_VAR
VAR_OUTPUT
Cnt0 : INT;
Cnt1 : INT;
END_VAR
VAR
CounterST0 : CounterST;
END_VAR
CounterST0(Reset := Reset);
Cnt1 := CounterST0.Out1;
Cnt0 := CounterST0.Out0;
END_PROGRAM
CONFIGURATION config
VAR_GLOBAL
ResetCounterValue : INT := 0;
OI_sensor_counter AT %IL1.2 : LREAL;
VFD_relay0 AT %QD0.0 : DINT;
Air_Valve_Relay0 AT %QD0.1 : DINT;
MES5_int_counter_in AT %IL2.2 : LINT;
MES5_int_counter_out AT %QL2.2 : LINT;
END_VAR
VAR_GLOBAL
pyext_csv_update : BOOL := TRUE;
END_VAR
RESOURCE resource1 ON PLC
TASK task0(INTERVAL := T#50ms,PRIORITY := 0);
PROGRAM instance0 WITH task0 : plc_prg;
END_RESOURCE
END_CONFIGURATION
This diff is collapsed.
This diff is collapsed.
/*
* Python Asynchronous execution code
*
* PLC put python commands in a fifo, respecting execution order
* with the help of C pragmas inserted in python_eval FB code
*
* Buffer content is read asynchronously, (from non real time part),
* commands are executed and result stored for later use by PLC.
*
* In this implementation, fifo is a list of pointer to python_eval
* function blocks structures. Some local variables have been added in
* python_eval interface. We use those local variables as buffer and state
* flags.
*
* */
#include "iec_types_all.h"
#include "POUS.h"
#include <string.h>
/* The fifo (fixed size, as number of FB is fixed) */
static PYTHON_EVAL* EvalFBs[1];
/* Producer and consumer cursors */
static int Current_PLC_EvalFB;
static int Current_Python_EvalFB;
/* A global IEC-Python gateway state, for use inside python_eval FBs*/
static int PythonState;
#define PYTHON_LOCKED_BY_PYTHON 0
#define PYTHON_LOCKED_BY_PLC 1
#define PYTHON_MUSTWAKEUP 2
#define PYTHON_FINISHED 4
/* Each python_eval FunctionBlock have it own state */
#define PYTHON_FB_FREE 0
#define PYTHON_FB_REQUESTED 1
#define PYTHON_FB_PROCESSING 2
#define PYTHON_FB_ANSWERED 3
int WaitPythonCommands(void);
void UnBlockPythonCommands(void);
int TryLockPython(void);
void UnLockPython(void);
void LockPython(void);
int __init_py_ext()
{
int i;
/* Initialize cursors */
Current_Python_EvalFB = 0;
Current_PLC_EvalFB = 0;
PythonState = PYTHON_LOCKED_BY_PYTHON;
for(i = 0; i < 1; i++)
EvalFBs[i] = NULL;
return 0;
}
void __cleanup_py_ext()
{
PythonState = PYTHON_FINISHED;
UnBlockPythonCommands();
}
void __retrieve_py_ext()
{
/* Check Python thread is not being
* modifying internal python_eval data */
PythonState = TryLockPython() ?
PYTHON_LOCKED_BY_PLC :
PYTHON_LOCKED_BY_PYTHON;
/* If python thread _is_ in, then PythonState remains PYTHON_LOCKED_BY_PYTHON
* and python_eval will no do anything */
}
void __publish_py_ext()
{
if(PythonState & PYTHON_LOCKED_BY_PLC){
/* If runnig PLC did push something in the fifo*/
if(PythonState & PYTHON_MUSTWAKEUP){
/* WakeUp python thread */
UnBlockPythonCommands();
}
UnLockPython();
}
}
/**
* Called by the PLC, each time a python_eval
* FB instance is executed
*/
void __PythonEvalFB(int poll, PYTHON_EVAL* data__)
{
if(!__GET_VAR(data__->TRIG)){
/* ACK is False when TRIG is false, except a pulse when receiving result */
__SET_VAR(data__->, ACK,, 0);
}
/* detect rising edge on TRIG to trigger evaluation */
if(((__GET_VAR(data__->TRIG) && !__GET_VAR(data__->TRIGM1)) ||
/* polling is equivalent to trig on value rather than on rising edge*/
(poll && __GET_VAR(data__->TRIG) )) &&
/* trig only if not already trigged */
__GET_VAR(data__->TRIGGED) == 0){
/* mark as trigged */
__SET_VAR(data__->, TRIGGED,, 1);
/* make a safe copy of the code */
__SET_VAR(data__->, PREBUFFER,, __GET_VAR(data__->CODE));
}
/* retain value for next rising edge detection */
__SET_VAR(data__->, TRIGM1,, __GET_VAR(data__->TRIG));
/* python thread is not in ? */
if( PythonState & PYTHON_LOCKED_BY_PLC){
/* if some answer are waiting, publish*/
if(__GET_VAR(data__->STATE) == PYTHON_FB_ANSWERED){
/* Copy buffer content into result*/
__SET_VAR(data__->, RESULT,, __GET_VAR(data__->BUFFER));
/* signal result presence to PLC*/
__SET_VAR(data__->, ACK,, 1);
/* Mark as free */
__SET_VAR(data__->, STATE,, PYTHON_FB_FREE);
/* mark as not trigged */
if(!poll)
__SET_VAR(data__->, TRIGGED,, 0);
/*printf("__PythonEvalFB pop %d - %*s\n",Current_PLC_EvalFB, data__->BUFFER.len, data__->BUFFER.body);*/
}else if(poll){
/* when in polling, no answer == ack down */
__SET_VAR(data__->, ACK,, 0);
}
/* got the order to act ?*/
if(__GET_VAR(data__->TRIGGED) == 1 &&
/* and not already being processed */
__GET_VAR(data__->STATE) == PYTHON_FB_FREE)
{
/* Enter the block in the fifo
* Don't have to check if fifo cell is free
* as fifo size == FB count, and a FB cannot
* be requested twice */
EvalFBs[Current_PLC_EvalFB] = data__;
/* copy into BUFFER local*/
__SET_VAR(data__->, BUFFER,, __GET_VAR(data__->PREBUFFER));
/* Set ACK pin to low so that we can set a rising edge on result */
if(!poll){
/* when not polling, a new answer imply reseting ack*/
__SET_VAR(data__->, ACK,, 0);
}else{
/* when in polling, acting reset trigger */
__SET_VAR(data__->, TRIGGED,, 0);
}
/* Mark FB busy */
__SET_VAR(data__->, STATE,, PYTHON_FB_REQUESTED);
/* Have to wakeup python thread in case he was asleep */
PythonState |= PYTHON_MUSTWAKEUP;
/*printf("__PythonEvalFB push %d - %*s\n",Current_PLC_EvalFB, data__->BUFFER.len, data__->BUFFER.body);*/
/* Get a new line */
Current_PLC_EvalFB = (Current_PLC_EvalFB + 1) % 1;
}
}
}
char* PythonIterator(char* result, void** id)
{
char* next_command;
PYTHON_EVAL* data__;
//printf("PythonIterator result %s\n", result);
/*emergency exit*/
if(PythonState & PYTHON_FINISHED) return NULL;
/* take python mutex to prevent changing PLC data while PLC running */
LockPython();
/* Get current FB */
data__ = EvalFBs[Current_Python_EvalFB];
if(data__ && /* may be null at first run */
__GET_VAR(data__->STATE) == PYTHON_FB_PROCESSING){ /* some answer awaited*/
/* If result not None */
if(result){
/* Get results len */
__SET_VAR(data__->, BUFFER, .len, strlen(result));
/* prevent results overrun */
if(__GET_VAR(data__->BUFFER, .len) > STR_MAX_LEN)
{
__SET_VAR(data__->, BUFFER, .len, STR_MAX_LEN);
/* TODO : signal error */
}
/* Copy results to buffer */
strncpy((char*)__GET_VAR(data__->BUFFER, .body), result, __GET_VAR(data__->BUFFER,.len));
}else{
__SET_VAR(data__->, BUFFER, .len, 0);
}
/* remove block from fifo*/
EvalFBs[Current_Python_EvalFB] = NULL;
/* Mark block as answered */
__SET_VAR(data__->, STATE,, PYTHON_FB_ANSWERED);
/* Get a new line */
Current_Python_EvalFB = (Current_Python_EvalFB + 1) % 1;
//printf("PythonIterator ++ Current_Python_EvalFB %d\n", Current_Python_EvalFB);
}
/* while next slot is empty */
while(((data__ = EvalFBs[Current_Python_EvalFB]) == NULL) ||
/* or doesn't contain command */
__GET_VAR(data__->STATE) != PYTHON_FB_REQUESTED)
{
UnLockPython();
/* wait next FB to eval */
//printf("PythonIterator wait\n");
if(WaitPythonCommands()) return NULL;
/*emergency exit*/
if(PythonState & PYTHON_FINISHED) return NULL;
LockPython();
}
/* Mark block as processing */
__SET_VAR(data__->, STATE,, PYTHON_FB_PROCESSING);
//printf("PythonIterator\n");
/* make BUFFER a null terminated string */
__SET_VAR(data__->, BUFFER, .body[__GET_VAR(data__->BUFFER, .len)], 0);
/* next command is BUFFER */
next_command = (char*)__GET_VAR(data__->BUFFER, .body);
*id=data__;
/* free python mutex */
UnLockPython();
/* return the next command to eval */
return next_command;
}
/*******************************************/
/* FILE GENERATED BY iec2c */
/* Editing this file is not recommended... */
/*******************************************/
#include "iec_std_lib.h"
// RESOURCE RESOURCE1
extern unsigned long long common_ticktime__;
#include "accessor.h"
#include "POUS.h"
#include "config.h"
#include "POUS.c"
BOOL TASK0;
PLC_PRG RESOURCE1__INSTANCE0;
#define INSTANCE0 RESOURCE1__INSTANCE0
void RESOURCE1_init__(void) {
BOOL retain;
retain = 0;
TASK0 = __BOOL_LITERAL(FALSE);
PLC_PRG_init__(&INSTANCE0,retain);
}
void RESOURCE1_run__(unsigned long tick) {
TASK0 = !(tick % 1);
if (TASK0) {
PLC_PRG_body__(&INSTANCE0);
}
}
import csv
from collections import OrderedDict
csv_int_files = {}
def CSVRdInt(fname, rowidx, colidx):
"""
Return value at row/column pointed by integer indexes
Assumes data starts at first row and first column, no headers.
"""
global csv_int_files
data = csv_int_files.get(fname, None)
if data is None:
data = list()
try:
csvfile = open(fname, 'rb')
except IOError:
return "#FILE_NOT_FOUND"
try:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
for row in reader:
data.append(row)
except csv.Error:
return "#CSV_ERROR"
finally:
csvfile.close()
csv_int_files[fname] = data
try:
row = data[rowidx]
except IndexError:
return "#ROW_NOT_FOUND"
try:
return row[colidx]
except IndexError:
return "#COL_NOT_FOUND"
csv_str_files = {}
def CSVRdStr(fname, rowname, colname):
"""
Return value at row/column pointed by a pair of names as string
Assumes first row is column headers and first column is row name.
"""
global csv_str_files
entry = csv_str_files.get(fname, None)
if entry is None:
data = dict()
try:
csvfile = open(fname, 'rb')
except IOError:
return "#FILE_NOT_FOUND"
try:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
headers = dict([(name, index) for index, name in enumerate(reader.next()[1:])])
for row in reader:
data[row[0]] = row[1:]
except csv.Error:
return "#CSV_ERROR"
finally:
csvfile.close()
csv_str_files[fname] = (headers, data)
else:
headers, data = entry
try:
row = data[rowname]
except KeyError:
return "#ROW_NOT_FOUND"
try:
colidx = headers[colname]
except KeyError:
return "#COL_NOT_FOUND"
try:
return row[colidx]
except IndexError:
return "#COL_NOT_FOUND"
def pyext_csv_reload():
global csv_int_files, csv_str_files
csv_int_files.clear()
csv_str_files.clear()
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