Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
532b5b7211
|
|||
|
25f6a1f43f
|
|||
|
a5f9527f4d
|
@@ -11,7 +11,7 @@ ARG CONF_DIR="${APP_DIR}/config"
|
|||||||
RUN \
|
RUN \
|
||||||
apt update && \
|
apt update && \
|
||||||
pip3 install loguru && \
|
pip3 install loguru && \
|
||||||
pip3 install pymodbus && \
|
pip3 install pymodbus==3.6.3 && \
|
||||||
pip3 install paho-mqtt
|
pip3 install paho-mqtt
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
|
|||||||
@@ -39,17 +39,17 @@ class ModbusHandler(threading.Thread):
|
|||||||
|
|
||||||
self.processImage.init(digitalOutputBits, digitalInputBits, analogInputBits)
|
self.processImage.init(digitalOutputBits, digitalInputBits, analogInputBits)
|
||||||
|
|
||||||
reg = client.read_coils(0, digitalOutputBits)
|
|
||||||
if isinstance(reg, ModbusIOException):
|
|
||||||
raise Exception(reg)
|
|
||||||
with self.processImage:
|
|
||||||
self.processImage.setCoils(reg.bits)
|
|
||||||
|
|
||||||
while not self.killBill:
|
while not self.killBill:
|
||||||
try:
|
try:
|
||||||
if not client.is_socket_open():
|
if not client.is_socket_open():
|
||||||
client.connect()
|
client.connect()
|
||||||
|
|
||||||
|
reg = client.read_coils(0, digitalOutputBits)
|
||||||
|
if isinstance(reg, ModbusIOException):
|
||||||
|
raise Exception(reg)
|
||||||
|
readCoils = reg.bits
|
||||||
|
|
||||||
reg = client.read_input_registers(0, analogInputBits // 8)
|
reg = client.read_input_registers(0, analogInputBits // 8)
|
||||||
if isinstance(reg, ModbusIOException):
|
if isinstance(reg, ModbusIOException):
|
||||||
raise Exception(reg)
|
raise Exception(reg)
|
||||||
@@ -64,6 +64,7 @@ class ModbusHandler(threading.Thread):
|
|||||||
with self.processImage:
|
with self.processImage:
|
||||||
self.processImage.setAnalogsInputs(analogInputs)
|
self.processImage.setAnalogsInputs(analogInputs)
|
||||||
self.processImage.setDiscreteInputs(discreteInputs)
|
self.processImage.setDiscreteInputs(discreteInputs)
|
||||||
|
self.processImage.setCoils(readCoils)
|
||||||
if self.processImage.hasPendingInputChanges():
|
if self.processImage.hasPendingInputChanges():
|
||||||
self.processImage.notify()
|
self.processImage.notify()
|
||||||
if self.processImage.hasPendingOutputChanges():
|
if self.processImage.hasPendingOutputChanges():
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class ProcessImage(Condition):
|
|||||||
self.numCoils = numCoils
|
self.numCoils = numCoils
|
||||||
self.coils = []
|
self.coils = []
|
||||||
self.shadowCoils = [ None ] * numCoils
|
self.shadowCoils = [ None ] * numCoils
|
||||||
|
self.readCoils = [ None ] * numCoils
|
||||||
|
self.readShadowCoils = [ None ] * numCoils
|
||||||
|
|
||||||
self.numDiscreteInputs = numDiscreteInputs
|
self.numDiscreteInputs = numDiscreteInputs
|
||||||
self.discreteInputs = []
|
self.discreteInputs = []
|
||||||
@@ -31,7 +33,7 @@ class ProcessImage(Condition):
|
|||||||
return self.initialized
|
return self.initialized
|
||||||
|
|
||||||
def hasPendingInputChanges(self):
|
def hasPendingInputChanges(self):
|
||||||
return (self.discreteInputs != self.shadowDiscreteInputs) or (self.analogInputs != self.shadowAnalogInputs)
|
return (self.discreteInputs != self.shadowDiscreteInputs) or (self.analogInputs != self.shadowAnalogInputs) or (self.readCoils != self.readShadowCoils)
|
||||||
|
|
||||||
def hasPendingOutputChanges(self):
|
def hasPendingOutputChanges(self):
|
||||||
return self.shadowCoils != self.coils
|
return self.shadowCoils != self.coils
|
||||||
@@ -56,7 +58,9 @@ class ProcessImage(Condition):
|
|||||||
def setCoils(self, coils):
|
def setCoils(self, coils):
|
||||||
if not self.initialized:
|
if not self.initialized:
|
||||||
raise NotInitializedException
|
raise NotInitializedException
|
||||||
self.coils = coils
|
self.readCoils = coils
|
||||||
|
if self.coils == []:
|
||||||
|
self.coils = coils
|
||||||
|
|
||||||
def setCoil(self, coilNum, value):
|
def setCoil(self, coilNum, value):
|
||||||
if not self.initialized:
|
if not self.initialized:
|
||||||
@@ -67,8 +71,8 @@ class ProcessImage(Condition):
|
|||||||
def getChangedCoils(self):
|
def getChangedCoils(self):
|
||||||
if not self.initialized:
|
if not self.initialized:
|
||||||
raise NotInitializedException
|
raise NotInitializedException
|
||||||
changedCoils = zippingFilter(self.coils, self.shadowCoils)
|
changedCoils = zippingFilter(self.coils, self.readCoils)
|
||||||
# self.shadowCoils = self.coils
|
self.readShadowCoils = self.coils
|
||||||
return changedCoils
|
return changedCoils
|
||||||
|
|
||||||
def getCoils(self):
|
def getCoils(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user