예제 #1
0
    def test_CDT_Add_Nested(self):
        # Using strings as teh types
        """Test Adding Nested CDTs"""
        c = pydax.Client("cdtnest")
        c.dax_configure()
        c.dax_connect()

        inlist = [("mem1", pydax.DAX_DINT, 10),("mem2", pydax.DAX_BOOL, 16)]
        inner = c.add_cdt("type1", inlist)
        result = c.get_cdt(inner)
        self.assertEqual(inlist, result)
        outlist = [("cdtmem", inner, 10), ("mem2", pydax.DAX_REAL, 16)]
        print("What the????", inner)
        inner = c.add_cdt("type2", outlist)
        result = c.get_cdt(inner)
        self.assertEqual(outlist, result)
예제 #2
0
    def test_write_array_ints(self):
        """Test writing integers"""
        c = pydax.Client("tagwrite")
        c.dax_configure()
        c.dax_connect()

        c.dax_tag_add("d_bytes", "byte", 32)
        c.dax_tag_add("d_sints", "sint", 32)
        c.dax_tag_add("d_words", "word", 32)
        c.dax_tag_add("d_ints", "int", 32)
        c.dax_tag_add("d_uints", "uint", 32)
        c.dax_tag_add("d_dwords", "dword", 32)
        c.dax_tag_add("d_dints", "dint", 32)
        c.dax_tag_add("d_udints", "udint", 32)
        c.dax_tag_add("d_lwords", "lword", 32)
        c.dax_tag_add("d_lints", "lint", 32)
        c.dax_tag_add("d_ulints", "ulint", 32)
예제 #3
0
    def test_write_array_bools(self):
        """Test writing booleans"""
        c = pydax.Client("tagwrite")
        c.dax_configure()
        c.dax_connect()

        c.dax_tag_add("bool2", "bool", 16) # Array of 16 bools
        c.dax_tag_add("bool3", "bool", 2048) # Big array of bools

        l = [b'0'] *16
        c.write_tag("bool2", [True]) # Just writing the first one
        l[0] = b'1'
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool2"]), b"\n".join(l)+b'\n')
        c.write_tag("bool2", [False, True, False, True]) # Just writing the first one
        l[0] = b'0'
        l[1] = b'1'
        l[2] = b'0'
        l[3] = b'1'
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool2"]), b"\n".join(l)+b'\n')

        l = [b'0'] *16
        c.write_tag("bool2[0]", True) # Just writing the first one
        l[0] = b'1'
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool2"]), b"\n".join(l)+b'\n')

        c.write_tag("bool2[15]", True) # Just writing the last one
        l[15] = b'1'
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool2"]), b"\n".join(l)+b'\n')

        l = [b'0'] *16
        x =  [False] * 16
        c.write_tag("bool2[0]", x) # Just writing the first one with a whole list
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool2"]), b"\n".join(l)+b'\n')

        l = [b'0'] *16
        c.write_tag("bool2[2]", [True, False, True]) # Writing in the middle
        l[2] = b'1'
        l[3] = b'0'
        l[4] = b'1'
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool2"]), b"\n".join(l)+b'\n')

        l = [b'0'] *16
        x =  [False] * 16
        with self.assertRaises(pydax.TooBigError):
            c.write_tag("bool2[2]", x) # This sho  uld fail
예제 #4
0
    def test_write_single_bools(self):
        """Test writing booleans"""
        c = pydax.Client("tagwrite")
        c.dax_configure()
        c.dax_connect()

        c.dax_tag_add("bool1", "bool")  # Single bool without the 'count' argument

        c.write_tag("bool1", True)
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool1"]), b'1\n')
        c.write_tag("bool1", False)
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool1"]), b'0\n')
        c.write_tag("bool1", 1)
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool1"]), b'1\n')
        c.write_tag("bool1", 0)
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool1"]), b'0\n')
        c.write_tag("bool1", "1") # Strings are considered True
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool1"]), b'1\n')
        c.write_tag("bool1", "0") # Strings are considered True
        self.assertEqual(subprocess.check_output(["daxc", "-x", "read bool1"]), b'1\n')
예제 #5
0
    def test_CDT_Add_Basic(self):
        """Test Adding Basic CDT"""
        c = pydax.Client("cdtadd")
        c.dax_configure()
        c.dax_connect()

        # Using integers as the types
        tlist = [("mem1", pydax.DAX_INT, 1),("mem2", pydax.DAX_BOOL, 10)]
        t = c.add_cdt("type1", tlist)
        # read as the integer type
        result = c.get_cdt(t)
        self.assertEqual(tlist, result)
        # read as the string type
        result = c.get_cdt("type1")
        self.assertEqual(tlist, result)

        # Using strings as the types
        tlist = [("mem1", "DINT", 10),("mem2", "BOOL", 16)]
        rlist = [("mem1", pydax.DAX_DINT, 10),("mem2", pydax.DAX_BOOL, 16)]
        t = c.add_cdt("type2", tlist)
        result = c.get_cdt(t)
        self.assertEqual(rlist, result)
        result = c.get_cdt("type2")
        self.assertEqual(rlist, result)
예제 #6
0
import pydax
import time

c = pydax.Client("Dummy")
c.dax_configure()
c.dax_connect()

#t = c.add_cdt("dopey", [("mem1", pydax.DAX_INT, 1),("mem2", pydax.DAX_BOOL, 10)])
#t = c.add_cdt("dingy", [("ddd", t, 1), ("mem3", pydax.DAX_BOOL, 16)])
#t = c.dax_tag_add("dummy3", t, 10)
#t = c.dax_tag_add("dummy1", "dopey", 1)
t = c.dax_tag_add("dummy", "uint", 1, 0)
c.write_tag("dummy", 65536, clip=True)
print(c.dummy.value)
# c.dummy.value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# print(c.dummy.value)
# c.dummy[3].value = 445
# print(c.dummy[3].value)

#x = c.read_tag("dummy[0].mem1")
#print(type(x))
#print(x)
#c.dummy3[0].ddd.mem1.value = 23
#print(c.dummy3[9].ddd.mem1.value)
#for each in c.dummy3:
#    print(each.ddd.mem1.path)
# c.dummy3.value  = 34
# c.dummy[3].value  = 48
예제 #7
0
 def test_MinimalSuccess(self):
     """Minimal Process start/stop test"""
     c = pydax.Client("Dummy")
     c.dax_configure()
     c.dax_connect()
예제 #8
0
    def test_write_single_ints(self):
        """Test writing integers"""
        c = pydax.Client("tagwrite")
        c.dax_configure()
        c.dax_connect()

        c.dax_tag_add("d_byte", "byte")
        c.dax_tag_add("d_sint", "sint")
        c.dax_tag_add("d_word", "word")
        c.dax_tag_add("d_int", "int")
        c.dax_tag_add("d_uint", "uint")
        c.dax_tag_add("d_dword", "dword")
        c.dax_tag_add("d_dint", "dint")
        c.dax_tag_add("d_udint", "udint")
        c.dax_tag_add("d_lword", "lword")
        c.dax_tag_add("d_lint", "lint")
        c.dax_tag_add("d_ulint", "ulint")

        should_work = [
                        ("d_byte", 1, b"1\n"),
                        ("d_byte", 0, b"0\n"),
                        ("d_byte", 127, b"127\n"),
                        ("d_byte", 128, b"128\n"),
                        ("d_byte", 255, b"255\n"),
                        ("d_sint", 1, b"1\n"),
                        ("d_sint", -1, b"-1\n"),
                        ("d_sint", 0, b"0\n"),
                        ("d_sint", 127, b"127\n"),
                        ("d_sint", -128, b"-128\n"),
                        ("d_word", 1, b"1\n"),
                        ("d_word", 0, b"0\n"),
                        ("d_word", 32767, b"32767\n"),
                        ("d_word", 65535, b"65535\n"),
                        ("d_uint", 1, b"1\n"),
                        ("d_uint", 0, b"0\n"),
                        ("d_uint", 32767, b"32767\n"),
                        ("d_uint", 65535, b"65535\n"),
                        ("d_int", 1, b"1\n"),
                        ("d_int", -1, b"-1\n"),
                        ("d_int", 0, b"0\n"),
                        ("d_int", 32767, b"32767\n"),
                        ("d_int", -32768, b"-32768\n"),
                        ("d_dword", 1, b"1\n"),
                        ("d_dword", 0, b"0\n"),
                        ("d_dword", 2147483647, b"2147483647\n"),
                        ("d_dword", 4294967295, b"4294967295\n"),
                        ("d_udint", 1, b"1\n"),
                        ("d_udint", 0, b"0\n"),
                        ("d_udint", 2147483647, b"2147483647\n"),
                        ("d_udint", 4294967295, b"4294967295\n"),
                        ("d_dint", -1, b"-1\n"),
                        ("d_dint", 1, b"1\n"),
                        ("d_dint", 0, b"0\n"),
                        ("d_dint", 2147483647, b"2147483647\n"),
                        ("d_dint", -2147483648, b"-2147483648\n"),
                        ("d_lword", 1, b"1\n"),
                        ("d_lword", 0, b"0\n"),
                        ("d_lword", 9223372036854775807, b"9223372036854775807\n"),
                        ("d_lword", 18446744073709551615, b"18446744073709551615\n"),
                        ("d_ulint", 1, b"1\n"),
                        ("d_ulint", 0, b"0\n"),
                        ("d_ulint", 9223372036854775807, b"9223372036854775807\n"),
                        ("d_ulint", 18446744073709551615, b"18446744073709551615\n"),
                        ("d_lint", 1, b"1\n"),
                        ("d_lint", -1, b"-1\n"),
                        ("d_lint", 0, b"0\n"),
                        ("d_lint", 9223372036854775807, b"9223372036854775807\n"),
                        ("d_lint", -9223372036854775808, b"-9223372036854775808\n"),
        ]
        for each in should_work:
            c.write_tag(each[0], each[1])
            self.assertEqual(subprocess.check_output(["daxc", "-x", "read {}".format(each[0])]), each[2])

        should_overflow = [
                        ("d_byte", -1, b"0\n"),
                        ("d_byte", 256, b"255\n"),
                        ("d_sint", 128, b"127\n"),
                        ("d_sint", -129, b"-128\n"),
                        ("d_word", -1, b"0\n"),
                        ("d_word", 65536, b"65535\n"),
                        ("d_uint", -1, b"0\n"),
                        ("d_uint", 65536, b"65535\n"),
                        ("d_int", 32768, b"32767\n"),
                        ("d_int", -32769, b"-32768\n"),
                        ("d_dword", -1, b"0\n"),
                        ("d_dword", 4294967296, b"4294967295\n"),
                        ("d_udint", -1, b"0\n"),
                        ("d_udint", 4294967296, b"4294967295\n"),
                        ("d_dint", 2147483648, b"2147483647\n"),
                        ("d_dint", -2147483649, b"-2147483648\n"),
                        ("d_lword", -1, b"0\n"),
                        ("d_lword", 18446744073709551616, b"18446744073709551615\n"),
                        ("d_ulint", -1, b"0\n"),
                        ("d_ulint", 18446744073709551616, b"18446744073709551615\n"),
                        ("d_lint", 9223372036854775808, b"9223372036854775807\n"),
                        ("d_lint", -9223372036854775809, b"-9223372036854775808\n"),
        ]

        for each in should_overflow:
            c.write_tag(each[0], each[1], clip=True)
            self.assertEqual(subprocess.check_output(["daxc", "-x", "read {}".format(each[0])]), each[2])
            with self.assertRaises(OverflowError):
                c.write_tag(each[0], each[1])