|
1 | 1 | import re |
2 | 2 | import unittest |
| 3 | +import struct |
3 | 4 |
|
4 | 5 | from snap7 import util, types |
5 | 6 |
|
|
67 | 68 | 32, 7, 18, 23, 50, 2, 133, 65, # these 8 values build the date and time 12 byte total |
68 | 69 | # data typ together, for details under this link |
69 | 70 | # https://support.industry.siemens.com/cs/document/36479/date_and_time-format-bei-s7-?dti=0&lc=de-DE |
70 | | - 254, 254, 254, 254, 254, 127 # test small int |
| 71 | + 254, 254, 254, 254, 254, 127, # test small int |
| 72 | + 128, # test set byte |
71 | 73 | ]) |
72 | 74 |
|
| 75 | +_new_bytearray = bytearray(100) |
| 76 | +_new_bytearray[41:41 + 1] = struct.pack("B", 128) # byte_index=41, value=128, bytes=1 |
| 77 | +_new_bytearray[42:42 + 1] = struct.pack("B", 255) # byte_index=41, value=255, bytes=1 |
| 78 | + |
73 | 79 |
|
74 | 80 | class TestS7util(unittest.TestCase): |
75 | 81 |
|
| 82 | + def test_get_byte(self): |
| 83 | + test_array = bytearray(_new_bytearray) |
| 84 | + byte_ = util.get_byte(test_array, 41) |
| 85 | + self.assertEqual(byte_, 128) |
| 86 | + byte_ = util.get_byte(test_array, 42) |
| 87 | + self.assertEqual(byte_, 255) |
| 88 | + |
| 89 | + def test_set_byte(self): |
| 90 | + test_array = bytearray(_new_bytearray) |
| 91 | + util.set_byte(test_array, 41, 127) |
| 92 | + byte_ = util.get_byte(test_array, 41) |
| 93 | + self.assertEqual(byte_, 127) |
| 94 | + |
76 | 95 | def test_get_s5time(self): |
77 | 96 | """ |
78 | 97 | S5TIME extraction from bytearray |
|
0 commit comments