comm.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:buttshock-py 作者: metafetish 项目源码 文件源码
def __init__(self, port, key=None, shift_baud_rate=False):
        """Initialization function. Follows RAII, so creating the object opens the
        port."""
        super(ET312SerialSync, self).__init__(key)
        # Allow derived classes to set up a port to mock serial ports for
        # tests. There are cleaner ways to mock this, but this will do for now.
        if not hasattr(self, "port"):
            # Check argument validity
            import serial
            if not port or type(port) is not str:
                raise ButtshockIOError("Serial port name is missing or is not string!")

            self.port = serial.Serial(port, 19200, timeout=1,
                                      parity=serial.PARITY_NONE,
                                      bytesize=8, stopbits=1,
                                      xonxoff=0, rtscts=0)

        self.needs_bytes = False
        # Test for python 3
        if not isinstance(bytes([0]), str):
            self.needs_bytes = True
        self.shift_baud_rate = shift_baud_rate
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号