当前位置: 首页>>代码示例>>Python>>正文


Python APIFrame.fill方法代码示例

本文整理汇总了Python中xbee.frame.APIFrame.fill方法的典型用法代码示例。如果您正苦于以下问题:Python APIFrame.fill方法的具体用法?Python APIFrame.fill怎么用?Python APIFrame.fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xbee.frame.APIFrame的用法示例。


在下文中一共展示了APIFrame.fill方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: txXBee

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
class txXBee(protocol.Protocol, ZigBee):
    def __init__(self, escaped=True):
        self._escaped = escaped
	self._frame = None

    def dataReceived(self, data):
        for c in data:
            if self._frame:
                self._frame.fill(c)
                if self._frame.remaining_bytes() == 0:
		    try:
			# Try to parse and return result
			self._frame.parse()
			self.handle_packet(self._split_response(self._frame.data))
		    except ValueError:
			# Bad frame, so restart
                        self.handle_badframe(self._frame.raw_data)
		    self._frame = None
	    else:
		if c == APIFrame.START_BYTE:
		    self._frame = APIFrame(escaped=self._escaped)
                    self._frame.fill(c)

    def handle_packet(self, packet):
        pass

    def handle_badframe(self, packet):
        pass

    def _write(self, data):
	frame = APIFrame(data, self._escaped).output()
	self.transport.write(frame)
开发者ID:mmattice,项目名称:txXBee,代码行数:34,代码来源:protocol.py

示例2: _wait_for_frame

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def _wait_for_frame(self, timeout=None):
        """
        _wait_for_frame: None -> binary data

        _wait_for_frame will read from the serial port until a valid
        API frame arrives. It will then return the binary data
        contained within the frame.

        If this method is called as a separate thread
        and self.thread_continue is set to False, the thread will
        exit by raising a ThreadQuitException.
        """
        frame = APIFrame(escaped=self._escaped)

        deadline = 0
        if timeout is not None and timeout > 0:
            deadline = time.time() + timeout

        while True:
                if self._callback and not self._thread_continue:
                    raise ThreadQuitException

                if self.serial.inWaiting() == 0:
                    if deadline and time.time() > deadline:
                        raise _TimeoutException
                    time.sleep(.01)
                    continue

                byte = self.serial.read()

                if byte != APIFrame.START_BYTE:
                    continue

                # Save all following bytes, if they are not empty
                if len(byte) == 1:
                    frame.fill(byte)

                while(frame.remaining_bytes() > 0):
                    byte = self.serial.read()

                    if len(byte) == 1:
                        frame.fill(byte)

                try:
                    # Try to parse and return result
                    frame.parse()

                    # Ignore empty frames
                    if len(frame.data) == 0:
                        frame = APIFrame()
                        continue

                    return frame
                except ValueError:
                    # Bad frame, so restart
                    frame = APIFrame(escaped=self._escaped)
开发者ID:nioinnovation,项目名称:python-xbee,代码行数:58,代码来源:base.py

示例3: test_unescape_input

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
 def test_unescape_input(self):
     """
     APIFrame must properly unescape escaped input
     """
     test_data = b'\x7D\x23'
     expected_data = b'\x03'
     frame = APIFrame(escaped=True)
     
     for byte in [test_data[x:x+1] for x in range(0, len(test_data))]:
         frame.fill(byte)
     self.assertEqual(frame.raw_data, expected_data)
开发者ID:ymichael,项目名称:xbns,代码行数:13,代码来源:test_frame.py

示例4: test_invalid_checksum

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def test_invalid_checksum(self):
        """
        when an invalid frame is read, an exception must be raised
        """
        api_frame = APIFrame()
        frame = b'\x7E\x00\x01\x00\xF6'
        
        for byte in frame:
            api_frame.fill(intToByte(byteToInt(byte)))

        self.assertRaises(ValueError, api_frame.parse)
开发者ID:ymichael,项目名称:xbns,代码行数:13,代码来源:test_frame.py

示例5: _wait_for_frame

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def _wait_for_frame(self, timeout=None):
        """
        _wait_for_frame: None -> binary data
        
        _wait_for_frame will read from the serial port until a valid
        API frame arrives. It will then return the binary data
        contained within the frame.

        If this method is called as a separate thread
        and self.thread_continue is set to False, the thread will
        exit by raising a ThreadQuitException.
        """
        frame = APIFrame(escaped=self._escaped)

        deadline = 0
        if timeout is not None and timeout > 0:
            deadline = time.time() + timeout

        while True:
            if self._exit.is_set():
                raise ThreadQuitException

            byte = self.serial.read()

            if byte != APIFrame.START_BYTE:
                if deadline and time.time() > deadline:
                    raise TimeoutException
                continue

            if timeout is not None and timeout > 0:
                deadline = time.time() + timeout

            frame.fill(byte)  # Save all following bytes

            while frame.remaining_bytes() > 0:
                if self._exit.is_set():
                    raise ThreadQuitException

                if self.serial.inWaiting() < 1 and deadline and time.time() > deadline:
                    raise TimeoutException, len(frame.data)

                byte = self.serial.read(frame.remaining_bytes())
                for b in byte:
                    frame.fill(b)

            try:
                # Try to parse and return result
                frame.parse()
                return frame
            except ValueError:
                # Bad frame, so restart
                frame = APIFrame(escaped=self._escaped)
开发者ID:hoopes,项目名称:python-xbee,代码行数:54,代码来源:base.py

示例6: test_single_byte

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def test_single_byte(self):
        """
        read a frame containing a single byte
        """
        api_frame = APIFrame()

        frame = b'\x7E\x00\x01\x00\xFF'
        expected_data = b'\x00'
        
        for byte in frame:
            api_frame.fill(intToByte(byteToInt(byte)))
        api_frame.parse()

        self.assertEqual(api_frame.data, expected_data)
开发者ID:ymichael,项目名称:xbns,代码行数:16,代码来源:test_frame.py

示例7: _wait_for_frame

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def _wait_for_frame(self):
        """
        _wait_for_frame: None -> binary data

        _wait_for_frame will read from the serial port until a valid
        API frame arrives. It will then return the binary data
        contained within the frame.

        If this method is called as a separate thread
        and self.thread_continue is set to False, the thread will
        exit by raising a ThreadQuitException.
        """

        frame = APIFrame(escaped=self._escaped)

        while True:
            if self._callback and not self._thread_continue:
                raise ThreadQuitException

            bytes = self.serial.read(1)
            byte = bytes[0]

            if byte != APIFrame.START_BYTE:
                continue

            frame.fill(byte)

            while True:
                remaining_bytes = frame.remaining_bytes()
                if remaining_bytes < 1:
                    break
                bytes = self.serial.read(remaining_bytes)
                for byte in bytes:
                    frame.fill(byte)

            try:
                # Try to parse and return result
                frame.parse()

                # Ignore empty frames
                if len(frame.data) == 0:
                    frame = APIFrame()
                    continue

                return frame
            except ValueError:
                # Bad frame, so restart
                frame = APIFrame(escaped=self._escaped)
开发者ID:jleben,项目名称:python-xbee,代码行数:50,代码来源:base.py

示例8: _wait_for_frame

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def _wait_for_frame(self, msec):
        """
        _wait_for_frame: None -> binary data
        
        _wait_for_frame will read from the serial port until a valid
        API frame arrives. It will then return the binary data
        contained within the frame.

        If this method is called as a separate thread
        and self.thread_continue is set to False, the thread will
        exit by raising a ThreadQuitException.
        """
        frame = APIFrame(escaped=self._escaped)
        timeoutflag = False if msec < 0 else True
        limit = time.time() + msec / 1000.0
        
        while True:
                if timeoutflag and time.time() > limit:
                    return None

                if self._callback and not self._thread_continue:
                    raise ThreadQuitException

                if self.serial.inWaiting() == 0:
                    time.sleep(.01)
                    continue
                
                byte = self.serial.read()

                if byte != APIFrame.START_BYTE:
                    continue

                # Save all following bytes
                frame.fill(byte)
                while(frame.remaining_bytes() > 0):
                    frame.fill(self.serial.read())

                try:
                    # Try to parse and return result
                    frame.parse()
                    return frame
                except ValueError:
                    # Bad frame, so restart
                    frame = APIFrame(escaped=self._escaped)
开发者ID:HuangZhenQiu,项目名称:NanoKong,代码行数:46,代码来源:base.py

示例9: _wait_for_frame

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def _wait_for_frame(self):
        """
        _wait_for_frame: None -> binary data
        
        _wait_for_frame will read from the serial port until a valid
        API frame arrives. It will then return the binary data
        contained within the frame.

        If this method is called as a separate thread
        and self.thread_continue is set to False, the thread will
        exit by raising a ThreadQuitException.
        """
        frame = APIFrame(escaped=self._escaped)
        mode = 0
        while True:
                if self._callback and not self._thread_continue:
                    raise ThreadQuitException
                
                while (  self.serial.inWaiting() <1):
                    time.sleep(0.01)
                byte = self.serial.read()
                if byte =='':
                    continue 

                if (mode ==0):
                    if byte == APIFrame.START_BYTE:
                        mode=1
                    else:
                        continue

                frame.fill(byte)
                
                if ( (mode==1) and (frame.remaining_bytes() <=0) ) :
                    try:
                        # Try to parse and return result
                        frame.parse()
                        mode =0
                        return frame
                    except ValueError:
                        # Bad frame, so restart
                        mode=0
                        frame = APIFrame(escaped=self._escaped)
开发者ID:AhmedAnsariIIT,项目名称:iitmabhiyanros,代码行数:44,代码来源:base.py

示例10: _process_input

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def _process_input(self, data, events):
        """
        _process_input:

        _process_input will be notified when there is data ready on the
        serial connection to be read.  It will read and process the data
        into an API Frame and then either resolve a frame future, or push
        the frame into the queue of frames needing to be processed
        """
        frame = APIFrame(escaped=self._escaped)

        byte = self.serial.read()

        if byte != APIFrame.START_BYTE:
            return

        # Save all following bytes, if they are not empty
        if len(byte) == 1:
            frame.fill(byte)

        while(frame.remaining_bytes() > 0):
            byte = self.serial.read()

            if len(byte) == 1:
                frame.fill(byte)

        try:
            # Try to parse and return result
            frame.parse()

            # Ignore empty frames
            if len(frame.data) == 0:
                return

            if self._frame_future is not None:
                self._frame_future.set_result(frame)
                self._frame_future = None
            else:
                self._frame_queue.append(frame)
        except ValueError:
            return
开发者ID:nioinnovation,项目名称:python-xbee,代码行数:43,代码来源:base.py

示例11: test_remaining_bytes

# 需要导入模块: from xbee.frame import APIFrame [as 别名]
# 或者: from xbee.frame.APIFrame import fill [as 别名]
    def test_remaining_bytes(self):
        """
        remaining_bytes() should provide accurate indication
        of remaining bytes required before parsing a packet
        """
        api_frame = APIFrame()

        frame = b'\x7E\x00\x04\x00\x00\x00\x00\xFF'
        self.assertEqual(api_frame.remaining_bytes(), 3)
        api_frame.fill(frame[0])
        self.assertEqual(api_frame.remaining_bytes(), 2)
        api_frame.fill(frame[1])
        self.assertEqual(api_frame.remaining_bytes(), 1)
        api_frame.fill(frame[2])
        self.assertEqual(api_frame.remaining_bytes(), 5)
        api_frame.fill(frame[3])
        self.assertEqual(api_frame.remaining_bytes(), 4)
开发者ID:ymichael,项目名称:xbns,代码行数:19,代码来源:test_frame.py


注:本文中的xbee.frame.APIFrame.fill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。