Basic VFD and E300 devices. Can RW, but not control.
This commit is contained in:
38
common.py
Normal file
38
common.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Hold common functions for CIP messaging."""
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def reverse_parameter_name(lower_underscore):
|
||||
"""Reverse the parameter lookup process."""
|
||||
lower_split = lower_underscore.split("_")
|
||||
upper_split = [x[0].upper() + x[1:] for x in lower_split]
|
||||
return " ".join(upper_split)
|
||||
|
||||
|
||||
def bitfield(n):
|
||||
"""Distribute integer into bits."""
|
||||
binary_with_padding = "0"*32 + bin(int(n))[2:]
|
||||
binary = binary_with_padding[-32:]
|
||||
bin_array = [1 if digit == '1' else 0 for digit in binary]
|
||||
bin_array.reverse()
|
||||
return bin_array
|
||||
|
||||
|
||||
class CIP_value(object):
|
||||
"""Value of vfd parameter."""
|
||||
|
||||
def __init__(self, name, units):
|
||||
"""Initialize VFD Parameter."""
|
||||
self.name = name
|
||||
self.value = None
|
||||
self.timestamp = 0
|
||||
self.units = units
|
||||
|
||||
def update(self, value):
|
||||
"""Update the current value."""
|
||||
self.value = value
|
||||
self.timestamp = datetime.now()
|
||||
|
||||
def __str__(self):
|
||||
"""Represent as a string."""
|
||||
return "name: {}, value: {} {}, timestamp: {}".format(self.name, self.value, self.units, self.timestamp)
|
||||
Reference in New Issue
Block a user