diff --git a/Telegram/Telegram.py b/Telegram/Telegram.py index d69d0ca..0dbb809 100644 --- a/Telegram/Telegram.py +++ b/Telegram/Telegram.py @@ -1,7 +1,7 @@ import binascii import datetime -from TelegramData import TelegramData +from Telegram.TelegramData import TelegramData class Telegram: @@ -46,7 +46,7 @@ class Telegram: def berekenCrc(self, telegram): bericht = b''.join(telegram) - crc = binascii.crc_hqx(telegram, 0x0000) + crc = binascii.crc_hqx(bericht, 0x0000) return f'!{crc:04X}\r\n' def maakTelegram(self): @@ -92,4 +92,6 @@ class Telegram: def __str__(self): telegram = self.maakTelegram() - return telegram.append(self.berekenCrc(telegram)) + crc = self.berekenCrc(telegram) + telegram.append(crc) + return telegram \ No newline at end of file diff --git a/Telegram/TelegramUtil.py b/Telegram/TelegramUtil.py new file mode 100644 index 0000000..ec937ce --- /dev/null +++ b/Telegram/TelegramUtil.py @@ -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) diff --git a/Util/ioUtil.py b/Util/ioUtil.py deleted file mode 100644 index 810e731..0000000 --- a/Util/ioUtil.py +++ /dev/null @@ -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) diff --git a/__main__.py b/__main__.py index bb5a1de..42e5b3a 100644 --- a/__main__.py +++ b/__main__.py @@ -1,4 +1,7 @@ -import hello +from Telegram.Telegram import Telegram +from Telegram.TelegramUtil import verzend if __name__ == '__main__': - print(hello.helloWorld()) \ No newline at end of file + telegram = Telegram() + while True: + verzend(telegram.__str__()) \ No newline at end of file diff --git a/hello.py b/hello.py deleted file mode 100644 index cd6c71e..0000000 --- a/hello.py +++ /dev/null @@ -1,2 +0,0 @@ -def helloWorld(): - return 'Hello, juul!' \ No newline at end of file