package com.zy.acs.conveyor.core.constant;
|
|
|
/**
|
* 站点状态字段枚举(对应 §2.1)
|
*/
|
public enum StationStatusField {
|
TASK_NUMBER("DB100", 0, 4), // 任务号,偏移0,4字节
|
FINAL_TARGET("DB100", 4, 2), // 最终目标站,偏移4,2字节
|
STATUS_WORD("DB100", 6, 2), // 状态字,偏移6,2字节
|
TASK_WRITABLE("DB100", 8, 2); // 任务可写区,偏移8,2字节
|
|
private final String addressPattern;
|
private final int offset;
|
private final int byteLength;
|
|
StationStatusField(String addressPattern, int offset, int byteLength) {
|
this.addressPattern = addressPattern;
|
this.offset = offset;
|
this.byteLength = byteLength;
|
}
|
|
/**
|
* 根据 DB 块编号和站点偏移生成具体地址
|
*
|
* @param dbBlock DB块编号
|
* @param stationBaseOffset 站点基址偏移(站点号*站点长度)
|
* @return PLC4X 地址字符串,如 "DB100.DBD0"
|
*/
|
public String buildAddress(int dbBlock, int stationBaseOffset) {
|
int finalOffset = stationBaseOffset + offset;
|
return String.format(addressPattern, dbBlock, finalOffset);
|
}
|
|
public String getAddressPattern() {
|
return addressPattern;
|
}
|
|
public int getOffset() {
|
return offset;
|
}
|
|
public int getByteLength() {
|
return byteLength;
|
}
|
}
|