Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_phys(self):
var = od.Variable("Test INTEGER16", 0x1000)
var.data_type = od.INTEGER16
var.factor = 0.1
self.assertAlmostEqual(var.decode_phys(128), 12.8)
self.assertEqual(var.encode_phys(-0.1), -1)
def test_integer16(self):
var = od.Variable("Test INTEGER16", 0x1000)
var.data_type = od.INTEGER16
self.assertEqual(var.decode_raw(b"\xfe\xff"), -2)
self.assertEqual(var.decode_raw(b"\x01\x00"), 1)
self.assertEqual(var.encode_raw(-2), b"\xfe\xff")
self.assertEqual(var.encode_raw(1), b"\x01\x00")
def test_dummy_variable(self):
var = self.od['Dummy0003']
self.assertIsInstance(var, canopen.objectdictionary.Variable)
self.assertEqual(var.index, 0x0003)
self.assertEqual(var.subindex, 0)
self.assertEqual(var.name, 'Dummy0003')
self.assertEqual(var.data_type, canopen.objectdictionary.INTEGER16)
self.assertEqual(var.access_type, 'const')
self.assertEqual(len(var), 16)
try:
import xml.etree.cElementTree as etree
except ImportError:
import xml.etree.ElementTree as etree
import logging
from canopen import objectdictionary
logger = logging.getLogger(__name__)
DATA_TYPES = {
"BOOLEAN": objectdictionary.BOOLEAN,
"INTEGER8": objectdictionary.INTEGER8,
"INTEGER16": objectdictionary.INTEGER16,
"INTEGER32": objectdictionary.INTEGER32,
"UNSIGNED8": objectdictionary.UNSIGNED8,
"UNSIGNED16": objectdictionary.UNSIGNED16,
"UNSIGNED32": objectdictionary.UNSIGNED32,
"REAL32": objectdictionary.REAL32,
"VISIBLE_STRING": objectdictionary.VISIBLE_STRING,
"DOMAIN": objectdictionary.DOMAIN
}
def import_epf(epf):
"""Import an EPF file.
:param epf:
Either a path to an EPF-file, a file-like object, or an instance of
:class:`xml.etree.ElementTree.Element`.