driver.py 文件源码

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

项目:microscan-driver 作者: jonemo 项目源码 文件源码
def connect(
            self, baudrate=None, parity=None, databits=None, stopbits=None):
        """Open a serial port for communication with barcode reader device

        Connection settings are taken from three possible locations in the
        following order:

        - method arguments
        - object properties set directly or in constructor or
          detect_connection_settings()
        - default device settings according to device documentation

        If connection settings (baud rate, parity, etc.) are neither provided
        as arguments nor previously set as object properties, for example by
        a search with the detect_connection_settings() method, the default
        values specified in the device documentation are used. For example,
        page 3-1 of the MS3 user manual specifies:
            - baud rate: 9600
            - parity: even
            - data bits: 7
            - stop bits: 1
            - flow control: none
        """
        baudrate = baudrate or self.baudrate or 9600
        parity = parity or self.parity or serial.PARITY_EVEN
        bytesize = databits or self.databits or serial.SEVENBITS
        stopbits = stopbits or self.stopbits or serial.STOPBITS_ONE

        self.port = serial.Serial(
            self.portname,
            baudrate=baudrate,
            parity=parity,
            bytesize=bytesize,
            stopbits=stopbits,
            timeout=1,
            xonxoff=False,
            rtscts=False,
            dsrdtr=False,
        )

        self._config = self.read_config()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号