From f1fbb9afb95d6ee1374825d8baec439c66bf1ccc Mon Sep 17 00:00:00 2001 From: mj Date: Sun, 2 Jan 2022 11:52:04 +0100 Subject: [PATCH] 485 fuzz (random data write) test --- tests/test_485_fuzz.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) mode change 100644 => 100755 tests/test_485_fuzz.py diff --git a/tests/test_485_fuzz.py b/tests/test_485_fuzz.py old mode 100644 new mode 100755 index 687783e..96029a4 --- a/tests/test_485_fuzz.py +++ b/tests/test_485_fuzz.py @@ -8,7 +8,22 @@ # # Return 0 if read was successful, 1 otherwise. # +import time import serial import minimalmodbus +import numpy as np +from sensor import Sensor +serial_file = '/dev/rs485' +address = 247 +baudrate = 19200 +serial_device = serial.Serial(serial_file, baudrate) +# repeatedly write random stuff +print('Sending random data to sensor') +for i in range(0,16): + random_data = np.random.randint(256, size=(1024)).astype('uint8') + bytes_sent = serial_device.write(random_data) + if bytes_sent != len(random_data): + print(f'Warning: failed to write all bytes (sent {bytes_sent}/{len_random_data})') + time.sleep(0.05)