# HG changeset patch
# User Andrey Skvortsov <andrej.skvortzov@gmail.com>
# Date 1481127856 -10800
# Node ID f5868f866d2b0a494cdcff1f6f4fdc1a739ea77b
# Parent  b3cc68dd037dd41a42a4de408e3cc34d51c1fe9f
stop PLC before unloading


This fixes segmentation fault if service was quit without stopping it.
It has happened if Beremiz service was quit using taskbar icon or by
closing Beremiz IDE (in case of autostarted local service).

In second case to trigger the bug following step has to be done:
1. Open Beremiz IDE
2. Open project, compile and connect to LOCAL:// runtime
3. Transfer and start the PLC program
4. Open other project without disconneting the PLC runtime
5. Close Beremiz IDE

diff -r b3cc68dd037d -r f5868f866d2b Beremiz_service.py
--- a/Beremiz_service.py	Wed Dec 07 18:32:34 2016 +0300
+++ b/Beremiz_service.py	Wed Dec 07 19:24:16 2016 +0300
@@ -411,6 +411,7 @@
     def Quit(self):
         self.continueloop = False
         if self.plcobj is not None:
+            self.plcobj.StopPLC()
             self.plcobj.UnLoadPLC()
         self.Stop()