Blame view

src/core/pyros_django/devices/PLC.py 2.17 KB
ddf59dd4   haribo   Remaniement :
1
from common.models import *
605b65e5   Jeremy   Update simulators
2
import abc
6c2793c2   jeremy   Update
3
import json
ddf59dd4   haribo   Remaniement :
4
from .Device import DeviceController
21598bc6   haribo   Date: 01/08/2016
5

e8e6f017   Jeremy   Reworked devices ...
6
7
8
9
'''
    Device controller for PLC.
    This class must implement set, get and do functions (DeviceController is an abstract)
'''
ddf59dd4   haribo   Remaniement :
10
class PLCController(DeviceController):
21598bc6   haribo   Date: 01/08/2016
11
12

    def __init__(self):
bb0fbab1   haribo   Fini de mettre la...
13
        super().__init__("PLC")
e8e6f017   Jeremy   Reworked devices ...
14

6c2793c2   jeremy   Update
15
16
    def sendCommand(self, dict_list):
        command = { "command" : dict_list }
15e15006   Etienne Pallier   Nouvelles modifs ...
17
18
19
        return self.sendMessage(json.dumps(command))
        # EP sert à rien
        #return ""
e8e6f017   Jeremy   Reworked devices ...
20

6c2793c2   jeremy   Update
21
    def sendCommandWithAnswer(self, dict_list):
1a2dc19f   Etienne Pallier   nombreux bugfixes...
22
        # Send commmand TO plc
15e15006   Etienne Pallier   Nouvelles modifs ...
23
        status = self.sendCommand(dict_list)
f47ec727   Quentin Durand   hotfix monitoring
24

15e15006   Etienne Pallier   Nouvelles modifs ...
25
        #EP added
f47ec727   Quentin Durand   hotfix monitoring
26
27
        if not status:
            return "NOT_SET1"
1a2dc19f   Etienne Pallier   nombreux bugfixes...
28
        # Read result FROM plc
f6076245   Patrick Maeght   penelope work part 1
29
        return (self.blockAndReadBytes(8192))
e8e6f017   Jeremy   Reworked devices ...
30

fc957772   Quentin Durand   Control command P...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    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"

6c2793c2   jeremy   Update
53
54
    def getList(self):
        return self.sendCommandWithAnswer([{"name":"LIST"}])
ce470283   Jeremy   Plc simulator fin...
55

fc957772   Quentin Durand   Control command P...
56
57
58
59
60
    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

f47ec727   Quentin Durand   hotfix monitoring
61
62
        s = self.sendCommandWithAnswer([{"name":"STATUS"}])
        return s
6c2793c2   jeremy   Update
63
64
65
66
67
    '''
        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}])