adafruit / adafruit/Adafruit-VC0706-Serial-Camera-Library
Error Upon Running the program
- Dominant language
- C++
- Stars
- 139
- Forks
- 108
- PR merge metrics
- No merged PRs in 30d
Description
Traceback (most recent call last):
File "C:\Users\Benson\Desktop\Python33\pyserial-2.7\serial\Pyhton Arduino Camera sketch.py", line 120, in
if (not getversion()):
File "C:\Users\Benson\Desktop\Python33\pyserial-2.7\serial\Pyhton Arduino Camera sketch.py", line 54, in getversion
if checkreply(r, CMD_GETVERSION):
File "C:\Users\Benson\Desktop\Python33\pyserial-2.7\serial\Pyhton Arduino Camera sketch.py", line 36, in checkreply
if (r[0] == 0x76 and r[1] == SERIALNUM and r[2] == b and r[3] == 0x00):
IndexError: list index out of range
Thank you for any help on this matter I have double checked all of my code and believe that it is the exact same as what you have posted, I am running python 3.3.4 and can't come to a conclusion why I am getting an out of range error.
# python code for interfacing to VC0706 cameras and grabbing a photo
# pretty basic stuff
# written by ladyada. MIT license
import serial
BAUD = 38400
PORT = "COM4" # change this to your com port!
TIMEOUT = 0.2
SERIALNUM = 0 # start with 0
COMMANDSEND = 0x56
COMMANDREPLY = 0x76
COMMANDEND = 0x00
CMD_GETVERSION = 0x11
CMD_RESET = 0x26
CMD_TAKEPHOTO = 0x36
CMD_READBUFF = 0x32
CMD_GETBUFFLEN = 0x34
FBUF_CURRENTFRAME = 0x00
FBUF_NEXTFRAME = 0x01
FBUF_STOPCURRENTFRAME = 0x00
getversioncommand = [COMMANDSEND, SERIALNUM, CMD_GETVERSION, COMMANDEND]
resetcommand = [COMMANDSEND, SERIALNUM, CMD_RESET, COMMANDEND]
takephotocommand = [COMMANDSEND, SERIALNUM, CMD_TAKEPHOTO, 0x01, FBUF_STOPCURRENTFRAME]
getbufflencommand = [COMMANDSEND, SERIALNUM, CMD_GETBUFFLEN, 0x01, FBUF_CURRENTFRAME]
def checkreply(r, b):
r = map (ord, r)
if (r[0] == 0x76 and r[1] == SERIALNUM and r[2] == b and r[3] == 0x00):
return True
return False
def reset():
cmd = ''.join (map (chr, resetcommand))
s.write(cmd)
reply = s.read(100)
r = list(reply)
if checkreply(r, CMD_RESET):
return True
return False
def getversion():
cmd = ''.join (map (chr, getversioncommand))
s.write(cmd)
reply = s.read(16)
r = list(reply);
if checkreply(r, CMD_GETVERSION):
print r
return True
return False
def takephoto():
cmd = ''.join (map (chr, takephotocommand))
s.write(cmd)
reply = s.read(5)
r = list(reply);
if (checkreply(r, CMD_TAKEPHOTO) and r[3] == chr(0x0)):
return True
return False
def getbufferlength():
cmd = ''.join (map (chr, getbufflencommand))
s.write(cmd)
reply = s.read(9)
r = list(reply);
if (checkreply(r, CMD_GETBUFFLEN) and r[4] == chr(0x4)):
l = ord(r[5])
l <<= 8
l += ord(r[6])
l <<= 8
l += ord(r[7])
l <<= 8
l += ord(r[8])
return l
```
return 0
```
readphotocommand = [COMMANDSEND, SERIALNUM, CMD_READBUFF, 0x0c, FBUF_CURRENTFRAME, 0x0a]
def readbuffer(bytes):
addr = 0
photo = []
```
while (addr < bytes + 32):
command = readphotocommand + [(addr >> 24) & 0xFF, (addr >> 16) & 0xFF,
(addr >> 8) & 0xFF, addr & 0xFF]
command += [0, 0, 0, 32] # 32 bytes at a time
command += [1,0] # delay of 10ms
#print map(hex, command)
cmd = ''.join(map (chr, command))
s.write(cmd)
reply = s.read(32+5)
r = list(reply)
if (len(r) != 37):
continue
if (not checkreply(r, CMD_READBUFF)):
print "ERROR READING PHOTO"
return
photo += r[5:]
addr += 32
return photo
```
###### ## main
s = serial.Serial(PORT, baudrate=BAUD, timeout=TIMEOUT)
reset()
if (not getversion()):
print "Camera not found"
exit
print "VC0706 Camera found"
if takephoto():
print "Snap!"
bytes = getbufferlength()
print bytes, "bytes to read"
photo = readbuffer(bytes)
# photo = readbuffer(5024)
f = open("photo.jpg", 'w')
print photo
photodata = ''.join(photo)
f.write(photodata)
f.close()
# print len(photo)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Python code shown in the issue, especially checkreply(), getversion(), and the call at line 120, then run it with Python 3.3.4 against the VC0706 camera on COM4. Determine why the reply list is shorter than expected and verify that the program handles the camera response without IndexError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100