Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyads/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class PLCTYPE_WSTRING:

ads_type_to_ctype = {
# ADST_VOID
ADST_INT8: PLCTYPE_BYTE,
ADST_INT8: PLCTYPE_SINT,
ADST_UINT8: PLCTYPE_UBYTE,
ADST_INT16: PLCTYPE_INT,
ADST_UINT16: PLCTYPE_UINT,
Expand Down
51 changes: 51 additions & 0 deletions tests/test_connection_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,57 @@ def test_read_write_list_int_array(self):
self.assertEqual(read_values, expected_result)


def test_read_write_list_sint_array(self):
expected_sint_array = [-128, 0, 127]

sint_array_bytes = bytearray(ctypes.sizeof(constants.PLCTYPE_SINT) * len(expected_sint_array))

struct.pack_into(
"<" + "b" * len(expected_sint_array),
sint_array_bytes,
0,
*expected_sint_array,
)


# Add to test plc
self.handler.add_variable(PLCVariable(
name = "sint_test_array",
value = bytes(sint_array_bytes),
ads_type = constants.ADST_INT8,
symbol_type = "SINT"))


# Read variable
with self.plc:
read_values = self.plc.read_list_by_name(["sint_test_array"])

# Expected result
expected_result = {
"sint_test_array": expected_sint_array
}

self.assertEqual(expected_result, read_values)

# Modify the value
expected_sint_array[0] = 121

# Write variable
with self.plc:
self.plc.write_list_by_name({"sint_test_array": expected_sint_array})

# Read variable again
with self.plc:
read_values = self.plc.read_list_by_name(["sint_test_array"])

# Expected result
expected_result = {
"sint_test_array": expected_sint_array
}

self.assertEqual(read_values, expected_result)


def test_read_write_list_real_array(self):
expected_real_array = [123.4, 456.7, 789.1]

Expand Down