Johannes Müller 3 роки тому
батько
коміт
06258bdd8b

+ 1 - 1
box-pc/application/inputs/allen_bradley_connect.py

@@ -28,4 +28,4 @@ class AllenBradleyCPU(Input):
     ret = self.comm.Read(F"{self.tag}:I")
     if ret.Status == "Success":
       raw = ret.Value
-      self.queue_ifm_from_bytes(timestamp, raw[self.E_offset:self.E_offset+30])
+      self.queue_ifm_from_bytes("AB", timestamp, raw[self.E_offset:self.E_offset+30])

+ 7 - 7
box-pc/application/inputs/common.py

@@ -42,13 +42,13 @@ class Input:
       if remaining > 0:
         time.sleep(remaining)
 
-  def queue_ifm_from_bytes(self, timestamp, raw, channels = 16):
+  def queue_ifm_from_bytes(self, source, timestamp, raw, channels = 16):
     data = struct.unpack(">" + "B" * 16 + "HHHHHBxH", raw)
     current = tuple([x / 10 for x in data[0:channels]])
-    status = tuple([data[17] & (1 << i) for i in range(channels)])
-    overload = tuple([data[17] & (1 << i) for i in range(channels)])
-    short_circuit = tuple([data[17] & (1 << i) for i in range(channels)])
-    limit = tuple([data[17] & (1 << i) for i in range(channels)])
-    pushbutton = tuple([data[17] & (1 << i) for i in range(channels)])
+    status = tuple([data[16] & (1 << i) > 0 for i in range(channels)])
+    overload = tuple([data[17] & (1 << i) > 0 for i in range(channels)])
+    short_circuit = tuple([data[18] & (1 << i) > 0 for i in range(channels)])
+    limit = tuple([data[19] & (1 << i) > 0 for i in range(channels)])
+    pushbutton = tuple([data[20] & (1 << i) > 0 for i in range(channels)])
     voltage = data[22] / 100
-    self._q.put(Measurement24v(timestamp, "AB", current, status, overload, short_circuit, limit, pushbutton, voltage))
+    self._q.put(Measurement24v(timestamp, source, current, status, overload, short_circuit, limit, pushbutton, voltage))

+ 1 - 1
box-pc/application/inputs/snap7_connect.py

@@ -23,7 +23,7 @@ class SiemensCPU(Input):
     self.cpu = Client()
 
   def start(self):
-    self.cpu.connect("10.0.10.1", 0, 0)
+    self.cpu.connect("192.168.10.6", 0, 0)
     super().start()
 
   def read_handler(self):

+ 5 - 1
box-pc/application/inputs/snap7_server.py

@@ -5,6 +5,8 @@ from datetime import datetime
 
 from inputs.common import Input
 
+localtz = datetime.now().astimezone().tzinfo
+
 class SiemensCPU(Input):
   interval = 0.02
 
@@ -19,7 +21,7 @@ class SiemensCPU(Input):
   def read_handler(self):
     event : snap7.types.SrvEvent
     while event := self.server.pick_event():
-      timestamp = datetime.now()
+      timestamp = datetime.now(localtz)
       text = self.server.event_text(event)
       match = re.match("^(?P<datetime>\d+-\d+-\d+ \d+:\d+:\d+) \[(?P<host>[\w\.:]+)\] (?P<type>[\w ]+), Area : (?P<area>.+), Start : (?P<start>\d+), Size : (?P<size>\d+) --> (?P<response>.+)$", text)
       if not match:
@@ -30,3 +32,5 @@ class SiemensCPU(Input):
         print(text)
         continue
       
+      raw = bytearray(self.DBdata)
+      self.queue_ifm_from_bytes("S7", timestamp, raw[0:30])

+ 4 - 3
box-pc/application/main.py

@@ -1,4 +1,4 @@
-from inputs.snap7_connect import SiemensCPU
+from inputs.snap7_server import SiemensCPU
 from inputs.balluff_html import Balluff
 from inputs.allen_bradley_connect import AllenBradleyCPU
 from database import *
@@ -11,18 +11,19 @@ db1 = InfluxDB()
 db2 = CSVFile()
 
 cpu = SiemensCPU()
+cpu.start()
 
 #print(cpu.synchronize())
 
 balluff = Balluff()
 
 ab = AllenBradleyCPU()
-ab.start()
+#ab.start()
 
 start = 0
 
 while True:
-  values = list(ab.read())
+  values = list(ab.read()) + list(cpu.read())
   dt = time.monotonic() - start
   start = time.monotonic()
   db1.write(values)