Skip to content

v0.29.1 — 취소된 그랩 뒤 곧 건 시작이 장을 잃지 않게(단발·라이브), 시한 초과 문구, GevSharp 0.5.0 - #16

Merged
cmir79 merged 8 commits into
mainfrom
dev
Sep 27, 2026
Merged

cmir79 merged 8 commits into
mainfrom
dev

Conversation

@cmir79

@cmir79 cmir79 commented Sep 27, 2026

Copy link
Copy Markdown
Owner

What changed and why

GevCam now waits briefly before starting acquisition right after a grab that ended without its frame, because on the
camera measured here a start sent too soon after it can have its frames cut. The wait also covers StartContinuous,
where the same thing can bring up a live stream that delivers nothing. Timeout messages and drop logging after stops are
corrected, and the GigE library moves to GevSharp 0.5.0. No public type or member was added or removed.

Take this release if your host cancels grabs in flight (a loop or cycle token, a UI that aborts a grab) and then grabs
or starts live soon after, or if you run GigE cameras on Windows (GevSharp 0.5.0 fixes a receive-side loss there, below).

Imaging.Gev — a start right after a cancelled grab no longer loses its frames

The 0.29.0 notes said that a grab right after a cancelled grab could time out, that the cause had not been isolated, and
that a change to the grab sequence was planned. This is that change.

What was measured (Basler acA2500-14gm, one camera; exposure 5, 30 and 100 ms; 20–30 tries per point). A single grab
was stopped right after its start, and the next start was sent g ms later:

  • The window in which the next start's frame was cut ended at about previous start + 2 × exposure + 68 ms at all
    three exposures. Inside it, 45–90 % of tries were cut (5 ms: 80 and 87 %; 30 ms: 90 and 45 %; 100 ms: 50 and 50 %).
  • A next start later than previous start + exposure + transfer time (about 70 ms here) was never cut.
  • In every cut try, the stopped grab's frame had not been sent at all. In the same window, every try in which the stopped
    grab's frame did arrive was clean (140 of 140).
  • Why the camera does this was not observed: this model has no readable acquisition-status node. Only the timing rule is a
    measurement.
  • A stop that landed after the exposure, or 20–80 ms into a 100 ms exposure, left nothing behind. In the late-stop runs
    0 of 60 tries were cut without the wait, while in the same run layout a stop 2–7 ms after the call cut 3 of 20.

What GevCam does. After a single grab that sent its start but ended without its frame (timeout or cancellation), the
next start waits until the previous start + exposure + measured transfer time + 25 ms. This applies to the next single
grab and to StartContinuous, and it logs waiting N ms before starting.

  • The measured transfer time is capped at 300 ms, so the wait never exceeds exposure + 325 ms from the previous start. The
    transfer is timed on the host, and without the cap a grab that waited 20 s for a trigger would have made the next wait
    20 s. A capped sample is logged once per open (free-run cameras only).
  • The wait is not counted in the grab's timeout. StartContinuous blocks its caller for it, outside the camera lock.
  • It is skipped when the camera was opened with TriggerMode on. That mode was not measured, and a trigger arriving while
    acquisition is stopped would be lost. TriggerMode is read under the TriggerSelector selected at open, so a frame
    trigger enabled under another selector is not seen and the wait still applies (bounded as above).
  • After a grab that used a normal timeout (default 5000 ms), the moment has usually passed and nothing waits. The wait
    appears mainly after a grab cancelled soon after it was called.

Measured effect. Each result below alternated the wait on and off within the same run, with the grab cancelled 2–7 ms
after the call:

Next start Exposure Without the wait With the wait
single grab, 30 ms later 5 ms 7 of 40 cut 0 of 40
single grab, 100 ms later 100 ms 3 of 20 cut 0 of 20
live, 75 ms later 30 ms 5 of 43: every block cut, no complete frame for 1 s 0 of 42
live, 25 ms later 5 ms 4 of 27: first block cut 0 of 21
live, 100 ms later 100 ms 2 of 24: first block cut 0 of 26

The live rows count only tries whose cancelled start had reached the camera. In each of the five broken live starts, all
15 blocks of the second were cut: the first at about 170 of 563 packets, the rest at 254. That lasted until live was
stopped and started again, so on screen the live view looked frozen. Live
started at once after the cancel was never affected (0 of 35), so the risk is a user pressing Live a moment after a grab
was aborted.

  • Cost: a wait of about exposure + 95 ms after the previous start (≈100 ms at 5 ms exposure, ≈195 ms at 100 ms), and
    only after a grab that ended without its frame.
  • Not measured: other models, including Crevis. On a camera that does not do this, the wait is a short delay after an
    aborted grab. Also unmeasured: a different exposure between the aborted and the next grab, transfers longer than
    300 ms, and a live acquisition stopped right after it started.

Correction to the 0.29.0 README. It said that grabs cancelled within a few milliseconds of the call cut their own
block. A recount of the later runs found the cancelled grab's own block cut in 0 of 758 tries: it arrived whole or was
not sent at all. What got cut was the block of a start sent shortly after it. The README now says so.

Imaging.Gev — timeout message and drop logging

  • The TimeoutException text now names the reason for dropped blocks while the grab waited. If the last drop was not
    Incomplete (chunk payloads, for example), the text no longer says "cut or lost" and adds the camera-state hint, because
    chunk mode is a setting.
  • Drops inside the two-second window after a live stop still reach the timeout text. They are logged as "not a loss",
    so the text does not blame them, but the window is decided by time alone and cannot tell whose block it was. The text
    therefore says one of them may have been this grab's frame.
  • Starting live closes both stop windows. Before, a live stream started within 2 s of the previous live stop had
    its drops logged at Info as "in flight when acquisition stopped, not a loss". In the broken live starts above, all 15
    drop lines of one second were logged that way, so the log looked as if nothing had happened. A single grab still keeps
    the live window, on purpose, so the cut tail of a live stream stopped for a teaching grab is not reported as a loss.
  • Regressions: 10-G-12 (window rules, including the single-grab/live asymmetry), 10-G-13 (wait arithmetic against
    the measured safe points, upper bounds, cap), 10-G-14 (timeout text branches).

Imaging.Gev — GevSharp 0.4.1 → 0.5.0

GevSharp's notes: cmir79/GevSharp#3. What reaches this package:

  • Windows receive: the receive wait is non-blocking with polling. That removes a loss GevSharp measured on Windows with
    resends off and slow transfers.
  • Device loss while loading the camera XML now surfaces as its own type (GevControlLostException,
    GevTimeoutException, ObjectDisposedException). GevCam.Open still rewrites only the control-lost case into its
    "already controlled by another application" message. ReconnectingCam treats any open failure as retryable, so its
    path is unchanged.
  • Stop and stream lifetime: stopping the stream clears the stream channel whatever the caller's token. A receive
    thread that ends on its own reports the stream as stopped, and a closed control channel raises control loss at once.
    GevCam already folds its pump on control loss.
  • Devices that restart block numbers (Crevis, among others) get a new slot when a new leader reuses the number of an
    old, leader-only block.
  • Cache invalidation now reaches registers behind formulas. GevCam's start-line timestamp latch was already fresh
    on both known models, because their XML names the latch as the registers' invalidator.

Measured through this package on the shared Basler with 0.5.0: single grabs, live, short timeouts, repeated cancellations
and an InfiniteTimeSpan grab were all normal, with no warning or error lines ("83 completed, 0 incomplete").

Imaging — contract documentation

  • ICamGrabAsync.GrabFrameAsync: timeout is how long to wait for the frame. An implementation may wait briefly
    before starting acquisition, and that wait is not counted (GevCam: up to exposure + 325 ms, only after a grab that
    ended without its frame).
  • ICam.StartContinuous: it can hold the caller briefly before starting, for the same reason. On a UI thread the UI
    freezes for that long.

Version

0.29.1 — patch. No public type or member was added or removed; the new members are internal. The behaviour changes are
GevCam's start timing after an aborted grab (single grab and StartContinuous), its timeout text, and the log level of
drops after live is restarted. The GevSharp dependency moves from 0.4.1 to 0.5.0. The four packages are released in
lockstep.

Checks

  • dotnet build CvInspect.sln -c Release --no-incremental reports 0 warnings
  • main is an ancestor of this branch (the release-pr-guard job verifies it)
  • the tag will be created on the merge commit, main merged back into dev afterwards, and dev bumped to the next -dev version

GevSharp 0.5.0(태그 v0.5.0, 노트 cmir79/GevSharp PR #3, minor) — CvInspect 통지문의 남은 항목과 그쪽 검토분.
이 패키지에 닿는 것:
- XML 적재가 장치 상실을 원래 형으로 던진다(GevControlLostException·GevTimeoutException·ObjectDisposedException).
  GevCam 열기는 GevControlLostException 만 잡아 사유를 바꾸고 나머지는 전파한다 — ReconnectingCam 은 열기 실패를
  Exception 으로 받으므로 재시도 경로는 그대로다.
- 블록 번호를 다시 세는 장치(Crevis 등)에서 리더만 받은 옛 장 위로 같은 번호의 새 리더가 오면 슬롯을 다시 연다.
- 수신 대기를 논블로킹 + Poll 로 바꿔 Windows 에서 재전송을 끈 채 느린 전송에서 나던 유실을 없앴다(그쪽 실기).
- StopAsync 가 호출자 토큰과 무관하게 SCP/SCDA=0 을 시도, 수신 스레드가 스스로 끝나면 IsStarted=false,
  제어 채널이 닫히면 ControlLost 즉시. GevCam 의 제어 상실 처리(펌프 접기)는 그대로 유효.
- Invalidate 가 수식 뒤 레지스터까지 내려간다. GevCam 의 시작선 래치는 **0.4.1 에서도 이미 새 값**이었다 — 공용
  Basler 에서 GevCam 의 실제 래치 코드를 100 ms 간격으로 불러 ≈0.1 s 분 틱씩 늘었고, 래치 없는 대조 읽기는 같은 값이었다
  (우리 실측). 이유는 Invalidate() 가 아니라 XML 이다: GevTimestampValue 는 두 기종 모두 IntSwissKnife (HIGH << 32) | LOW
  를 거쳐 래치 레지스터 두 개에서 오는데, 그 레지스터들이 래치 쪽을 pInvalidator 로 지목해 래치 명령을 실행하는 순간
  캐시가 버려진다(그쪽 XML 독해 — Basler 는 개체에서 받은 XML, Crevis 는 벤더 XML). 그래서 이 판은 우리 래치를 바꾸지
  않는다. pInvalidator 가 없는 XML 의 장치에서만 의미가 있다.
- 새 공개 API GevDevice.OpenAsync(IPEndPoint) — 장비 없는 GevCam 회귀(시뮬레이터) 후보.

실기(공용 Basler acA2500-14gm, 이 판 + CvInspect dev): 단발·라이브·짧은 시한·취소 반복·Infinite 전부 정상,
경고·오류 0, "83 completed, 0 incomplete". 취소 묶음 ×8 은 0.4.1 과 같은 모양(묶음 직후 그랩 자신의 장이 장치에서
끊겨 시한 초과 2/8) — 새 회귀 없음, 장치 현상은 그대로(다음 판 후보 1).
원자료 D:\.claude\cvinspect-0290-chain\run3-gevsharp050.txt · D:\.claude\cvinspect-0290-cutloop\burst-050.txt.
복원 판은 project.assets.json 에서 GevSharp/0.5.0 확인. 비증분 빌드 경고 0 · 테스트 40 + 30 통과.
0.29.0 게시 직전 실기에서 "취소 직후 다음 그랩의 장이 끊긴다" 가 나왔고(0.4.0 은 그 장을 답으로, 0.4.1 은 시한 초과로)
원인을 못 가린 채 냈다. 가렸다(공용 Basler acA2500-14gm, D:\.claude\cvinspect-cutmech\ run1~5).

기전 — GevCam 세션 위에서 명령을 직접: Start → Stop → g ms → Start, 다음 시작의 장이 끊기는가.
- 시작 응답 뒤 d ms 에 멈춤(d 0~60): 168회 0. 응답 대기 중 취소 여부 무관(a1/a2/a3 같은 비율).
- 노출 5 ms, g 0/25/50/75/100 → 끊김 3/24/26/0/0 (각 30회). g 가 클수록 빠진 패킷이 많다 — 잘림이 늘 앞 시작으로부터
  ≈78 ms 에서 난다. 노출 30 ms, g 0/50/75/100/125/150 → 0/18/9/0/0/0 (20회), 절단 ≈128 ms. 노출 100 ms, g 0/100/150/
  175/200/250/300 → 0/10/10/0/0/0/0 (20회), 절단 ≈268 ms. 세 점 모두 **절단 ≈ 앞 시작 + 2×노출 + 68 ms**.
- 해석: 장치가 시작 직후의 멈춤을 한 장 주기 뒤에 실행하고, 그 사이 들어온 다음 시작의 장을 그 멈춤이 전송 도중에 자른다.
  멈춤이 노출 뒤에 오면 앞 장을 정상대로 끝내고 남는 것이 없다(취소 12 ms 에서 0/40). 라이브 정지 직후 그랩 20회도 0.
- 안전 조건: 다음 시작 ≥ 앞 시작 + 노출 + 전송(≈70 ms). 세 노출에서 경계 양쪽을 쟀다.

조치(GevCam) — 장을 못 받고 끝난 그랩이 시작을 보냈으면, 다음 그랩은 시작 전에 "앞 시작 + 노출 + 잰 전송 + 25 ms" 까지
기다린다. 전송은 최근 정상 그랩의 (시작 → 도착) − 노출로 재고, 모르면 150 ms. 드레인보다 앞에서 기다려 늦게 끝난 앞 장이
드레인에 걸리게 한다. 시한을 다 채우고 끝난 그랩 뒤에는 이미 지나 있어 기다림이 없다. 기다리면 Info 한 줄
("waiting N ms before starting …"). 실기 비용은 비정상 정지 뒤 그랩마다 ≈80~100 ms.
- 검증(같은 런, 켬/끔 번갈아 — 내부 스위치 SettleAfterAbnormalStop): 취소 시점 2~7 ms 흩음 + 간격 30 ms, 80회 →
  켬 0/40, 끔 7/40. 취소 묶음 A/B 두 런 → 켬 0/16 · 끔 2/16(둘째 런은 끔도 0 이라 판별력 없음). 원자료
  D:\.claude\cvinspect-0290-cutloop\gap30-sweep-settle-ab.txt · burst-settle-ab*.txt.
- ⚠ 한 기종에서 잰 기전이다. Crevis 는 못 쟀다 — 멈춤을 곧바로 실행하는 기종이면 이 대기는 무해한 지연일 뿐이다.

후보 2(소비자 제안) — 시한 초과 문구: 기다리는 동안 버려진 블록이 있었으면 "트리거를 보라" 대신 그 사실(마지막 블록 번호·
빠진 패킷)과 "이 그랩의 장이었을 수 있다" 를 싣는다. 진단에 시각이 없어(블록 번호뿐, 시작마다 1 부터 세는 기종도 있다)
이 그랩의 장인지는 가를 수 없고, 그래서 일찍 끝내지 않는다. 취득 라이브러리가 진단에 리더 시각을 싣는 판(그쪽 dev)이 나오면
시작선으로 가를 수 있다.

회귀(장치 불필요): 10-G-13 대기 산술 — 노출 5·30·100 ms 에서 잰 안전 경계(75·100·175 ms)를 넘는지, 전송을 모를 때 더 길게,
노출과 함께 커지는지. 10-G-14 시한 초과 문구 두 갈래. 배선(그랩이 시각을 찍고 기다리는 것)은 실기 몫이다.
문서: Gev README(끊김 기전·조치·검증), GevCamHealth, ICamGrabAsync 의 GevCam 시한 문구 설명.

비증분 빌드 경고 0 · 테스트 40 + 30 통과.
60a42ef 검토(wf_a263d093-93f)에서 살아남은 major 를 고친다.

1) 전송 표본에 상한이 없었다. 시작 명령부터 도착까지를 호스트 시계로 재므로 트리거 대기·재전송이
   끼면 표본이 그만큼 부풀고, 트리거를 20초 기다려 성공한 그랩 하나가 다음 비정상 정지 뒤 대기를
   20초로 만들 수 있었다(코드 경로로 찾은 것, 실기에서 본 것은 아님). 대기는 시한 밖이고 GrabOne 은
   취소 토큰이 없어 닫기만 풀 수 있었다.
   - 표본을 300 ms(MaxReadoutMs)로 자른다 → 대기는 앞 시작으로부터 노출 + 325 ms 를 넘지 않는다.
   - 열 때 TriggerMode On 이면 대기를 걸지 않는다(그 모드는 안 쟀고, 대기 중 트리거는 버려진다).
   - 열 때 전송 표본을 지운다(앞 세션의 ROI·패킷 크기). 노출을 이 세션이 안 쓰면 열 때 읽은 값을 쓴다.

2) StartContinuous 는 대기를 따르지 않았다 — 검토의 예측을 실기로 재현했다(Basler acA2500-14gm,
   부른 뒤 2~7 ms 에 취소 → d ms 뒤 라이브 1초, 같은 런에서 대기 켬/끔 번갈아, 시작이 나간 회차만):
   - 노출 30 ms·d=75: 끔 43회 중 5회는 라이브의 모든 장이 254/563 패킷에서 잘려 온전한 장 0~1장
     (멈췄다 다시 걸면 회복). 켬 0/42.
   - 노출 5 ms·d=25: 끔 4/27 첫 장 잘림, 켬 0/21. 노출 100 ms·d=100: 끔 2/24, 켬 0/26.
   - 곧장(d≈0) 걸면 세 노출 모두 0/35.
   → StartContinuous 도 락 밖에서 같은 대기를 한다.
   그 재현 회차의 드롭 15줄이 전부 "손실 아님"(Info)으로 내려갔다 — 앞 라이브를 멈춘 2초 창 안이었다.
   → 연속 취득을 걸 때 정지 창 둘을 모두 닫는다. 뒤 런에서 같은 드롭이 경고로 나왔다.

3) 노출 도중의 늦은 멈춤(검토 minor): 노출 100 ms 에서 부른 뒤 20·50·80 ms 취소는 대기 없이 0/60,
   같은 런 구조의 2~7 ms 취소는 끔 3/20·켬 0/20 — 시작 기준 대기는 이 범위에서 넉넉한 쪽이다.

4) 기전 문장 정정. "장치가 멈춤을 한 장 주기 뒤에 실행한다" 는 관측이 아니라 해석이었다(취득 상태
   노드를 읽을 수 없는 기종). 원자료로 다시 센 것: 끊긴 회차 97건은 전부 앞 그랩의 장이 아예 안 왔고,
   구간 안에서 앞 장이 온 43건은 전부 안 끊겼다. 취소된 그랩 자신의 블록이 잘려 온 회차는 758회 중 0 —
   0.29.0 README 의 "취소된 그랩은 자기 블록을 끊었다" 를 거둔다(잘린 것은 그 직후 시작의 블록).
   구간 안 끊김률도 노출별로 바로 적었다(5 ms 80·87%, 30 ms 90·45%, 100 ms 50·50%).

5) 시한 초과 문구: 정지 경계 드롭은 세지 않고, 버린 사유를 싣는다. 불완전이 아니면(청크 등) 잘림으로
   단정하지 않고 설정 안내를 함께 낸다.

회귀 10-G-13 에 상한(단위 실수·20초 표본)과 표본 산술, 10-G-14 에 사유 갈래를 더했다.
빌드 --no-incremental 경고 0, 테스트 70/70. 원자료 D:\.claude\cvinspect-0290-cutloop\contab-*.txt,
late-exp100-*.txt, cont-exp*.txt.
- ICamGrabAsync: timeout 은 장을 기다리는 시간이고, 구현이 취득을 걸기 전에 기다리는 몫은 그 밖이다
  (GevCam: 장을 못 받고 끝난 그랩 바로 뒤, 앞 시작으로부터 노출 + 325 ms 이내). 백엔드를 가리지 않는
  소비자는 GevCam 이 아니라 이 문서를 읽는다.
- 정지 창 필드: StartContinuous 가 둘 다 닫고 단발 그랩은 제 창만 닫는 비대칭이 일부러라는 것을 적는다 —
  안 적으면 다음 사람이 "고친다". README 문장도 창마다 언제 닫히는지로 바로잡았다.
- StartContinuous 의 대기는 열려 있고 아직 안 돌 때만 — 닫힌·해제된 카메라가 대기부터 하고 던지지 않게.

빌드 --no-incremental 경고 0, 테스트 70/70.
델타 검토 wf_7cb1b425-95b(715d083·99d4bc4 범위) 반영.

- (살아남은 건) 715d083 이 정지 경계 드롭을 그랩의 드롭 계수에서 뺐는데, 창은 시각으로만 가리므로 라이브를
  멈춘 지 2초 안에 부른 그랩은 **자기 장이 잘려도** 그것이 빠져 문구가 "트리거를 보라" 로 떨어졌다. 원인으로
  단정하지 않는다는 것은 지키되 버리지 않는다 — 따로 세어, 그것뿐이면 "라이브 정지 2초 안에 버려진 블록이
  있었고 손실 아님으로 남겼다, 이 그랩의 장이었을 수 있다" 를 설정 안내와 함께 싣는다.
- 두 창의 규칙을 회귀로(10-G-12): 단발 그랩은 라이브 창을 남기고, 라이브 시작은 둘 다 닫는다.
  MarkLiveStopped·CloseStopWindows 로 뽑았다. 10-G-14 에 정지 창 갈래.
- StartContinuous 의 대기는 제어 상실·기다리는 그랩이 있을 때도 건너뛴다(대기 뒤 던지던 것).
- ICam.StartContinuous 에 "시작 전에 잠깐 붙잡을 수 있다" 를 적는다.
- 전송 상한(300 ms)의 대가를 그 자리에 적고(긴 전송·실제 노출이 더 긴 경우 대기가 모자랄 수 있다 — 잰 것은
  5 MB·1 GbE 하나), 표본이 상한에 걸리면 열 때마다 한 번 Info 로 남긴다. 동작은 바꾸지 않았다(재현 없음).
- TriggerMode 는 열 때 선택된 TriggerSelector 기준으로 읽힌다는 한계를 필드 주석과 README 에 적는다
  (선택자를 돌려 읽으려면 여는 길에서 장치에 써야 해 넣지 않았다).
- 필드 주석 두 곳을 지금 동작에 맞춘다(드롭 계수는 사유 무관, 대기는 연속 시작에도).

빌드 --no-incremental 경고 0, 테스트 70/70.
- 트리거 모드로 읽힌 카메라는 트리거 대기로 표본이 늘 상한에 걸리고 대기도 안 쓰므로, 그 줄이 정상 구성의 열기마다
  뜨는 잡음이 된다 — 거기서는 남기지 않는다.
- StartContinuous 주석의 재현 수치: 5회 모두 온전한 장 0("0~1" 이 아니다), 첫 블록은 ≈170/563·나머지 254/563
  (contab-exp30-d75.txt 재집계).

빌드 --no-incremental 경고 0, 테스트 70/70.
patch: 공개 형식·멤버 추가·제거 없음(새 멤버는 internal). 동작 변경은 GevCam 의 비정상 정지 뒤 시작 시각(단발·연속),
시한 초과 문구, 라이브 재시작 뒤 드롭 로그 등급. GevSharp 0.4.1 → 0.5.0.
빌드 --no-incremental 경고 0, 테스트 70/70.
@cmir79 cmir79 changed the title v0.29.1 v0.29.1 — 취소된 그랩 뒤 곧 건 시작이 장을 잃지 않게(단발·라이브), 시한 초과 문구, GevSharp 0.5.0 Sep 27, 2026
@cmir79
cmir79 merged commit ccb7507 into main Sep 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant