Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1275

Python • Re: What's wrong with this code?

$
0
0
Excuse me, but python stops at the fist horror and danjpeperron corrcted the first error you made.
from https://pyserial.readthedocs.io/en/late ... l_api.html
serial py can read UP to size (less or equal the number requested)

read(size=1)
Parameters:size – Number of bytes to read.
Returns:Bytes read from the port.
Return type:bytes

Read size bytes from the serial port. If a timeout is set it may return fewer characters than requested. With no timeout it will block until the requested number of bytes is read.

Changed in version 2.5: Returns an instance of bytes when available (Python 2.6 and newer) and str otherwise.
If you receive less than size, you cannot index your array with high indexes. You should at least test the length of the receided string
edited or increase timeout at line .open.ing ...
Other issue

I do not understand

Code:

    #Invert number with xor    crc=~crc&0xFF    crc+=1
[/code]
xor is built in by ^ (like in C end Fortran90 ) It is either complicated (edited likely comment puzlles reader; ) or wrong

Code:

>>> 55 ^0xFF200>>>
BTW: you can embed error messages in Code button : that makes cutting and pasting to a console or to stackoverflow easier!!!

Statistics: Posted by dbrion1 — Thu Jan 11, 2024 3:41 pm



Viewing all articles
Browse latest Browse all 1275

Trending Articles