Replace datatypes dictionary with enum.
This commit is contained in:
@@ -1,41 +1,44 @@
|
||||
"""
|
||||
Definitions for IEC 61131 programming paradigms.
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
@dataclass
|
||||
class DataType:
|
||||
"""Class for IEC 61131-3 data types."""
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
# tagname: str,
|
||||
length_bits: int,
|
||||
word_length = 16,
|
||||
):
|
||||
self.name = name
|
||||
# self.tagname = tagname
|
||||
self.length_bits = length_bits
|
||||
self.length_bytes = length_bits // 8
|
||||
self.length_words = length_bits // word_length
|
||||
|
||||
datatypes = {
|
||||
'bool': DataType('bool', 1),
|
||||
'byte': DataType('byte', 8),
|
||||
'char': DataType('char', 8),
|
||||
'int': DataType('int', 16),
|
||||
'uint': DataType('uint', 16),
|
||||
'word': DataType('word', 16),
|
||||
'date': DataType('date', 32),
|
||||
'dt': DataType('dt', 32),
|
||||
'dint': DataType('dint', 32),
|
||||
'real': DataType('real', 32),
|
||||
'time': DataType('time', 32),
|
||||
'udint': DataType('udint', 32),
|
||||
}
|
||||
class DataTypes(DataType, Enum):
|
||||
BOOL = 1
|
||||
BYTE = 8
|
||||
CHAR = 8
|
||||
INT = 16
|
||||
UINT = 16
|
||||
WORD = 16
|
||||
DATE = 32
|
||||
DT = 32
|
||||
DINT = 32
|
||||
DWORD = 32
|
||||
REAL = 32
|
||||
TIME = 32
|
||||
UDINT = 32
|
||||
|
||||
class ElementaryVariable:
|
||||
""""""
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
type: str,
|
||||
type: DataTypes,
|
||||
address: str,
|
||||
comment: str,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user