Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

windows - really wierd python behaveiour with pythn 3 on raspberry pi(3B+)

i am trying to recieve a message and add error correction, i am using unireedsolomon and python 3.7.3 on the pi and 3.8.3 on my main machine, i get this error on the pi while on my windows computer it works fine:

Traceback (most recent call last):
  File "server.py", line 53, in <module>
    recv = read_rs(recv)
  File "server.py", line 36, in read_rs
    packet1 = coder.decode(packet1).encode()
  File "/home/pi/.local/lib/python3.7/site-packages/unireedsolomon/rs.py", line 294, in decode
    ret = self._list2str(ret)
  File "/home/pi/.local/lib/python3.7/site-packages/unireedsolomon/rs.py", line 493, in _list2str
    return ''.join(chr(x) for x in L)
TypeError: 'NoneType' object is not iterable

sockets is used to get the message from gnuradio

unireedsolomon to decode read solemen codeing

my code:

# first of all import the socket library
import socket
import struct
import array
import zlib
import unireedsolomon as rs
coder = rs.RSCoder(25, 15)
# next create a socket object
s = socket.socket()
print ("Socket successfully created")
port = 25565

s.bind(('', port))
print ("socket binded to %s" %(port))
# put the socket into listening mode
s.listen(5)
print ("socket is listening")
def check_packet(packet):
    packet = bytes(packet)
    id = packet[-2:-1]
    crc = packet[-6:-2]
    crc2 = zlib.crc32(packet[:-6]).to_bytes(4,'big')
    print(crc.hex(),crc2.hex())
    if crc == crc2:
        return id[0]
    else:
        return 255
def read_rs(packet1):
    packet1 = packet1[:-1]
    packet1 = coder.decode(packet1).encode()
    packet1.append(bytes([0]))
    return packet1
while True:
    c, addr = s.accept()
    connected = True
    recv = []
    data1 = []
    i = 0
    while connected:
        try:
            a = c.recv(4)
            data = int(struct.unpack('<f',a)[0])
            recv += bytes([data])
            print(data)
            if data  == 0:
                print(recv)
                recv = read_rs(recv)
                print(recv)
                correct = check_packet(recv)
                if correct != 255:
                    print("packet:",bytes(recv[:-6]).decode(),"number of packet:",correct)
                    while len(data1) < i:
                        data1.append('')
                    while len(data1) > correct:
                        print(''.join(data1))
                        data1 = []
                    data1.append(bytes(recv[:-6]).decode())
                    i = correct
                    print("partial data:",''.join(data1))
                else:
                    print("invaild packet, ignored")
                recv = []
        except:
                raise
question from:https://stackoverflow.com/questions/65868647/really-wierd-python-behaveiour-with-pythn-3-on-raspberry-pi3b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...