Example #1
0
def test_serialize_frame_with_empty_payload():
    empty_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5, b'')
    (base, ) = list(_frames.serialize_frame(empty_frame))
    assert base[
        0:
        16] == b'\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x04\x05\x00'
    assert base[16:] == b'\x00\x00\x00\x00\x00\x00\x00\x00'
Example #2
0
    def write(
            self,
            frames,
            timeout=10):
        # type: (typing.Iterable[types.Frame], float) -> None
        """Write frame data.

        Args:
            frames(list of float): One or more :any:`nixnet.types.Frame` objects to be
                written to the session.
            timeout(float): The time in seconds to wait for number to read
                frame bytes to become available.

                If 'timeout' is positive, this function waits up to that 'timeout'
                for space to become available in queues. If the space is not
                available prior to the 'timeout', a 'timeout' error is returned.

                If 'timeout' is 'constants.TIMEOUT_INFINITE', this functions
                waits indefinitely for space to become available in queues.

                If 'timeout' is 'constants.TIMEOUT_NONE', this function does not
                wait and immediately returns with a 'timeout' error if all data
                cannot be queued. Regardless of the 'timeout' used, if a 'timeout'
                error occurs, none of the data is queued, so you can attempt to
                call this function again at a later time with the same data.
        """
        units = itertools.chain.from_iterable(
            _frames.serialize_frame(frame.to_raw())
            for frame in frames)
        bytes = b"".join(units)
        self.write_bytes(bytes, timeout)
Example #3
0
    def write_raw(self, raw_frames, timeout=10):
        """Write raw CAN frame data.

        Args:
            raw_frames: One or more :any:`nixnet.types.RawFrame` objects to be
                written to the session.
            timeout: The time to wait for the data to be queued up for transmit.
                The 'timeout' is represented as 64-bit floating-point in units of seconds.

                If 'timeout' is positive, this function waits up to that 'timeout'
                for space to become available in queues. If the space is not
                available prior to the 'timeout', a 'timeout' error is returned.

                If 'timeout' is 'constants.TIMEOUT_INFINITE', this functions
                waits indefinitely for space to become available in queues.

                If 'timeout' is 'constants.TIMEOUT_NONE', this function does not
                wait and immediately returns with a 'timeout' error if all data
                cannot be queued. Regardless of the 'timeout' used, if a 'timeout'
                error occurs, none of the data is queued, so you can attempt to
                call this function again at a later time with the same data.
        """
        units = itertools.chain.from_iterable(
            _frames.serialize_frame(frame) for frame in raw_frames)
        bytes = b"".join(units)
        self.write_bytes(bytes, timeout)
Example #4
0
def test_serialize_frame_with_base_payload():
    payload = b'\x01\x02\x03\x04\x05\x06\x07\x08'
    base_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5,
                                payload)
    (base, ) = list(_frames.serialize_frame(base_frame))
    assert base[
        0:
        16] == b'\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x04\x05\x08'
    assert base[16:] == b'\x01\x02\x03\x04\x05\x06\x07\x08'
Example #5
0
    def write_raw(self, raw_frames):
        """Write raw CAN frame data.

        Args:
            raw_frames: A list of :any:`nixnet.types.RawFrame` objects to be
                written to the session.
        """
        units = itertools.chain.from_iterable(
            _frames.serialize_frame(frame) for frame in raw_frames)
        bytes = b"".join(units)
        self.write_bytes(bytes)
Example #6
0
    def write(
            self,
            frames):
        # type: (typing.Iterable[types.Frame]) -> None
        """Write frame data.

        Args:
            frames(list of float): One or more :any:`nixnet.types.Frame` objects to be
                written to the session.
        """
        units = itertools.chain.from_iterable(
            _frames.serialize_frame(frame.to_raw())
            for frame in frames)
        bytes = b"".join(units)
        self.write_bytes(bytes)
Example #7
0
    def convert_frames_to_signals(self, frames):
        # type: (typing.Iterable[types.Frame]) -> typing.Iterable[typing.Tuple[int, float]]
        """Convert Frames to signals.

        The frames passed into the ``frames`` array are read one by one, and
        the signal values found are written to internal buffers for each
        signal. Frames are identified by their identifier (FlexRay: slot)
        field. After all frames in ``frames`` array are processed, the internal
        signal buffers' status is returned with the corresponding timestamps
        from the frames where a signal value was found. The signal internal
        buffers' status is being preserved over multiple calls to this
        function.

        This way, for example, data returned from multiple calls of nxFrameRead
        for a Frame Input Stream Mode session (or any other Frame Input
        session) can be passed to this function directly.

        .. note:: Frames unknown to the session are silently ignored.
        """
        units = itertools.chain.from_iterable(
            _frames.serialize_frame(frame.to_raw()) for frame in frames)
        bytes = b"".join(units)
        return self._convert_bytes_to_signals(bytes)
Example #8
0
def test_serialize_frame_with_excessive_payload():
    payload = 0xFF * b'\x01\x02\x03\x04\x05\x06\x07\x08'
    base_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5,
                                payload)
    with pytest.raises(errors.XnetError):
        list(_frames.serialize_frame(base_frame))
Example #9
0
 def write_raw(self, raw_frames):
     "http://zone.ni.com/reference/en-XX/help/372841N-01/nixnet/nxwriteframe/"
     units = itertools.chain.from_iterable(
         _frames.serialize_frame(frame) for frame in raw_frames)
     bytes = b"".join(units)
     self.write_bytes(bytes)