PLC.py 1.04 KB
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 }
        self.sendMessage(json.dumps(command))
        return ""

    def sendCommandWithAnswer(self, dict_list):
        # Send commmand TO plc
        self.sendCommand(dict_list)
        # Read result FROM plc
        return (self.blockAndReadBytes(4096))

    def getList(self):
        return self.sendCommandWithAnswer([{"name":"LIST"}])

    def getStatus(self):
        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}])