TEM3: AutoFlashing Tutorial¶
This tutorial explains how to run FEG AutoFlashing in a safe sequence.
Target flow:
SetBeamValve(0)SetFEGEmissionOff()Poll
GetEmissionOnStatus()until it returns(0, 0)ExecAutoFlashing(1)Poll
GetAutoFlashingStatus()until it returns0ExecEmissionOn(1)Poll
GetEmissionOnStatus()until it returns(0, 1)
Notes:
This procedure modifies the actual instrument state. Follow your facility’s operating rules before executing.
Some
FEG3functions are available only on CFEG instruments.GetAutoFlashingStatus()may temporarily return0immediately afterExecAutoFlashing(1)is called. This tutorial therefore separates the start-confirmation and completion-confirmation steps.
1from datetime import datetime, timedelta
2import time
3
4from PyJEM import TEM3
5
6feg = TEM3.FEG3()
7
8def poll_until(check_func, expected_value, timeout_seconds=60, interval_seconds=1, label="status"):
9 deadline = datetime.now() + timedelta(seconds=timeout_seconds)
10 while datetime.now() < deadline:
11 value = check_func()
12 print(f"{label}: {value}")
13 if value == expected_value:
14 return value
15 time.sleep(interval_seconds)
16 raise TimeoutError(f"Timed out waiting for {label} == {expected_value}")
Step 1. Close beam valve¶
Close the beam valve first to block the beam before changing the emission state.
1feg.SetBeamValve(0)
2print("Beam valve closed.")
Beam valve closed.
Step 2. Turn emission off¶
Stop the FEG emission before starting AutoFlashing.
1feg.SetFEGEmissionOff(1)
2print("FEG emission off command sent.")
FEG emission off command sent.
Step 3. Wait until emission is fully off¶
GetEmissionOnStatus() returns (phase, status).
Poll until the value is (0, 0) to confirm that the emission-off sequence has completed.
1poll_until(
2 feg.GetEmissionOnStatus,
3 (0, 0),
4 timeout_seconds=120,
5 interval_seconds=1,
6 label="GetEmissionOnStatus"
7 )
Step 4. Start auto flashing¶
Start AutoFlashing.
The return value is checked as an indicator that the command was accepted.
1result = feg.ExecAutoFlashing(1)
2print("ExecAutoFlashing(1):", result)
Step 5. Wait until auto flashing completes¶
GetAutoFlashingStatus() may return 0 (Idle) immediately after ExecAutoFlashing(1) because the flashing has not yet started.
This step therefore first waits until 1 (Running) is observed to confirm the start, then waits for the status to return to 0 (Idle) to confirm completion.
1startup_deadline = datetime.now() + timedelta(seconds=30)
2finish_deadline = datetime.now() + timedelta(minutes=10)
3seen_running = False
4
5while datetime.now() < finish_deadline:
6 status = feg.GetAutoFlashingStatus()
7 print("GetAutoFlashingStatus:", status)
8
9 if status == 1:
10 seen_running = True
11
12 if seen_running and status == 0:
13 print("AutoFlashing finished.")
14 break
15
16 if (not seen_running) and datetime.now() > startup_deadline:
17 raise TimeoutError("AutoFlashing did not enter running state within 30 seconds.")
18
19 time.sleep(1)
20else:
21 raise TimeoutError("AutoFlashing did not finish within 10 minutes.")
Step 6. Turn emission on¶
Resume FEG emission after AutoFlashing has completed.
1result = feg.ExecEmissionOn(1)
2print("ExecEmissionOn(1):", result)
Step 7. Wait until emission is fully on¶
Poll GetEmissionOnStatus() until it returns (0, 1) to confirm that the emission-on sequence has completed.
1poll_until(
2 feg.GetEmissionOnStatus,
3 (0, 1),
4 timeout_seconds=180,
5 interval_seconds=1,
6 label="GetEmissionOnStatus"
7 )