コード例 #1
0
 def test_oned_as(self):
     x = np.ones(10)
     self.sci.push('x', x)
     assert self.sci.pull('x').shape == x[:, np.newaxis].T.shape
     sci = Scilab2Py(oned_as='column')
     sci.push('x', x)
     assert sci.pull('x').shape == x[:, np.newaxis].shape
     sci.exit()
コード例 #2
0
    def test_logging(self):
        # create a stringio and a handler to log to it
        def get_handler():
            sobj = StringIO()
            hdlr = logging.StreamHandler(sobj)
            hdlr.setLevel(logging.DEBUG)
            return hdlr

        hdlr = get_handler()
        self.sci.logger.addHandler(hdlr)

        # generate some messages (logged and not logged)
        self.sci.ones(1, verbose=True)

        self.sci.logger.setLevel(logging.DEBUG)
        self.sci.zeros(1)
        # check the output
        lines = hdlr.stream.getvalue().strip().split('\n')
        resp = '\n'.join(lines)
        assert 'zeros(A__)' in resp
        print(resp)
        assert '0.' in resp
        assert 'loadmatfile ' in resp

        # now make an object with a desired logger
        logger = get_log('test')
        hdlr = get_handler()
        logger.addHandler(hdlr)

        logger.setLevel(logging.INFO)
        sci2 = Scilab2Py(logger=logger)
        # generate some messages (logged and not logged)
        sci2.ones(1, verbose=True)
        sci2.logger.setLevel(logging.DEBUG)
        sci2.zeros(1)
        sci2.exit()

        # check the output
        lines = hdlr.stream.getvalue().strip().split('\n')
        resp = '\n'.join(lines)
        assert 'zeros(A__)' in resp
        assert '0.' in resp
        assert 'loadmatfile' in resp
コード例 #3
0
    def run(self):
        """
        Create a unique instance of Scilab and verify namespace uniqueness.

        Raises
        ======
        Scilab2PyError
            If the thread does not sucessfully demonstrate independence

        """
        scilab = Scilab2Py()
        # write the same variable name in each thread and read it back
        scilab.push('name', self.getName())
        name = scilab.pull('name')
        now = datetime.datetime.now()
        print("{0} got '{1}' at {2}".format(self.getName(), name, now))
        scilab.exit()
        try:
            assert self.getName() == name
        except AssertionError:  # pragma: no cover
            raise Scilab2PyError('Thread collision detected')
        return
コード例 #4
0
 def setUp(self):
     self.sci = Scilab2Py()
     self.sci.getd(THIS_DIR)
コード例 #5
0
 def test_temp_dir(self):
     with Scilab2Py(temp_dir='.') as sci:
         thisdir = os.path.dirname(os.path.abspath('.'))
         assert sci._reader.out_file.startswith(thisdir)
         assert sci._writer.in_file.startswith(thisdir)
コード例 #6
0
#!/usr/bin/env python
import struct
import serial
from time import sleep
import math
from pprint import pprint
import os
os.environ[
    "PATH"] += os.pathsep + "/Applications/scilab-5.5.2.app/Contents/MacOS/bin"
from scilab2py import Scilab2Py
sci = Scilab2Py()

#SMORA = 'L'
SMORA = 'XL'


def set_PID_parameters(Kp, Ki, Kd, Kf, frequency):
    print "* Sending bytes..."
    ser.write(
        struct.pack("<BffffH", 0xFB, float(Kp), float(Ki), float(Kd),
                    float(Kf), frequency))
    print "* Waiting for answer..."
    while 1:
        data = ser.readline().strip()
        if 'done' in data:
            break
    print "* Done"


def retrieve_PID_samples(initSpeed, finalSpeed, duration):
    print "* Sending bytes..."
コード例 #7
0
 def __init__(self):
     """Create our scilab instance and initialize the data array
     """
     self.scilab = Scilab2Py()
     self.array = []
コード例 #8
0
 def test_call_path(self):
     with Scilab2Py() as sci:
         sci.getd(THIS_DIR)
         DATA = sci.test_datatypes()
     assert DATA.string.basic == 'spam'
コード例 #9
0
 def test_timeout(self):
     with Scilab2Py(timeout=2) as sci:
         sci.xpause(2.1e6, timeout=20)
         test.assert_raises(Scilab2PyError, sci.xpause, 10e6)
コード例 #10
0
 def test_using_closed_session(self):
     with Scilab2Py() as sci:
         sci.exit()
         test.assert_raises(Scilab2PyError, sci.eval, 'ones')
コード例 #11
0
 def setUpClass(cls):
     cls.sci = Scilab2Py()
     cls.sci.getd(THIS_DIR)
     cls.data = cls.sci.test_datatypes()
コード例 #12
0
 def setUpClass(cls):
     with Scilab2Py() as sci:
         sci.getd(THIS_DIR)
         cls.data = sci.test_datatypes()
コード例 #13
0
 def setUpClass(cls):
     cls.sci = Scilab2Py()
     cls.sci.getd(THIS_DIR)