def update(node, new): if isinstance(new, (float, )): new = MDSplus.Float32(new) elif isinstance(new, (int, )): new = MDSplus.Uint16(new) else: return rec = node.getRecord(None) if rec is None: rec = MDSplus.Array([new, new]) elif len(rec) != 1: return else: rec = MDSplus.Array([rec[0], new]) node.write_once = node.no_write_shot = False try: node.record = rec finally: node.write_once = node.no_write_shot = True
def tdiPythonInterface(self): self._doTdiTest("Py('a=None')", 1) self._doTdiTest("Py('a=None','a')", None) self._doTdiTest("Py('a=123','a')", 123) self._doTdiTest("Py('import MDSplus;a=MDSplus.Uint8(-1)','a')", m.Uint8(255)) self._doTdiTest( 'addfun("test","import __main__\n_file_=__main__.__file__\nstatic=[0]\ndef test():\n static[0]+=1\n return [1 if __main__.__file__==_file_ else 0]+static")', "TEST") if not self.inThread: self._doTdiTest("TEST()", m.Array([1, 1])) self._doTdiTest("pyfun('Uint8','MDSplus',-1)", m.Uint8(255)) self._doTdiTest("pyfun('Uint8',*,-1)", m.Uint8(255)) self._doTdiTest("pyfun('str',*,123)", m.String("123")) if not self.inThread: self._doTdiTest("TEST()", m.Array([1, 2]))
def doTest(suffix, cl, scl, ucl, **kw): """ test array and signal """ def results(cl, scl, ucl): from numpy import array return [ cl([13, 8, 7]), cl([7, 0, -3]), cl([30, 16, 10]), cl([10. / 3, 1, .4]), cl([1000, 256, 32]), # +,-,*,/,** ucl([11, 4, 7]), ucl([2, 4, 0]), # |,& array([False, True, False]), # == array([True, False, True]), # != cl([80, 64, 64]), cl([1, 0, 0]), scl([-10, -4, -2]), scl([10, 4, 2]), scl([10, 4, 2]), scl([100, 16, 4]), # <<,>>,-,abs cl([22026.4658, 54.5981500, 7.38905610]), # exp cl([2.30258509, 1.38629436, 0.69314718]), # log cl([-0.54402111, -0.7568025, 0.90929743]), # sin cl([-0.83907153, -0.65364362, -0.41614684]), # cos cl([0.64836083, 1.15782128, -2.18503986]), # tan cl([1.57079633, 0.41151685, 0.20135792]), # asin cl([0., 1.15927948, 1.36943841]), # acos cl([1.47112767, 1.32581766, 1.10714872]), # atan cl([1.47112767, 1.32581766, 1.10714872]), # atan2 cl([3.32192809, 2., 1.]), # log2 cl([1., 0.60205999, 0.30103]), # log10 cl([0.17364818, 0.06975647, 0.0348995]), # sind cl([0.98480775, 0.99756405, 0.99939083]), # cosd cl([0.17632698, 0.06992681, 0.03492077]), # tand cl([3, 1, 1]), # anint cl([1, 0, 2]), # % array([True, False, False]), # > array([True, True, False]), # >= array([False, False, True]), # < array([False, True, True]), # <= ] """ test array """ m.Data.execute('_a=[10%s,4%s,2%s],_b=[3%s,4%s,5%s]' % tuple([suffix] * 6)) a, b = cl([10, 4, 2]), cl([3, 4, 5]) self._doThreeTestArray('_a', m.Array(a), m.Data(a)) self._executeTests(self._doThreeTestArray, a, b, results(cl, scl, ucl), **kw) """ test signal """ Scl = lambda v: m.Signal(cl(v)) Sscl = lambda v: m.Signal(scl(v)) Sucl = lambda v: m.Signal(ucl(v)) m.Data.execute('_a=Make_Signal(_a,*)') a = m.Signal(a) self._executeTests(self._doThreeTestArray, a, b, results(Scl, Sscl, Sucl), **kw)