Rasppie and PC are connected via serial communication
I'm trying to transfer images from Rasppie to a PC with Python3,
The following error has occurred.
Applicable source code
File "C: ~ \ bytes_receive_1.py", line 16, in bytes_receive img_bytes = "" .join (img_bytes_list) #list → character string TypeError: sequence item 0: expected str instance, bytes found
Python3 PC side server_main_0_1.py #-*-coding: utf-8-*- from bytes_receive_1 import bytes_receive from bytes_convert_img_0_2 import convert_img img_bytes = bytes_receive () img = convert_img (img_bytes) img.save ('./ images/decoded_img.jpg', quality = 75) bytes_receive_1.py #-*-coding: utf-8-*- import serial def bytes_receive (): ser = serial.Serial ( port = "COM6", baudrate = 115200, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, timeout = 5 ) img_bytes_list = ser.readlines () print (img_bytes_list) img_bytes = "" .join (img_bytes_list) #list → character string print (img_bytes) ser.close () print ("End") return img_bytes Rasp pie side client_main_1.py #-*-coding: utf-8-*- from img_convert_string_1_1 import convert_string from string_transfer_0 import transfer_to_pc img_gray = "../images/smile_img.jpg" img_string = convert_string (img_gray) transfer_to_pc (img_string) img_convert_string_1_1.py #-*-coding: utf-8-*- #import numpy as np from PIL import Image def convert_string (img_gray = "../images/smile_img.jpg"): #img = np.array (Image.open (img_gray)) #Image is converted to ndarray img = Image.open (img_gray) (width, height) = img.size print ((width, height)) #img_string = img.tobytes () + b "\ n" img_string = img.tobytes () #Convert to byte array return img_string string_transfer_0.py #-*-coding: utf-8-*- import serial def transfer_to_pc (string): port = serial.Serial ( port = "/ dev/ttyS0", baudrate = 115200, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, timeout = 3.0 ) port.write (string) port.close ()
Server_main_0_1.py on the PC side
Run client_main_1.py on the rasp pie side.
Please provide more detailed information here.
Answer # 1
That's fine if you follow tachikoma's advice.
Changed as follows in bytes_receive_1.py on the PC side.
img_bytes ="".join (img_bytes_list) #list → string
img_bytes = b"".join (img_bytes_list) #list → string
Answer # 2
img_string = img.tobytes () #Convert to byte array
A byte string, not a byte string?
- how to handle python list
- python - i'm trying to use get_dummys for one hot encoding, but i can't handle duplicates properly
- python - i want to extract groups and combine strings in specific columns
- python - when writing to a file and then reading, the strings are linked and printed
- how to handle multidimensional list in python
- python - i want to read the file, sort the strings into each file, and print out only the strings that do not apply, but they ar
- about deleting strings (python)
- i want to handle backslashes in string replacement in python
- python - i want to customize the selection of strings with qlineedit
- about extracting python strings
- transfer from txt file to existing excel sheet in python
- python 3x - i don't know how to handle variables in python
- how to handle python nested dictionaries
- python 3x - i want to extract only strings and numbers from a data frame (object type) that contains a mixture of strings, numbe
- i want to handle json in python by specifying the dot directly with the key name
- python - how to handle exe error no module named'scipysparsecsgraph_validation' with cx_freeze
- python - i want to use the stack to reverse the strings, but an error occurs, so please give me a solution
- python - i don't know how to handle the error that occurred in the production environment (djangodbutilsprogrammingerror: column
- python scraping: how to handle "years" in regular expressions
- python - regarding how to handle the list output string as a list type
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- android studio - unresolved reference comes out in kotlin
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- python - importerror: cannot import name md5 error cannot be resolved