PLC.py
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from common.models import *
import abc
import json
from .Device import DeviceController
'''
Device controller for PLC.
This class must implement set, get and do functions (DeviceController is an abstract)
'''
class PLCController(DeviceController):
def __init__(self):
super().__init__("PLC")
def sendCommand(self, dict_list):
command = { "command" : dict_list }
return self.sendMessage(json.dumps(command))
# EP sert à rien
#return ""
def sendCommandWithAnswer(self, dict_list):
# Send commmand TO plc
status = self.sendCommand(dict_list)
#EP added
if not status:
return "NOT_SET1"
# Read result FROM plc
return (self.blockAndReadBytes(8192))
def switch_lights(self, command) :
command = command.split()
if len(command) > 2:
if command[2] == "ON":
return self.sendCommandWithAnswer([{"name": "SWITCH LINES ON"}])
elif command[2] == "OFF":
return self.sendCommandWithAnswer([{"name": "SWITCH LINES OFF"}])
else:
return "Invalid command"
def manage_shutters(self, command):
command = command.split()
if len(command) == 2:
if command[0] == "CLOSE":
return self.sendCommandWithAnswer([{"name": "CLOSE SHUTTERS"}])
elif command[0] == "OPEN":
return self.sendCommandWithAnswer([{"name": "OPEN SHUTTERS"}])
else:
return "Invalid command"
return "Invalid command"
def getList(self):
return self.sendCommandWithAnswer([{"name":"LIST"}])
def getStatus(self, command=""):
command = command.split()
if (len(command) > 2):
I = 0 #emplacement ou gérer la commande a envoyer pour le statut d'un capteur en particulier
s = self.sendCommandWithAnswer([{"name":"STATUS"}])
return s
'''
Value is a string ("on" or "off"), current is a decimal value ("0.231")
'''
def setLampFlatCagire(self, value, current):
return self.sendCommand([{"name":"LAMP_FLAT_CAGIRE", "value":value, "current":current}])