본문으로 건너뛰기

AoE (ADS over EtherCAT)

slave.aoe 로 접근한다(지연 생성, 항상 객체를 돌려줌). 슬레이브가 AoE 를 지원하는지는 slave.aoe.is_supported 로 조회한다. 이 속성은 True(메일박스 프로토콜 비트의 긍정적 증거)나 None(미상)만 돌려주고 False 를 절대 내지 않으므로, "미지원이 확인됨"을 판단하는 데 쓸 수 없다.

AoE 는 EtherCAT 으로 ADS 명령을 운반한다. IndexGroup / IndexOffset 으로 슬레이브 데이터를 읽고 쓰며, 장치 정보와 ADS 상태를 읽고, 데이터 변화를 구독한다. 평범한 스캔과 PDO 프로세스 데이터는 이 길을 통과하지 않는다. 장치 문서가 ADS 객체나 ADS 상태 기계를 명시적으로 제공할 때만 쓴다.

메서드 개요​

분류메서드타입읽기/쓰기설명
장치 정보read_device_infodict or None읽기 전용버전 번호를 읽는다. major / minor / build 세 키를 돌려준다. 현재 버전에는 장치 이름이 없다
read_statetuple or None읽기 전용ADS 상태와 장치 상태를 읽는다
상태 제어write_controlbool쓰기 전용슬레이브 ADS 상태를 전환한다
get_ads_state_descriptionstr읽기 전용모듈 수준 함수. ADS 상태 코드를 중국어 설명으로 바꾼다
데이터 읽기/쓰기read_writebytes or None읽기/쓰기IndexGroup / IndexOffset 으로 읽는다. 쓰기 인자를 비워 두면 순수 읽기가 된다
writebool쓰기 전용IndexGroup / IndexOffset 으로 데이터를 쓴다
send_commandbytes or None읽기/쓰기임의의 ADS 명령을 보내고 응답 데이터를 가져온다
알림add_notificationint or None쓰기 전용ADS 데이터 알림을 등록하고 알림 핸들을 돌려준다
del_notificationbool쓰기 전용핸들로 알림을 지운다
라우팅 구성set_configbool쓰기 전용AoE 라우팅(대상 / 출발 NetID 와 포트)을 지정한다
get_configdict or None읽기 전용현재 AoE 라우팅 구성을 읽는다
프로토콜 간 게이트웨이read_coe_via_aoe / write_coe_via_aoebytes or bool읽기/쓰기AoE 라우팅으로 CoE 객체를 읽고 쓴다
read_soe_via_aoe / write_soe_via_aoebytes or bool읽기/쓰기AoE 라우팅으로 SoE IDN 을 읽고 쓴다
initialize_slave_net_idbool쓰기 전용6바이트 AMS Net ID 를 슬레이브 ADS 라우팅 표에 쓴다
데이터 구독AoESubscriptionManager.subscribestr or None읽기/쓰기데이터 변화를 구독하고 구독 ID 를 돌려준다. slave.aoe 자체에는 구독 메서드가 없다
AoESubscriptionManager.unsubscribebool쓰기 전용구독 ID 로 구독을 취소한다
AoESubscriptionManager.unsubscribe_allint쓰기 전용모든 구독을 취소하고 성공적으로 취소한 수를 돌려준다
비동기read_async / write_async / read_write_asyncbytes or bool읽기/쓰기이벤트 루프를 차단하지 않는 모듈 수준 asyncio 래퍼
subscribe_async / unsubscribe_asyncstr or None / bool읽기/쓰기구독 관리의 비동기 버전

속성​

분류속성타입읽기/쓰기설명
기능is_supportedbool or None읽기 전용True = 메일박스 프로토콜 비트의 긍정적 증거. None = 미상. 이 경로는 False 를 절대 내지 않는다

장치 정보​

read_device_info()​

def read_device_info(self) -> Optional[dict]

ADS 장치 정보를 읽는다.

반환:

  • dict | None — 장치 정보 딕셔너리. 실패하면 None. 키는 major / minor / build 이며 모두 정수다. 현재 버전은 장치 이름 ** 을 **돌려주지 않으므로name info['name'] 을 읽지 않는다
{
'major': int, # 메이저 버전 번호
'minor': int, # 마이너 버전 번호
'build': int, # 빌드 번호
}

예제:

info = slave.aoe.read_device_info()
if info is not None:
print(f"版本: v{info['major']}.{info['minor']}.{info['build']}") # 버전: v{info['major']}.{info['minor']}.{info['build']}

read_state()​

def read_state(self) -> Optional[Tuple[int, int]]

ADS 상태를 읽어 (ads_state, device_state) 튜플을 돌려준다. 실패하면 None. ads_state 는 정수 상태 코드(전용 열거형 클래스는 없다)이며 모듈 수준 함수 get_ads_state_description() 으로 읽을 수 있는 문자열로 바꿀 수 있다.

ADS 상태 코드 (정수):

ads_state 는 아래 값을 갖는 원시 정수다(SDK 는 get_ads_state_description 매핑을 제공한다):

  • 0 — invalid
  • 1 — idle
  • 2 — reset
  • 3 — initialization
  • 4 — start
  • 5 — run
  • 6 — stop
  • 7 — 구성 저장
  • 8 — 구성 로드
  • 9 — shutdown
  • 10 — suspend
  • 11 — reconfiguration
  • 15 — error

예제:

result = slave.aoe.read_state()
if result is not None:
ads_state, device_state = result
print(f"ADS 状态: {ads_state}, 设备状态: {device_state}") # ADS 상태: {ads_state}, 장치 상태: {device_state}

write_control()​

def write_control(self, ads_state: int, device_state: int,
data: bytes = b'') -> bool

제어 명령을 쓴다(장치 상태를 전환한다).

get_ads_state_description()​

from darra_ethercat.slave.aoe import get_ads_state_description

def get_ads_state_description(ads_state: int) -> str

ADS 상태 이름을 얻는다(모듈 수준 함수이며 AoE 메서드가 아니다).

예제:

from darra_ethercat.slave.aoe import get_ads_state_description

result = slave.aoe.read_state()
if result:
ads_state, device_state = result
name = get_ads_state_description(ads_state)
print(f"ADS 状态: {name} ({ads_state})") # ADS 상태: {name} ({ads_state})

데이터 읽기/쓰기​

ADS 읽기는 read_write 를 통과한다

AoE 에는 별도의 read() 메서드가 없다. 순수 ADS 읽기에는 read_write(index_group, index_offset, read_length) 을 호출하고 write_data 를 비워 두고, 순수 쓰기에는 write() 를 쓴다.

read_write() — 순수 읽기 사용​

# 순수 읽기: write_data는 비워 둔다
data = slave.aoe.read_write(0x4020, 0, 4)
if data is not None and len(data) >= 4:
import struct
value = struct.unpack('<I', data)[0]
print(f"状态值: 0x{value:08X}") # 상태 값: 0x{value:08X}

write()​

def write(self, index_group: int, index_offset: int,
data: bytes) -> bool

ADS 데이터를 쓴다.

매개변수:

  • index_group (int) — 인덱스 그룹
  • index_offset (int) — 인덱스 오프셋
  • data (bytes) — 쓸 데이터

반환:

  • bool — 성공하면 True

예제:

import struct
slave.aoe.write(0x4020, 0, struct.pack('<I', 0x0006))

read_write()​

def read_write(self, index_group: int, index_offset: int,
read_length: int, write_data: bytes = b'') -> Optional[bytes]

ADS 읽기/쓰기 연산(데이터를 동시에 읽고 쓴다).

예제:

# 데이터 읽기
data = slave.aoe.read_write(0x4020, 0, 4)
if data is not None and len(data) >= 4:
import struct
value = struct.unpack('<I', data)[0]
print(f"值: 0x{value:08X}") # 값: 0x{value:08X}

# 데이터 쓰기 (read_length=0은 쓰기 전용)
slave.aoe.read_write(0x4020, 0, 0, struct.pack('<I', 0x0006))

send_command()​

def send_command(self, target_port: int, command_id: int,
command_data: bytes = b'') -> Optional[bytes]

AoE 명령을 보내고 응답을 받는다.

매개변수:

  • target_port (int) — 대상 AMS 포트
  • command_id (int) — ADS 명령 ID
  • command_data (bytes) — 명령 데이터

반환:

  • bytes | None — 응답 데이터. 실패하면 None

AoEResultCode 열거형​

ADS / AoE 연산의 표준 결과 오류 코드(ETG.1020 Table 16). 값은 ETG.1020 Table 16 정의를 따른다. 상위 바이트는 보통 오류 클래스를 나타낸다(0x0700 ADS 장치, 0x0740 ADS 클라이언트).

from darra_ethercat.slave.aoe import AoEResultCode
이름값설명
NO_ERROR0x0000오류 없음
INTERNAL_ERROR0x0001내부 오류
NO_REALTIME0x0002실시간 컨텍스트 없음
ALLOCATION_LOCKED_MEMORY_ERROR0x0003잠긴 메모리 할당 실패
INSERT_MAILBOX_ERROR0x0004메일박스 가득 참
WRONG_RECEIVE_HMSG0x0005명령 ID 불일치
TARGET_PORT_NOT_FOUND0x0006대상 AMS 포트 없음
TARGET_MACHINE_NOT_FOUND0x0007대상 장치 없음
UNKNOWN_COMMAND_ID0x0008알 수 없는 명령 ID
BAD_TASK_ID0x0009잘못된 작업 ID
NO_IO0x000AIO 채널 없음
UNKNOWN_AMS_COMMAND0x000B알 수 없는 AMS 명령
WIN32_ERROR0x000CWin32 오류
PORT_NOT_CONNECTED0x000D포트 미연결
INVALID_AMS_LENGTH0x000E잘못된 AMS 길이
INVALID_AMS_NET_ID0x000F잘못된 AMS Net ID
AMS_SYNC_TIMEOUT0x0015AMS 동기화 타임아웃
HOST_UNREACHABLE0x001B호스트 도달 불가
WSA_SERVICE_NOT_STARTED0x274D장치 서비스 시작 안 됨
DEVICE_INVALID_GROUP0x0700장치의 잘못된 IndexGroup
DEVICE_INVALID_OFFSET0x0701장치의 잘못된 IndexOffset
DEVICE_INVALID_ACCESS0x0702장치의 잘못된 접근
DEVICE_INVALID_SIZE0x0703장치의 잘못된 데이터 크기
DEVICE_NOT_READY0x0705장치 미준비
DEVICE_BUSY0x0706장치 바쁨
DEVICE_NOT_FOUND0x0708장치 없음
DEVICE_INVALID_STATE0x070C잘못된 장치 상태
DEVICE_TIMEOUT0x0712장치 타임아웃
DEVICE_ACCESS_DENIED0x071C장치 접근 거부
CLIENT_INVALID_PARAM0x0741잘못된 클라이언트 매개변수
CLIENT_INVOKE_TIMEOUT0x0744클라이언트 호출 타임아웃
CLIENT_PORT_NOT_OPEN0x0745클라이언트 포트 미개방

표에는 흔한 항목만 실었다.

예제:

from darra_ethercat.slave.aoe import AoEResultCode

result = slave.aoe.read_state()
if result is None:
# read_device_info / read_write / write 등이 None을 반환하면
# AoEResultCode와 대조해 실패의 의미를 파악한다
print(f"AoE 失败, 错误码可能为 {AoEResultCode.DEVICE_NOT_READY.name}") # AoE 실패, 오류 코드는 다음일 수 있음 {AoEResultCode.DEVICE_NOT_READY.name}

AoE 알림​

add_notification()​

def add_notification(self, index_group: int, index_offset: int,
length: int, trans_mode: int = 0,
max_delay: int = 0, cycle_time: int = 0) -> Optional[int]

ADS 알림을 추가하고 알림 핸들을 돌려준다.

매개변수:

  • index_group (int) — 인덱스 그룹
  • index_offset (int) — 인덱스 오프셋
  • length (int) — 데이터 길이
  • trans_mode (int) — 전송 모드(0-4, AoETransmissionMode 참조)
  • max_delay (int) — 최대 지연(100 ns 단위)
  • cycle_time (int) — 사이클 시간(100 ns 단위)

반환:

  • int | None — 알림 핸들. 실패하면 None
단위 변환

AoESubscriptionManager.subscribe 의 max_delay_ms / cycle_time_ms 은 밀리초다. 내부적으로 10000 을 곱해 이 인터페이스의 100 ns 단위로 바꾼다.

del_notification()​

def del_notification(self, handle: int) -> bool

ADS 알림을 지운다.

반환:

  • bool — 성공하면 True
고급 구독 관리

SDK 는 구독 관리 기능을 감싸는 AoESubscriptionManager 클래스를 제공한다.

from darra_ethercat import AoESubscriptionManager

mgr = AoESubscriptionManager(slave.aoe)
sub_id = mgr.subscribe(0x4020, 0, 4, callback=on_data_changed)
mgr.unsubscribe(sub_id)
mgr.unsubscribe_all()

라우팅 구성​

set_config()​

def set_config(self, target_net_id: bytes, target_port: int,
source_net_id: bytes, source_port: int) -> bool

AoE 라우팅 구성을 지정한다. NetID 는 6바이트다.

get_config()​

def get_config(self) -> Optional[dict]

AoE 라우팅 구성을 얻어 딕셔너리를 돌려준다.

{
'target_net_id': bytes, # 대상 NetID (6바이트)
'target_port': int, # 대상 포트
'source_net_id': bytes, # 소스 NetID (6바이트)
'source_port': int, # 소스 포트
}

프로토콜 간 게이트웨이​

AoE 라우팅으로 다른 메일박스 프로토콜에 접근한다(ETG.1020). CoE 와 SoE 프로토콜의 투명 전달을 지원한다.

read_coe_via_aoe()​

def read_coe_via_aoe(self, index: int, subindex: int,
read_length: int) -> Optional[bytes]

AoE 라우팅으로 CoE 객체를 읽는다(IndexGroup=0xF302, IndexOffset=(index << 16) | (subindex & 0xFF)).

매개변수:

  • index (int) — CoE 객체 인덱스
  • subindex (int) — CoE 서브인덱스
  • read_length (int) — 기대 읽기 길이

반환:

  • bytes | None — 읽은 데이터. 실패하면 None

write_coe_via_aoe()​

def write_coe_via_aoe(self, index: int, subindex: int,
data: bytes) -> bool

AoE 라우팅으로 CoE 객체를 쓴다(IndexGroup=0xF302).

read_soe_via_aoe()​

def read_soe_via_aoe(self, idn: int, read_length: int) -> Optional[bytes]

AoE 라우팅으로 SoE IDN 을 읽는다(IndexGroup=0xF420, IndexOffset=IDN 번호).

write_soe_via_aoe()​

def write_soe_via_aoe(self, idn: int, data: bytes) -> bool

AoE 라우팅으로 SoE IDN 을 쓴다(IndexGroup=0xF420).

예제:

# AoE로 CoE 객체 0x6041:0 (상태 워드) 읽기
data = slave.aoe.read_coe_via_aoe(0x6041, 0, 2)
if data is not None:
import struct
status_word = struct.unpack('<H', data)[0]
print(f"状态字: 0x{status_word:04X}") # 상태 워드: 0x{status_word:04X}

# AoE로 CoE 객체 0x6040:0 (제어 워드) 쓰기
slave.aoe.write_coe_via_aoe(0x6040, 0, struct.pack('<H', 0x000F))

# AoE로 SoE IDN 읽기
idn_data = slave.aoe.read_soe_via_aoe(32, 4)

initialize_slave_net_id()​

def initialize_slave_net_id(self, net_id: bytes) -> bool

슬레이브 AoE Net ID 를 초기화한다(ETG.1020 §9.4). INIT→PreOp 상태 전이 중에 호출한다. Net ID 를 슬레이브 ADS 라우팅 표(IndexGroup=1, IndexOffset=3)에 쓴다.

매개변수:

  • net_id (bytes) — 6바이트 AMS Net ID

반환:

  • bool — 성공하면 True

예외:

  • ValueError — Net ID 가 6바이트가 아님

예제:

slave.aoe.initialize_slave_net_id(bytes([5, 80, 187, 177, 1, 1]))

고급 구독 관리​

AoESubscriptionManager 클래스는 전체 구독 관리 기능을 감싸고 ID 로 구독을 관리한다. slave.aoe 자체에는 구독 메서드가 없으므로 매니저를 직접 만들어야 한다.

from darra_ethercat import AoESubscriptionManager

mgr = AoESubscriptionManager(slave.aoe)

subscribe() / unsubscribe() / unsubscribe_all()​

def subscribe(self, index_group: int, index_offset: int, length: int,
trans_mode: int = AoETransmissionMode.ON_CHANGE,
max_delay_ms: int = 0, cycle_time_ms: int = 100,
callback: Optional[Callable[[bytes], None]] = None
) -> Optional[str]

def unsubscribe(self, subscription_id: str) -> bool
def unsubscribe_by_handle(self, handle: int) -> bool
def unsubscribe_all(self) -> int

subscribe() 는 데이터 변화 알림을 등록하고 성공하면 구독 ID(UUID 문자열)를, 실패하면 None 을 돌려준다. callback 시그니처는 callback(data: bytes) 이며 None 이 될 수 있다. unsubscribe() 는 구독 ID 로 취소하며(권장), unsubscribe_by_handle() 은 알림 핸들로 취소한다(구 용법과의 호환용). 둘 다 등록을 제거하고 슬레이브에 알리며, 핸들 / ID 가 없으면 False 를 돌려준다. unsubscribe_all() 은 모든 구독을 취소하고 성공적으로 취소한 수를 돌려준다.

AoETransmissionMode​

class AoETransmissionMode(IntEnum):
NO_TRANSMISSION = 0 # 알림 없음
CYCLIC = 1 # 주기 알림 - 지정된 주기마다 전송한다
ON_CHANGE = 2 # 변화 알림 - 데이터가 변하면 전송한다
CYCLIC_IN_DEVICE = 3 # 장치에서 생성되는 주기적 알림
ON_CHANGE_IN_DEVICE = 4 # 장치에서 생성되는 변경 알림

AoESubscription​

@dataclass
class AoESubscription:
handle: int # 알림 핸들
slave_index: int # 슬레이브 번호
index_group: int # 인덱스 그룹
index_offset: int # 인덱스 오프셋
length: int # 데이터 길이
callback: Optional[Callable] # 콜백 함수
subscription_id: str # 고유 구독 ID (UUID)
trans_mode: int # 전송 모드
is_active: bool # 구독 활성 여부
tag: object # 임의 태그 (기본 None)

예제:

from darra_ethercat import AoESubscriptionManager
from darra_ethercat.slave import AoETransmissionMode

mgr = AoESubscriptionManager(slave.aoe)

# 데이터 변경 알림 구독
sub_id = mgr.subscribe(
index_group=0x4020, index_offset=0, length=4,
trans_mode=AoETransmissionMode.ON_CHANGE,
cycle_time_ms=100,
callback=lambda data: print(f"数据变化: {data.hex()}") # 데이터 변화: {data.hex()}
)

# 활성 구독 목록 가져오기
active = mgr.get_active_subscriptions()
print(f"活跃订阅数: {mgr.active_count}") # 활성 구독 수: {mgr.active_count}

# ID로 구독 취소
mgr.unsubscribe(sub_id)

# 모든 구독 취소
mgr.unsubscribe_all()

구독 매니저 속성​

분류속성타입읽기/쓰기설명
구독 관리active_countint읽기 전용현재 활성 구독 수
all_handleslist[int]읽기 전용모든 활성 알림 핸들 목록

핸들 / ID 로 구독 조회​

def get_subscription(self, handle: int) -> Optional[AoESubscription]
def get_subscription_by_id(self, subscription_id: str) -> Optional[AoESubscription]
def unsubscribe_by_handle(self, handle: int) -> bool
def get_active_subscriptions(self) -> List[AoESubscription]

get_subscription() 은 구형 핸들 방식 조회를 유지한다. 새 코드에는 get_subscription_by_id() 를 권장한다(UUID 는 이미 지워진 핸들과 충돌하지 않는다). get_active_subscriptions() 는 현재 활성 구독 목록의 사본을 돌려준다.

sub = mgr.get_subscription_by_id(sub_id)
if sub and sub.is_active:
print(f"订阅 slave={sub.slave_index} group=0x{sub.index_group:08X}") # 구독 slave={sub.slave_index} group=0x{sub.index_group:08X}

비동기 구독과 읽기/쓰기 (asyncio)​

AoE 메일박스 왕복은 보통 10-50 ms 가 걸리며, 동기 호출은 이벤트 루프를 차단한다. 비동기 버전은 전용 스레드 풀에서 돌아가 이벤트 루프를 차단하지 않는다.

subscribe_async() / unsubscribe_async() / unsubscribe_all_async()​

async def subscribe_async(self, index_group: int, index_offset: int,
length: int,
trans_mode: int = AoETransmissionMode.ON_CHANGE,
max_delay_ms: int = 0, cycle_time_ms: int = 100,
callback: Optional[Callable[[bytes], None]] = None,
timeout_ms: Optional[int] = None) -> Optional[str]

async def unsubscribe_async(self, subscription_id: str,
timeout_ms: Optional[int] = None) -> bool

async def unsubscribe_all_async(self,
timeout_ms: Optional[int] = None) -> int

subscribe / unsubscribe 의 비동기 버전. timeout_ms 가 지나면 asyncio.TimeoutError 를 던지지만, 백그라운드 스레드는 그 동기 호출 하나를 끝까지 실행한다.

import asyncio
from darra_ethercat import AoESubscriptionManager
from darra_ethercat.slave import AoETransmissionMode

async def main():
mgr = AoESubscriptionManager(slave.aoe)
sub_id = await mgr.subscribe_async(
index_group=0x4020, index_offset=0, length=4,
trans_mode=AoETransmissionMode.ON_CHANGE,
callback=lambda data: print(f"通知: {data.hex()}"), # 알림: {data.hex()}
timeout_ms=2000,
)
if sub_id is None:
print("订阅失败") # 구독 실패
return

await asyncio.sleep(10)
await mgr.unsubscribe_async(sub_id)

asyncio.run(main())

read_async() / write_async() / read_write_async()​

from darra_ethercat.slave.aoe import read_async, write_async, read_write_async

async def main():
data = await read_async(slave.aoe, 0x4020, 0, 4, timeout_ms=500)
if data is not None:
print(f"值: {data.hex()}") # 값: {data.hex()}
await write_async(slave.aoe, 0x4020, 0, b'\x06\x00\x00\x00',
timeout_ms=500)

read_write_async() 는 기저의 read_write 를 먼저 호출한다(한 메일박스 왕복에서 읽기와 쓰기). 그게 안 되면 write_async 다음에 read_async 로 되돌아간다.

shutdown_aoe_async_executor()​

from darra_ethercat.slave.aoe import shutdown_aoe_async_executor

shutdown_aoe_async_executor(wait=True)

프로세스가 끝나기 전에 AoE 프로토콜 전용 스레드 풀을 종료한다. 제출된 작업이 끝날 때까지 기다릴지(wait=True) 말지 정할 수 있다.

전체 예제​

데이터 읽기/쓰기​

# is_supported는 True 또는 None만 된다; None = 알 수 없음, 시도해 볼 만하므로 "미지원"으로 보면 안 된다
if slave.aoe.is_supported is not False:
import struct

# 장치 정보 (현재 버전에는 장치 이름이 없다)
info = slave.aoe.read_device_info()
if info is not None:
print(f"版本: v{info['major']}.{info['minor']}.{info['build']}") # 버전: v{info['major']}.{info['minor']}.{info['build']}

# 상태
from darra_ethercat.slave.aoe import get_ads_state_description
result = slave.aoe.read_state()
if result:
ads_state, device_state = result
name = get_ads_state_description(ads_state)
print(f"ADS 状态: {name} ({ads_state}), 设备状态: {device_state}") # ADS 상태: {name} ({ads_state}), 장치 상태: {device_state}

# 데이터 읽기 (순수 읽기는 read_write로 하며 write_data는 비워 둔다)
data = slave.aoe.read_write(0x4020, 0, 4)
if data is not None and len(data) >= 4:
print(f"值: 0x{struct.unpack('<I', data)[0]:08X}") # 값: 0x{struct.unpack('<I', data)[0]:08X}

# 데이터 쓰기
slave.aoe.write(0x4020, 0, struct.pack('<I', 0x0006))

# 장치 상태 전환
slave.aoe.write_control(5, 0) # Run 상태로 전환

데이터 구독​

from darra_ethercat import AoESubscriptionManager
from darra_ethercat.slave import AoETransmissionMode

if slave.aoe.is_supported is not False:
mgr = AoESubscriptionManager(slave.aoe)

sub_id = mgr.subscribe(
index_group=0x4020, index_offset=0, length=4,
trans_mode=AoETransmissionMode.ON_CHANGE,
cycle_time_ms=100,
callback=lambda data: print(f"数据变化: {data.hex()}") # 데이터 변화: {data.hex()}
)

import time
time.sleep(10)
mgr.unsubscribe_all()

프로토콜 간 게이트웨이​

if slave.aoe.is_supported is not False:
import struct

# AoE로 CoE 객체 0x6041:0 (상태 워드) 읽기
data = slave.aoe.read_coe_via_aoe(0x6041, 0, 2)
if data is not None:
status_word = struct.unpack('<H', data)[0]
print(f"状态字: 0x{status_word:04X}") # 상태 워드: 0x{status_word:04X}

# AoE로 CoE 객체 0x6040:0 (제어 워드) 쓰기
slave.aoe.write_coe_via_aoe(0x6040, 0, struct.pack('<H', 0x000F))

# AoE로 SoE IDN 읽기
idn_data = slave.aoe.read_soe_via_aoe(32, 4)
if idn_data is not None:
print(f"IDN 32 值: {struct.unpack('<I', idn_data)[0]}") # IDN 32비트 값: {struct.unpack('<I', idn_data)[0]}

실패와 대응​

증상원인대응
슬레이브가 아직 도는 중인데 읽기가 None 반환ADS 가 0이 아닌 결과 코드를 돌려줌(객체 없음, 접근 거부, 장치 바쁨). 실패를 이해하려면 AoEResultCode 와 비교IndexGroup / IndexOffset 과 길이를 확인하고 읽기 길이를 줄여 재시도
오랫동안 반환 없이 호출 실패메일박스 타임아웃(슬레이브가 바쁘거나 메일박스 미준비)호출 빈도를 줄이고 슬레이브가 통신 가능한 상태에 도달했는지 확인한 뒤 재시도
모든 호출이 실패하고 is_supported 가 None슬레이브가 AoE 를 지원하지 않거나, 메일박스 프로토콜 비트를 읽을 수 없음(None 은 미상이라는 뜻뿐)같은 객체를 CoE / SoE 로 읽는다. 재시도로 해결되지 않는다