part of the problem is that since its an intermittent bug its difficult to provide a solid test case. however, my simplified script should reveal the bug after many iterations.
it may be necessary to run this code a couple of times to see the crash. i've had the same code run 800 iterations and then on the next run crash after 40.
oh, and i should explain what i mean by crash. the script is exited without an error. my logging has shown that this almost always happens on press or release of shoot_half. however, if i remove the shoot_full lines this no longer occurs.
i've also tried calling press("shoot_half") through the pcall method which calls functions and catches errors. it doesn't work.
--[[
Log file handling. Uses io functions if they are available, otherwise print().
Usage:
require "f-log"
log.open("my_log.txt")
log.print("A quick brown fox etc.\n")
log.close()
Author: fudgey 2008/10/27
Licence: GPL v3 or higher
--]]
log={}
-- If io.* are available, open log CHDK/LOGS/name for append. If name==nil, use lua_0000.log
function log.open(name)
log.filename = name
-- yes, use write() for logging
if name==nil then name="lua_0000.log" end
log.file,msg=io.open("A/CHDK/LOGS/"..name,"a")
if not log.file then
log.type=0
print_screen(1)
print("Error opening log, using print() from now on: "..tostring(msg))
else
log.type=1
log.isopen=true
end
bi=get_buildinfo()
log.print("\n--- Log opened at ",date.datetimestamp()," ---\n")
log.print("platform: ",bi.platform," ",bi.platsub,"\n")
log.print("version: ",bi.version," ",bi.build_number," built on ",bi.build_date," ",bi.build_time,"\n")
end
function log.close()
if log.type==1 then
log.print("\n--- Log closed at ",date.datetimestamp()," ---\n")
io.close(log.file)
log.isopen=false
end
end
function log.print(...)
if log.type==1 and log.isopen==true then
log.file:write(...)
log.file:flush()
else
print(...)
end
end
--[[
Find the smallest three digit zero-padded number which doesn't match any
existing file in A/CHDK/LOGS/ when used as a part of a file name of the
form headerNNN.extension. Return complete filename without path.
Example:
logfilename = log.find_new_filename("log_","txt")
will return "log_002.txt" if log_000.txt and log_001.txt already exist.
If all files up to log_999.txt are found, log_999.txt is returned.
--]]
function log.find_new_filename(header,extension)
local numstr
local filename
for i=0,999 do
-- zero pad
if i<10 then
numstr = "00"..tostring(i)
elseif i<100 then
numstr = "0"..tostring(i)
else
numstr = tostring(i)
end
filename = tostring(header) .. numstr .. "." .. tostring(extension)
local filepath="A/CHDK/LOGS/"..filename
log.filename = "A/CHDK/LOGS/"..filename
local r,msg = os.stat(filepath)
if r==nil then
return filename
end
-- note: long for loop without forced sleep!
end
-- no free names found
return filename
end
function log.segmentAndCopy(filePath)
log.close()
disk.moveFile("A/CHDK/LOGS/"..log.filename,filePath)
log.open(log.filename)
end
--[[
Functions that return Date/Time strings for use in CHDK Lua scripts.
Authors: 2009/01/27 mattkime: replace get_time with os.date
2008/10/27 fudgey: datestamp(), datetimestamp()
2008/08/17 Francesco Bonomi: format_nn(), timestamp()
Licence: GPL
--]]
date = {}
-- formats a number to two digit string with leading zeroes e.g. 3 to "03"
-- (only works for numbers in range 0 - 99)
function date.format_nn(n)
local r=tostring(n)
if n<10 then
r= "0" .. n
end
return r
end
-- return a formatted timestamp (hh:mm:ss)
-- if called without parameters, gets current camera time and formats it
-- if a parameter is passed, formats the passed number
function date.timestamp(t)
if t==nil then
return os.date("%X")
else
return os.date("%X",t)
end
end
-- Returns formatted date string from camera clock.
-- Output format example: 2008/09/03
function date.datestamp()
return os.date("%Y/%m/%d")
end
--[[
-- Returns formatted time string from camera clock.
-- Output format example: 23:05:59
function timestamp2()
local H=get_time("h")
local M=get_time("m")
local S=get_time("s")
return format_nn(H) .. ":" .. format_nn(M) .. ":" .. format_nn(S)
end
--]]
-- Returns formatted date + time string from camera clock.
-- Output format example: 2008/09/03 23:05:59
function date.datetimestamp()
return os.date("%Y/%m/%d %X")
end
log.open("F2.log")
counter = 0
repeat
counter = counter + 1
print(counter)
--disk.deleteUntilMbFree100CANON(20,40)
log.print("cam.smartShoot - start\n")
-- Shoot: Half press and wait until camera is ready
press("shoot_half")
repeat
sleep(1)
until get_shooting() == true
log.print("cam.smartShoot - confirm shooting\n")
--not sure what good this does
local bv=get_bv96()
log.print("cam.smartShoot - get bv\n")
local av=get_av96()
log.print("cam.smartShoot - get av\n")
--init aperture and exposure
if(tv ~= nil)then set_prop(propcase.TV,tv) end
if(sv ~= nil)then set_prop(propcase.SV,sv) end
log.print("cam.smartShoot - init aperture and exposure\n")
--set_focus(subjdist)
log.print("cam.smartShoot - focus set\n")
press("shoot_full")
log.print("cam.smartShoot - press shoot full\n")
release("shoot_full")
log.print("cam.smartShoot - release shoot full\n")
release("shoot_half")
log.print("cam.smartShoot - release shoot half\n")
repeat
--log.print("cam.smartShoot - before sleep\n")
sleep(1)
--log.print("cam.smartShoot - after sleep\n")
until get_shooting() ~= true
log.print("cam.smartShoot - end shoot\n")
sleep(500)
until false