Refactor
This commit is contained in:
@@ -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
|
||||
@@ -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)
|
||||
@@ -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
@@ -1,4 +1,7 @@
|
||||
import hello
|
||||
from Telegram.Telegram import Telegram
|
||||
from Telegram.TelegramUtil import verzend
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(hello.helloWorld())
|
||||
telegram = Telegram()
|
||||
while True:
|
||||
verzend(telegram.__str__())
|
||||
Reference in New Issue
Block a user