5.1 개요
- GigE 카메라 Open() 후에 예상치 못한 오류로 Close()를 하지 못했을 때 다시 Open()을 하게 되면 다음과 같은 오류가 발생한다
- System.InvalidOperationException: 'Failed to open 'Basler xxx'. The device is controlled by another application. Err: An attempt was made to access an address location which is currently/momentary not accessible. (0xE1018006)
- BaslerOneShotGrab 프로젝트의 BtnOpen_Click함수를 다시 수정하여 에러 처리를 하겠다.
5.2 코드 입력
private void BtnOpen_Click(object sender, EventArgs e)
{
int timeOutMs = 1000;
try
{
camera.Open();
}
catch (Exception)
{
System.Threading.Thread.Sleep(1000);
if (!camera.IsConnected)
{
camera.Close();
camera.Open(timeOutMs, TimeoutHandling.ThrowException);
}
}
camera.Parameters[PLTransportLayer.HeartbeatTimeout].TrySetValue(timeOutMs, IntegerValueCorrection.Nearest);
camera.Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous);
}
5.3 구문 설명
catch (Exception)
{
System.Threading.Thread.Sleep(1000);
if (!camera.IsConnected)
{
camera.Close();
camera.Open(timeOutMs, TimeoutHandling.ThrowException);
}
}
- Open()함수를 try catch구문으로 감싼 후에 System. InvalidOperationException 관련 Exception처리를 한다.
- 그 다음 1000ms 정도 Open을 실행하고 있는 Thread를 sleep해서 딜레이를 준다
- 이 딜레이는 환경에 따라 맞춰서 설정한다.
- 딜레이 이후 camera가 Connect되지 않았다면 camera.Close()를 하고 다시 재 오픈을 한다.
camera.Parameters[PLTransportLayer.HeartbeatTimeout].TrySetValue(timeOutMs, IntegerValueCorrection.Nearest);
- 해당 파라미터는 Basler의 HeartbeatTimeout을 설정하는 함수다
- TrySetValue함수의 enum변수인 IntegerValueCorrection.Nearest는 timeOutMs값이 설정을 할수 없는 값이라면 유효한 값중에 가장 가까운 값으로 변경해서 입력된다
- Heartbeat주기를 10000ms주면 10000ms안에 다시 Open()을 실행했을 때 Exception이 발생한다
- 이 함수는 camera.Open()함수 바로 밑에 들어가는 것이 맞지만 최초 한번은 Open이 정상적으로 된다는 가정하에 try~catch문 밑에 출력 했으나 현장 상황상 최초 한번도 연결 안될 경우를 대비해 try와 catch구문 안에 조건문을 고려하여 따로 따로 넣어 주는것이 더 좋다고 볼수 있다.
'Basler' 카테고리의 다른 글
4. Multi Camera Grab (0) | 2024.02.15 |
---|---|
3. Continue shot Grab (0) | 2024.02.13 |
2. One shot Grab (0) | 2024.02.11 |
1. c# 작업 환경 만들기 (0) | 2024.02.08 |