2024-10-09 17:08:43 +11:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import unittest
|
|
|
|
|
2024-10-14 19:59:54 +11:00
|
|
|
from pyfroniusreg import froniusreg
|
2024-10-09 17:08:43 +11:00
|
|
|
|
2024-10-14 20:19:38 +11:00
|
|
|
|
2024-10-14 17:02:50 +11:00
|
|
|
class TestDataTypes(unittest.TestCase):
|
2024-10-09 17:08:43 +11:00
|
|
|
def test_int16(self):
|
2024-10-11 08:47:23 +11:00
|
|
|
int16_buffer = froniusreg.int16.encode_to_buffer(1024)
|
2024-10-14 17:02:50 +11:00
|
|
|
assert int16_buffer == [b"\x04\x00"]
|
2024-10-09 17:08:43 +11:00
|
|
|
|
2024-10-16 19:54:24 +11:00
|
|
|
def test_int16_decode(self):
|
|
|
|
int16_register = [0x0, 0x1, 0x0, 0x0, 0x0, 0x5, 0x1, 0x3, 0x2, 0x0, 0x0]
|
|
|
|
output = froniusreg.int16.decode_from_register(int16_register)
|
|
|
|
assert output == 0
|
2024-10-09 17:08:43 +11:00
|
|
|
|
2024-10-16 20:48:59 +11:00
|
|
|
def test_string16(self):
|
|
|
|
string_buffer = froniusreg.string16.encode_to_buffer("Fronius")
|
|
|
|
assert string_buffer == [b"Fr", b"on", b"iu", b"s\x00"]
|
|
|
|
|
|
|
|
def test_string_16_decode(self):
|
|
|
|
int_register = [18034, 28526, 26997, 29440, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
|
|
output = froniusreg.string16.decode_from_register(int_register)
|
|
|
|
expectation = "Fronius" + 9 * '\x00'
|
|
|
|
assert output == expectation
|
|
|
|
|
2024-10-14 17:02:50 +11:00
|
|
|
if __name__ == "__main__":
|
2024-10-09 17:08:43 +11:00
|
|
|
unittest.main()
|