Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial
- from binascii import unhexlify
- arduino = serial.Serial(port='COM4', baudrate=115200, bytesize=8)
- doCapture = False
- while not doCapture:
- doCapture = input("Start capture? ") == "A"
- buffer = []
- arduino.write(bytes("A", 'utf-8'))
- prevByte = b""
- currByte = b""
- line = arduino.readline().strip()
- while True:
- if len(line) == 1:
- currByte = unhexlify(b'0' + line)
- if (prevByte == b"\xff" and currByte == b"\xd8"):
- buffer = [b"\xff", b"\xd8"]
- print("found a new start")
- else:
- buffer.append(currByte)
- if len(line) == 2:
- currByte = unhexlify(line)
- if (prevByte == b"\xff" and currByte == b"\xd8"):
- buffer = [b"\xff", b"\xd8"]
- print("found a new start")
- else:
- buffer.append(currByte)
- if line == b"End read" or (prevByte == b"\xff" and currByte == b"\xd9"):
- break
- line = arduino.readline().strip()
- prevByte = currByte
- data = b"".join(buffer)
- print(data)
- with open("C:/Users/Hammad/Documents/GitHub/SBudniC/cameraPrintBytesTest/test.jpg", "wb") as f:
- f.write(data)
- arduino.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement