Skip to content

Commit 89f0a20

Browse files
authored
adding new attribute classes and converters (ni#2151)
1 parent 913a385 commit 89f0a20

File tree

28 files changed

+537
-0
lines changed

28 files changed

+537
-0
lines changed

build/templates/_attributes.py.mako

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ class AttributeViInt32TimeDeltaMilliseconds(Attribute):
3535
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_milliseconds_int32(value))
3636

3737

38+
class AttributeViInt32TimeDeltaMonths(Attribute):
39+
40+
def __get__(self, session, session_type):
41+
return _converters.convert_month_to_timedelta(session._get_attribute_vi_int32(self._attribute_id))
42+
43+
def __set__(self, session, value):
44+
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_months_int32(value))
45+
46+
3847
class AttributeViInt64(Attribute):
3948

4049
def __get__(self, session, session_type):
@@ -80,6 +89,15 @@ class AttributeViStringRepeatedCapability(Attribute):
8089
session._set_attribute_vi_string(self._attribute_id, _converters.convert_repeated_capabilities_without_prefix(value))
8190

8291

92+
class AttributeViStringCommaSeparated(Attribute):
93+
94+
def __get__(self, session, session_type):
95+
return _converters.convert_comma_separated_string_to_list(session._get_attribute_vi_string(self._attribute_id))
96+
97+
def __set__(self, session, value):
98+
session._set_attribute_vi_string(self._attribute_id, _converters.convert_list_to_comma_separated_string(value))
99+
100+
83101
class AttributeViBoolean(Attribute):
84102

85103
def __get__(self, session, session_type):

build/templates/_converters.py.mako

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ def convert_month_to_timedelta(months):
266266
return hightime.timedelta(days=(30.4167 * months))
267267

268268

269+
# Scaling factor to apply on seconds to get months
270+
# would be 1/(60 seconds * 60 minutes * 24 hours * 30.4167 days)
271+
def convert_timedelta_to_months_int32(value):
272+
return _convert_timedelta(value, _visatype.ViInt32, 1.0 / (60 * 60 * 24 * 30.4167))
273+
274+
269275
# This converter is not called from the normal codegen path for function. Instead it is
270276
# call from init and is a special case.
271277
def convert_init_with_options_dictionary(values):
@@ -332,6 +338,18 @@ def convert_comma_separated_string_to_list(comma_separated_string):
332338
return [x.strip() for x in comma_separated_string.split(',')]
333339

334340

341+
def convert_list_to_comma_separated_string(list_of_strings):
342+
'''Convert a list of strings into a comma-separated string.
343+
344+
Args:
345+
list_of_strings (list[str]): List of strings.
346+
347+
Returns:
348+
str: Comma-separated string.
349+
'''
350+
return ','.join(list_of_strings)
351+
352+
335353
def convert_chained_repeated_capability_to_parts(chained_repeated_capability):
336354
'''Convert a chained repeated capabilities string to a list of comma-delimited repeated capabilities string.
337355

generated/nidcpower/nidcpower/_attributes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def __set__(self, session, value):
3131
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_milliseconds_int32(value))
3232

3333

34+
class AttributeViInt32TimeDeltaMonths(Attribute):
35+
36+
def __get__(self, session, session_type):
37+
return _converters.convert_month_to_timedelta(session._get_attribute_vi_int32(self._attribute_id))
38+
39+
def __set__(self, session, value):
40+
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_months_int32(value))
41+
42+
3443
class AttributeViInt64(Attribute):
3544

3645
def __get__(self, session, session_type):
@@ -76,6 +85,15 @@ def __set__(self, session, value):
7685
session._set_attribute_vi_string(self._attribute_id, _converters.convert_repeated_capabilities_without_prefix(value))
7786

7887

88+
class AttributeViStringCommaSeparated(Attribute):
89+
90+
def __get__(self, session, session_type):
91+
return _converters.convert_comma_separated_string_to_list(session._get_attribute_vi_string(self._attribute_id))
92+
93+
def __set__(self, session, value):
94+
session._set_attribute_vi_string(self._attribute_id, _converters.convert_list_to_comma_separated_string(value))
95+
96+
7997
class AttributeViBoolean(Attribute):
8098

8199
def __get__(self, session, session_type):

generated/nidcpower/nidcpower/_converters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ def convert_month_to_timedelta(months):
257257
return hightime.timedelta(days=(30.4167 * months))
258258

259259

260+
# Scaling factor to apply on seconds to get months
261+
# would be 1/(60 seconds * 60 minutes * 24 hours * 30.4167 days)
262+
def convert_timedelta_to_months_int32(value):
263+
return _convert_timedelta(value, _visatype.ViInt32, 1.0 / (60 * 60 * 24 * 30.4167))
264+
265+
260266
# This converter is not called from the normal codegen path for function. Instead it is
261267
# call from init and is a special case.
262268
def convert_init_with_options_dictionary(values):
@@ -323,6 +329,18 @@ def convert_comma_separated_string_to_list(comma_separated_string):
323329
return [x.strip() for x in comma_separated_string.split(',')]
324330

325331

332+
def convert_list_to_comma_separated_string(list_of_strings):
333+
'''Convert a list of strings into a comma-separated string.
334+
335+
Args:
336+
list_of_strings (list[str]): List of strings.
337+
338+
Returns:
339+
str: Comma-separated string.
340+
'''
341+
return ','.join(list_of_strings)
342+
343+
326344
def convert_chained_repeated_capability_to_parts(chained_repeated_capability):
327345
'''Convert a chained repeated capabilities string to a list of comma-delimited repeated capabilities string.
328346

generated/nidigital/nidigital/_attributes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def __set__(self, session, value):
3131
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_milliseconds_int32(value))
3232

3333

34+
class AttributeViInt32TimeDeltaMonths(Attribute):
35+
36+
def __get__(self, session, session_type):
37+
return _converters.convert_month_to_timedelta(session._get_attribute_vi_int32(self._attribute_id))
38+
39+
def __set__(self, session, value):
40+
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_months_int32(value))
41+
42+
3443
class AttributeViInt64(Attribute):
3544

3645
def __get__(self, session, session_type):
@@ -76,6 +85,15 @@ def __set__(self, session, value):
7685
session._set_attribute_vi_string(self._attribute_id, _converters.convert_repeated_capabilities_without_prefix(value))
7786

7887

88+
class AttributeViStringCommaSeparated(Attribute):
89+
90+
def __get__(self, session, session_type):
91+
return _converters.convert_comma_separated_string_to_list(session._get_attribute_vi_string(self._attribute_id))
92+
93+
def __set__(self, session, value):
94+
session._set_attribute_vi_string(self._attribute_id, _converters.convert_list_to_comma_separated_string(value))
95+
96+
7997
class AttributeViBoolean(Attribute):
8098

8199
def __get__(self, session, session_type):

generated/nidigital/nidigital/_converters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ def convert_month_to_timedelta(months):
256256
return hightime.timedelta(days=(30.4167 * months))
257257

258258

259+
# Scaling factor to apply on seconds to get months
260+
# would be 1/(60 seconds * 60 minutes * 24 hours * 30.4167 days)
261+
def convert_timedelta_to_months_int32(value):
262+
return _convert_timedelta(value, _visatype.ViInt32, 1.0 / (60 * 60 * 24 * 30.4167))
263+
264+
259265
# This converter is not called from the normal codegen path for function. Instead it is
260266
# call from init and is a special case.
261267
def convert_init_with_options_dictionary(values):
@@ -322,6 +328,18 @@ def convert_comma_separated_string_to_list(comma_separated_string):
322328
return [x.strip() for x in comma_separated_string.split(',')]
323329

324330

331+
def convert_list_to_comma_separated_string(list_of_strings):
332+
'''Convert a list of strings into a comma-separated string.
333+
334+
Args:
335+
list_of_strings (list[str]): List of strings.
336+
337+
Returns:
338+
str: Comma-separated string.
339+
'''
340+
return ','.join(list_of_strings)
341+
342+
325343
def convert_chained_repeated_capability_to_parts(chained_repeated_capability):
326344
'''Convert a chained repeated capabilities string to a list of comma-delimited repeated capabilities string.
327345

generated/nidmm/nidmm/_attributes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def __set__(self, session, value):
3131
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_milliseconds_int32(value))
3232

3333

34+
class AttributeViInt32TimeDeltaMonths(Attribute):
35+
36+
def __get__(self, session, session_type):
37+
return _converters.convert_month_to_timedelta(session._get_attribute_vi_int32(self._attribute_id))
38+
39+
def __set__(self, session, value):
40+
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_months_int32(value))
41+
42+
3443
class AttributeViInt64(Attribute):
3544

3645
def __get__(self, session, session_type):
@@ -76,6 +85,15 @@ def __set__(self, session, value):
7685
session._set_attribute_vi_string(self._attribute_id, _converters.convert_repeated_capabilities_without_prefix(value))
7786

7887

88+
class AttributeViStringCommaSeparated(Attribute):
89+
90+
def __get__(self, session, session_type):
91+
return _converters.convert_comma_separated_string_to_list(session._get_attribute_vi_string(self._attribute_id))
92+
93+
def __set__(self, session, value):
94+
session._set_attribute_vi_string(self._attribute_id, _converters.convert_list_to_comma_separated_string(value))
95+
96+
7997
class AttributeViBoolean(Attribute):
8098

8199
def __get__(self, session, session_type):

generated/nidmm/nidmm/_converters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ def convert_month_to_timedelta(months):
256256
return hightime.timedelta(days=(30.4167 * months))
257257

258258

259+
# Scaling factor to apply on seconds to get months
260+
# would be 1/(60 seconds * 60 minutes * 24 hours * 30.4167 days)
261+
def convert_timedelta_to_months_int32(value):
262+
return _convert_timedelta(value, _visatype.ViInt32, 1.0 / (60 * 60 * 24 * 30.4167))
263+
264+
259265
# This converter is not called from the normal codegen path for function. Instead it is
260266
# call from init and is a special case.
261267
def convert_init_with_options_dictionary(values):
@@ -322,6 +328,18 @@ def convert_comma_separated_string_to_list(comma_separated_string):
322328
return [x.strip() for x in comma_separated_string.split(',')]
323329

324330

331+
def convert_list_to_comma_separated_string(list_of_strings):
332+
'''Convert a list of strings into a comma-separated string.
333+
334+
Args:
335+
list_of_strings (list[str]): List of strings.
336+
337+
Returns:
338+
str: Comma-separated string.
339+
'''
340+
return ','.join(list_of_strings)
341+
342+
325343
def convert_chained_repeated_capability_to_parts(chained_repeated_capability):
326344
'''Convert a chained repeated capabilities string to a list of comma-delimited repeated capabilities string.
327345

generated/nifake/nifake/_attributes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def __set__(self, session, value):
3131
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_milliseconds_int32(value))
3232

3333

34+
class AttributeViInt32TimeDeltaMonths(Attribute):
35+
36+
def __get__(self, session, session_type):
37+
return _converters.convert_month_to_timedelta(session._get_attribute_vi_int32(self._attribute_id))
38+
39+
def __set__(self, session, value):
40+
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_timedelta_to_months_int32(value))
41+
42+
3443
class AttributeViInt64(Attribute):
3544

3645
def __get__(self, session, session_type):
@@ -76,6 +85,15 @@ def __set__(self, session, value):
7685
session._set_attribute_vi_string(self._attribute_id, _converters.convert_repeated_capabilities_without_prefix(value))
7786

7887

88+
class AttributeViStringCommaSeparated(Attribute):
89+
90+
def __get__(self, session, session_type):
91+
return _converters.convert_comma_separated_string_to_list(session._get_attribute_vi_string(self._attribute_id))
92+
93+
def __set__(self, session, value):
94+
session._set_attribute_vi_string(self._attribute_id, _converters.convert_list_to_comma_separated_string(value))
95+
96+
7997
class AttributeViBoolean(Attribute):
8098

8199
def __get__(self, session, session_type):

generated/nifake/nifake/_converters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ def convert_month_to_timedelta(months):
257257
return hightime.timedelta(days=(30.4167 * months))
258258

259259

260+
# Scaling factor to apply on seconds to get months
261+
# would be 1/(60 seconds * 60 minutes * 24 hours * 30.4167 days)
262+
def convert_timedelta_to_months_int32(value):
263+
return _convert_timedelta(value, _visatype.ViInt32, 1.0 / (60 * 60 * 24 * 30.4167))
264+
265+
260266
# This converter is not called from the normal codegen path for function. Instead it is
261267
# call from init and is a special case.
262268
def convert_init_with_options_dictionary(values):
@@ -323,6 +329,18 @@ def convert_comma_separated_string_to_list(comma_separated_string):
323329
return [x.strip() for x in comma_separated_string.split(',')]
324330

325331

332+
def convert_list_to_comma_separated_string(list_of_strings):
333+
'''Convert a list of strings into a comma-separated string.
334+
335+
Args:
336+
list_of_strings (list[str]): List of strings.
337+
338+
Returns:
339+
str: Comma-separated string.
340+
'''
341+
return ','.join(list_of_strings)
342+
343+
326344
def convert_chained_repeated_capability_to_parts(chained_repeated_capability):
327345
'''Convert a chained repeated capabilities string to a list of comma-delimited repeated capabilities string.
328346

0 commit comments

Comments
 (0)