Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OPC UA server support #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# vim temporary files
*~
*.swp

# Compilation files
*.ii
*.s
*.o
*.so

# Python intermediate files
*.pyc

# Generated scripts and binaries
start_openplc.sh
webserver/iec2c
webserver/st_optimizer
160 changes: 158 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ if [ $# -eq 0 ]; then
echo "Error: You must provide a platform name as argument"
echo ""
echo "Usage: ./install.sh [platform] where [platform] can be"
echo " debug Install OpenPLC on Debian-based Linux distribution for debug"
echo " win Install OpenPLC on Windows over Cygwin"
echo " linux Install OpenPLC on a Debian-based Linux distribution"
echo " rpi Install OpenPLC on a Raspberry Pi"
Expand All @@ -17,7 +18,136 @@ if [ $# -eq 0 ]; then
exit 1
fi

if [ "$1" == "win" ]; then
if [ "$1" == "debug" ]; then
echo "Installing OpenPLC on Linux"
sudo apt-get update
sudo apt-get install build-essential pkg-config bison flex autoconf automake libtool make git python2.7 python-pip sqlite3 cmake
pip install flask
pip install flask-login
pip install pyserial
#make sure that packages are also installed for the super user
sudo -H pip install flask
sudo -H pip install flask-login
sudo -H pip install pyserial

echo ""
echo "[MATIEC COMPILER]"
cd utils/matiec_src
autoreconf -i
./configure
make
cp ./iec2c ../../webserver/
if [ $? -ne 0 ]; then
echo "Error compiling MatIEC"
echo "OpenPLC was NOT installed!"
exit 1
fi
cd ../..

echo ""
echo "[ST OPTIMIZER]"
cd utils/st_optimizer_src
g++ st_optimizer.cpp -o st_optimizer
cp ./st_optimizer ../../webserver/
if [ $? -ne 0 ]; then
echo "Error compiling ST Optimizer"
echo "OpenPLC was NOT installed!"
exit 1
fi
cd ../..

echo ""
echo "[GLUE GENERATOR]"
cd utils/glue_generator_src
g++ glue_generator.cpp -o glue_generator
cp ./glue_generator ../../webserver/core
if [ $? -ne 0 ]; then
echo "Error compiling Glue Generator"
echo "OpenPLC was NOT installed!"
exit 1
fi
cd ../..

echo ""
echo "[OPEN DNP3]"
cd utils/dnp3_src
echo "creating swapfile..."
sudo dd if=/dev/zero of=swapfile bs=1M count=1000
sudo mkswap swapfile
sudo swapon swapfile
cmake ../dnp3_src
make
sudo make install
if [ $? -ne 0 ]; then
echo "Error installing OpenDNP3"
echo "OpenPLC was NOT installed!"
exit 1
fi
sudo ldconfig
echo "removing swapfile..."
sudo swapoff swapfile
sudo rm -f ./swapfile
cd ../..

echo ""
echo "[LIBMODBUS]"
cd utils/libmodbus_src
./autogen.sh
./configure
sudo make install
if [ $? -ne 0 ]; then
echo "Error installing Libmodbus"
echo "OpenPLC was NOT installed!"
exit 1
fi
sudo ldconfig
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[sysv_ipc]"
sudo pip install sysv_ipc

echo ""
echo "[jsoncpp]"
sudo apt install libjsoncpp-dev

echo ""
echo "[OPENPLC SERVICE]"
WORKING_DIR=$(pwd)
echo -e "[Unit]\n\
Description=OpenPLC Service\n\
After=network.target\n\
\n\
[Service]\n\
Type=simple\n\
Restart=always\n\
RestartSec=1\n\
User=root\n\
Group=root\n\
WorkingDirectory=$WORKING_DIR\n\
ExecStart=$WORKING_DIR/start_openplc.sh\n\
\n\
[Install]\n\
WantedBy=multi-user.target" >> openplc.service
sudo cp -rf ./openplc.service /lib/systemd/system/
rm -rf openplc.service
echo "Enabling OpenPLC Service..."
sudo systemctl daemon-reload
sudo systemctl enable openplc

echo ""
echo "[FINALIZING]"
cd webserver/scripts
./change_hardware_layer.sh debug_linux
./compile_program.sh blank_program.st
cp ./start_openplc.sh ../../

elif [ "$1" == "win" ]; then
echo "Installing OpenPLC on Windows"
cp ./utils/apt-cyg/apt-cyg ./
cp ./utils/apt-cyg/wget.exe /bin
Expand Down Expand Up @@ -80,7 +210,12 @@ if [ "$1" == "win" ]; then
exit 1
fi
cd ../..


echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
cd utils/libmodbus_src
Expand Down Expand Up @@ -187,6 +322,11 @@ elif [ "$1" == "linux" ]; then
fi
sudo ldconfig
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[OPENPLC SERVICE]"
Expand Down Expand Up @@ -291,6 +431,11 @@ elif [ "$1" == "rpi" ]; then
sudo swapoff swapfile
sudo rm -f ./swapfile
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
Expand Down Expand Up @@ -409,6 +554,11 @@ elif [ "$1" == "neuron" ]; then
sudo swapoff swapfile
sudo rm -f ./swapfile
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
Expand Down Expand Up @@ -527,6 +677,11 @@ elif [ "$1" == "custom" ]; then
sudo swapoff swapfile
sudo rm -f ./swapfile
cd ../..

echo ""
echo "[OPC UA]"
sudo apt-get install -y python-pip python-dev
pip install opcua

echo ""
echo "[LIBMODBUS]"
Expand Down Expand Up @@ -555,6 +710,7 @@ else
echo "Error: unrecognized platform"
echo ""
echo "Usage: ./install.sh [platform] where [platform] can be"
echo " debug Install OpenPLC on Debian-based Linux distribution for debug"
echo " win Install OpenPLC on Windows over Cygwin"
echo " linux Install OpenPLC on a Debian-based Linux distribution"
echo " rpi Install OpenPLC on a Raspberry Pi"
Expand Down
19 changes: 19 additions & 0 deletions webserver/core/glueVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ IEC_UINT *int_memory[BUFFER_SIZE];
IEC_DINT *dint_memory[BUFFER_SIZE];
IEC_LINT *lint_memory[BUFFER_SIZE];

//Special Functions
IEC_LINT *special_functions[BUFFER_SIZE];


#define __LOCATED_VAR(type, name, ...) type __##name;
#include "LOCATED_VARIABLES.h"
Expand All @@ -58,6 +61,22 @@ IEC_LINT *lint_memory[BUFFER_SIZE];

void glueVars()
{
bool_input[0][0] = __IX0_0;
bool_input[0][1] = __IX0_1;
bool_input[0][2] = __IX0_2;
bool_input[0][3] = __IX0_3;
bool_input[0][4] = __IX0_4;
bool_input[0][5] = __IX0_5;
bool_input[0][6] = __IX0_6;
bool_input[0][7] = __IX0_7;
bool_input[1][0] = __IX1_0;
bool_input[1][1] = __IX1_1;
bool_input[1][2] = __IX1_2;
bool_input[1][3] = __IX1_3;
bool_output[0][0] = __QX0_0;
bool_output[0][1] = __QX0_1;
bool_output[0][2] = __QX0_2;
bool_output[0][3] = __QX0_3;
}

void updateTime()
Expand Down