This commit is contained in:
Juul
2025-07-21 13:50:03 +02:00
parent 5286a9de73
commit 073e957c9d
5 changed files with 29 additions and 28 deletions
+5 -3
View File
@@ -1,7 +1,7 @@
import binascii import binascii
import datetime import datetime
from TelegramData import TelegramData from Telegram.TelegramData import TelegramData
class Telegram: class Telegram:
@@ -46,7 +46,7 @@ class Telegram:
def berekenCrc(self, telegram): def berekenCrc(self, telegram):
bericht = b''.join(telegram) bericht = b''.join(telegram)
crc = binascii.crc_hqx(telegram, 0x0000) crc = binascii.crc_hqx(bericht, 0x0000)
return f'!{crc:04X}\r\n' return f'!{crc:04X}\r\n'
def maakTelegram(self): def maakTelegram(self):
@@ -92,4 +92,6 @@ class Telegram:
def __str__(self): def __str__(self):
telegram = self.maakTelegram() telegram = self.maakTelegram()
return telegram.append(self.berekenCrc(telegram)) crc = self.berekenCrc(telegram)
telegram.append(crc)
return telegram
+19
View File
@@ -0,0 +1,19 @@
from time import sleep
import serial
INPUT_PORT = '/dev/ttyUSB0'
OUTPUT_PORT = '/dev/ttyUSB0'
# dataInput = serial.Serial(INPUT_PORT, 115200, timeout=1)
# dataOutput = serial.Serial(OUTPUT_PORT, 115200, timeout=1)
# def lees():
# line = dataInput.readline()
# print(line)
def verzend(telegram):
for line in telegram:
print(line)
# dataOutput.write(line)
sleep(1)
-21
View File
@@ -1,21 +0,0 @@
from time import sleep
import serial
INPUT_PORT = '/dev/ttyUSB0'
OUTPUT_PORT = '/dev/ttyUSB0'
dataInput = serial.Serial(INPUT_PORT, 115200, timeout=1)
dataOutput = serial.Serial(OUTPUT_PORT, 115200, timeout=1)
def lees():
while True:
line = dataInput.readline()
print(line)
def verzend(telegram):
while True:
for line in telegram:
print(line)
dataOutput.write(line)
sleep(1)
+5 -2
View File
@@ -1,4 +1,7 @@
import hello from Telegram.Telegram import Telegram
from Telegram.TelegramUtil import verzend
if __name__ == '__main__': if __name__ == '__main__':
print(hello.helloWorld()) telegram = Telegram()
while True:
verzend(telegram.__str__())
-2
View File
@@ -1,2 +0,0 @@
def helloWorld():
return 'Hello, juul!'