Skip to content

Commit 38451dc

Browse files
committed
add hex string data type
untested
1 parent 076f3fc commit 38451dc

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

classes/protocol_settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Data_Type(Enum):
3030

3131
ASCII = 84
3232
''' 2 characters '''
33+
HEX = 85
34+
''' HEXADECIMAL STRING '''
3335

3436
_1BIT = 201
3537
_2BIT = 202
@@ -516,7 +518,7 @@ def process_row(row):
516518
value_max = strtoint(val_match.group('end'))
517519
matched = True
518520

519-
if data_type == Data_Type.ASCII:
521+
if data_type == Data_Type.ASCII: #might need to apply too hex values as well? or min-max works for hex?
520522
#value_regex
521523
val_match = ascii_value_regex.search(row['values'])
522524
if val_match:
@@ -885,6 +887,8 @@ def process_register_bytes(self, registry : dict[int,bytes], entry : registry_ma
885887
bit_mask = (1 << bit_size) - 1 # Create a mask for extracting X bits
886888
bit_index = entry.register_bit
887889
value = (register >> bit_index) & bit_mask
890+
elif entry.data_type == Data_Type.HEX:
891+
value = register.hex() #convert bytes to hex
888892
elif entry.data_type == Data_Type.ASCII:
889893
try:
890894
value = register.decode("utf-8") #convert bytes to ascii
@@ -999,6 +1003,9 @@ def process_register_ushort(self, registry : dict[int, int], entry : registry_ma
9991003
bit_mask = (1 << bit_size) - 1 # Create a mask for extracting X bits
10001004
bit_index = entry.register_bit
10011005
value = (registry[entry.register] >> bit_index) & bit_mask
1006+
elif entry.data_type == Data_Type.HEX:
1007+
value = registry[entry.register].to_bytes((16 + 7) // 8, byteorder=self.byteorder) #convert to ushort to bytes
1008+
value = value.hex() #convert bytes to hex
10021009
elif entry.data_type == Data_Type.ASCII:
10031010
value = registry[entry.register].to_bytes((16 + 7) // 8, byteorder=self.byteorder) #convert to ushort to bytes
10041011
try:

0 commit comments

Comments
 (0)