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

[development] Fix services not starting and introduce more precise exception handling when connecting to runtime and improvements to Docker setup. #159

Merged
merged 6 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
.exe/
**/.vs/
.vscode/
.idea/
cmake-*/
include/
lib/

.deps/
bin/
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ automake libtool make git python3 python3-pip \
sqlite3 cmake git

COPY . /workdir
RUN cd /workdir && ./install.sh docker
WORKDIR /workdir
RUN pip3 install -r requirements.txt
RUN ./install.sh docker
ENTRYPOINT ["./start_openplc.sh"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ docker build -t openplc:v3 .
_Devices can be passed to the `docker` daemon using the `-v` flag (e.g. `-v /dev/ttyACM0:/dev/ttyACM0`)_

```bash
docker run -it --rm --privileged -p 8080:8080 openplc:v3
docker run -it --rm --cap-add=SYS_NICE --cap-add=IPC_LOCK -p 8080:8080 openplc:v3
```

## Running Standalone
Expand Down
4 changes: 1 addition & 3 deletions background_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ elif [ "$1" == "linux" ]; then

elif [ "$1" == "docker" ]; then
echo "Installing OpenPLC on Linux inside Docker"
linux_install_deps
install_py_deps


cmake_build_and_test

if [ $? -ne 0 ]; then
Expand Down
28 changes: 14 additions & 14 deletions webserver/openplc.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ def start_modbus(self, port_num):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 43628))
s.send(b'start_modbusslave(' + str(port_num) + ')\n')
s.send(b'start_modbusslave(' + (b'%d' % port_num) + b')\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def stop_modbus(self):
Expand All @@ -181,18 +181,18 @@ def stop_modbus(self):
s.send(b'stop_modbusslave()\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def start_dnp3(self, port_num):
if (self.status() == "Running"):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 43628))
s.send(b'start_dnp3s(' + str(port_num) + ')\n')
s.send(b'start_dnp3s(' + (b'%d' % port_num) + b')\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def stop_dnp3(self):
Expand All @@ -203,18 +203,18 @@ def stop_dnp3(self):
s.send(b'stop_dnp3s()\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def start_enip(self, port_num):
if (self.status() == "Running"):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 43628))
s.send(b'start_enip(' + str(port_num) + ')\n')
s.send(b'start_enip(' + (b'%d' % port_num) + b')\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def stop_enip(self):
Expand All @@ -225,18 +225,18 @@ def stop_enip(self):
s.send(b'stop_enip()\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def start_pstorage(self, poll_rate):
if (self.status() == "Running"):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 43628))
s.send(b'start_pstorage(' + str(poll_rate) + ')\n')
s.send(b'start_pstorage(' + (b'%d' % poll_rate) + b')\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def stop_pstorage(self):
Expand All @@ -247,7 +247,7 @@ def stop_pstorage(self):
s.send(b'stop_pstorage()\n')
data = s.recv(1000)
s.close()
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

def logs(self):
Expand All @@ -259,7 +259,7 @@ def logs(self):
data = s.recv(1000000)
s.close()
return data
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

return "Error connecting to OpenPLC runtime"
Expand All @@ -275,7 +275,7 @@ def exec_time(self):
data = s.recv(10000)
s.close()
return display_time(int(data), 4)
except:
except ConnectionRefusedError:
print("Error connecting to OpenPLC runtime")

return "Error connecting to OpenPLC runtime"
Expand Down