Binary data with pyserial(python serial port)

前端 未结 3 587
滥情空心
滥情空心 2021-02-04 04:43

serial.write() method in pyserial seems to only send string data. I have arrays like [0xc0,0x04,0x00] and want to be able to send/receive them via the serial port? Are there any

3条回答
  •  感动是毒
    2021-02-04 05:42

    An alternative method, without using the array module:

    def a2s(arr):
        """ Array of integer byte values --> binary string
        """
        return ''.join(chr(b) for b in arr)
    

提交回复
热议问题