29 "USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", |
29 "USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", |
30 "BYTE" : "U8", "WORD" : "U16", "DWORD" : "U32", "LWORD" : "U64"} |
30 "BYTE" : "U8", "WORD" : "U16", "DWORD" : "U32", "LWORD" : "U64"} |
31 |
31 |
32 VARCLASSCONVERSION = {"T": LOCATION_VAR_INPUT, "R": LOCATION_VAR_OUTPUT, "RT": LOCATION_VAR_MEMORY} |
32 VARCLASSCONVERSION = {"T": LOCATION_VAR_INPUT, "R": LOCATION_VAR_OUTPUT, "RT": LOCATION_VAR_MEMORY} |
33 |
33 |
|
34 |
34 def ExtractHexDecValue(value): |
35 def ExtractHexDecValue(value): |
35 try: |
36 try: |
36 return int(value) |
37 return int(value) |
37 except Exception: |
38 except Exception: |
38 pass |
39 pass |
39 try: |
40 try: |
40 return int(value.replace("#", "0"), 16) |
41 return int(value.replace("#", "0"), 16) |
41 except Exception: |
42 except Exception: |
42 raise ValueError, "Invalid value for HexDecValue \"%s\"" % value |
43 raise ValueError, "Invalid value for HexDecValue \"%s\"" % value |
43 |
44 |
|
45 |
44 def GenerateHexDecValue(value, base=10): |
46 def GenerateHexDecValue(value, base=10): |
45 if base == 10: |
47 if base == 10: |
46 return str(value) |
48 return str(value) |
47 elif base == 16: |
49 elif base == 16: |
48 return "#x%.8x" % value |
50 return "#x%.8x" % value |
49 else: |
51 else: |
50 raise ValueError, "Not supported base" |
52 raise ValueError, "Not supported base" |
|
53 |
51 |
54 |
52 def ExtractName(names, default=None): |
55 def ExtractName(names, default=None): |
53 if len(names) == 1: |
56 if len(names) == 1: |
54 return names[0].getcontent() |
57 return names[0].getcontent() |
55 else: |
58 else: |