Blame view

src/devices/PLC.py 1.04 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
17
18
    def sendCommand(self, dict_list):
        command = { "command" : dict_list }
        self.sendMessage(json.dumps(command))
        return ""
e8e6f017   Jeremy   Reworked devices ...
19

6c2793c2   jeremy   Update
20
    def sendCommandWithAnswer(self, dict_list):
1a2dc19f   Etienne Pallier   nombreux bugfixes...
21
        # Send commmand TO plc
6c2793c2   jeremy   Update
22
        self.sendCommand(dict_list)
1a2dc19f   Etienne Pallier   nombreux bugfixes...
23
        # Read result FROM plc
6c2793c2   jeremy   Update
24
        return (self.blockAndReadBytes(4096))
e8e6f017   Jeremy   Reworked devices ...
25

6c2793c2   jeremy   Update
26
27
    def getList(self):
        return self.sendCommandWithAnswer([{"name":"LIST"}])
ce470283   Jeremy   Plc simulator fin...
28
29

    def getStatus(self):
6c2793c2   jeremy   Update
30
31
32
33
34
35
36
        return self.sendCommandWithAnswer([{"name":"STATUS"}])

    '''
        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}])