when i am using this code given below i having some issues.
1. when i am running this code it runs as i want capturing 3 photos one by one and doing some processing on the captured image in the function in CanonCaptureEvent()
2. when i click start button second time right after the first time process it creating some issue that the images are not capturing and not storing. it happens after every second time start button click
3.and somehow if images are captured then 3rd image is being captured corrupted and now able to do process even in 1st image too.
>> and while 2nd or 3rd time (or after 2nd click every time)clicking image it gives me error message that : SDK Error code: DEVICE_BUSY (81)
here the functions that are in the MainWindow.cs are
Start_Button_Click()
CanonCaptureEvent()
here the functions that are in the CameraSettings.cs are
public async Task TakePhoto(int photoIndex = 1)
MainCamera_DownloadReady()
here the functions that are in the Camera.cs are(canon sdk class)
public void TakePhoto()
public void DownloadFile(DownloadInfo Info, string directory)
What I have tried:
public async void Start_Button_Click(object sender, EventArgs e)
{
try
{
if(iscamera == "canon camera")
{
try
{
curDateTime = DateTime.Now.ToString("dd-MM-yyyy(HH-mm-ss)");
var defaultDelay = 1500;
MessageBox.Show("camset :" + curDateTime);
Todaysdate = curpath;
if (!Directory.Exists(Todaysdate))
{
Directory.CreateDirectory(Todaysdate);
}
cameraSettings.directory = Todaysdate;
await cameraSettings.TakePhoto();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
catch (Exception exx)
{
MessageBox.Show(exx.Message);
}
}
public async Task TakePhoto(int photoIndex = 1)
{
it = photoIndex;
var defaultDelay = 3000;
await Task.Delay(defaultDelay);
if (it == 1)
{
await Task.Delay(defaultDelay);
}
else if (it == 2)
{
await Task.Delay(defaultDelay);
}
else if (it == 3)
{
await Task.Delay(defaultDelay);
}
MainCamera.TakePhoto();
}
public void TakePhoto()
{
CheckState();
SendCommand(CameraCommand.TakePicture);
}
private void MainCamera_DownloadReady(Camera sender, DownloadInfo Info)
{
if(Info.IsRAW)
{
return;
}
try
{
string path = directory;
Info.FileName = it.ToString() + ".jpg";
sender.DownloadFile(Info, path);
Invoke((Action)delegate { MainProgressBar.Value = 0; });
if (it >= 3)
{
var table = this.Parent.CanonCaptureEvent(null);
}
else if (it < 3)
{
this.TakePhoto(++it);
}
}
catch (Exception ex) { ReportError(ex.Message, false); }
}
public void DownloadFile(DownloadInfo Info, string directory)
{
CheckState();
if (Info == null) throw new ArgumentNullException(nameof(Info));
if (directory == null || string.IsNullOrEmpty(directory.Trim())) directory = ".";
string currentFile = Path.Combine(directory, Info.FileName);
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
DownloadToFile(Info, currentFile);
}
public async Task<DataTable> CanonCaptureEvent(object obj)
{
if (mr.Read("savedpath") != null)
{
string Savedpath = mr.Read("savedpath");
Todaysdate = Savedpath;
}
if (!Directory.Exists(Todaysdate))
{
Directory.CreateDirectory(Todaysdate);
}
await Task.Delay(defaultDelay);
try
{
imgInput = new Image<Bgr, byte>(Todaysdate + "\\" + "1.jpg");
}
}
RefreshGridView();
return table;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}