Convert an int value to unicode

前端 未结 4 711
臣服心动
臣服心动 2020-12-30 23:18

I am using pyserial and need to send some values less than 255. If I send the int itself the the ascii value of the int gets sent. So now I am converting the int into a unic

4条回答
  •  醉梦人生
    2020-12-30 23:49

    Just use chr(somenumber) to get a 1 byte value of an int as long as it is less than 256. pySerial will then send it fine.

    If you are looking at sending things over pySerial it is a very good idea to look at the struct module in the standard library it handles endian issues an packing issues as well as encoding for just about every data type that you are likely to need that is 1 byte or over.

提交回复
热议问题