feat: test_snap7.py add --prev-req flag for PrevResultReq
This commit is contained in:
1 parent
a149215819
commit
6eada3fc29
1 file changed
+12
-3
+12
-3
@@ -16,6 +16,12 @@ PLC 测试工具 — 读写 S7 DB 块
|
||||
|
||||
# 清 ControlWord (写 0)
|
||||
python test_snap7.py --station 0 --value 0
|
||||
|
||||
# 工序 2 的 PrevResultReq 置位
|
||||
python test_snap7.py --station 2 --prev-req
|
||||
|
||||
# DataReady + PrevResultReq 同时置位
|
||||
python test_snap7.py --station 2 --dataready --prev-req
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -40,7 +46,8 @@ def parse_args():
|
||||
p.add_argument('--measured', type=float, help='写入 MeasuredValue (REAL, 偏移+12)')
|
||||
p.add_argument('--dataready', action='store_true', help='设置 ControlWord Bit0=1')
|
||||
p.add_argument('--qualified', action='store_true', help='设置 ControlWord Bit1=1')
|
||||
p.add_argument('--value', type=int, help='直接写入 ControlWord WORD 值 (覆盖 --dataready/--qualified)')
|
||||
p.add_argument('--prev-req', action='store_true', help='设置 ControlWord Bit2=1 (PrevResultReq)')
|
||||
p.add_argument('--value', type=int, help='直接写入 ControlWord WORD 值 (覆盖 --dataready/--qualified/--prev-req)')
|
||||
return p.parse_args()
|
||||
|
||||
|
||||
@@ -117,14 +124,16 @@ def main():
|
||||
write_word(plc, args.db, base + 16, args.value)
|
||||
print(f"[写] ControlWord@{base+16} = 0x{args.value:04X}")
|
||||
any_write = True
|
||||
elif args.dataready or args.qualified:
|
||||
elif args.dataready or args.qualified or args.prev_req:
|
||||
cw = read_fields(plc, args.db, base)['ControlWord']
|
||||
if args.dataready:
|
||||
cw |= 0x0001
|
||||
if args.qualified:
|
||||
cw |= 0x0002
|
||||
if args.prev_req:
|
||||
cw |= 0x0004
|
||||
write_word(plc, args.db, base + 16, cw)
|
||||
print(f"[写] ControlWord@{base+16} = 0x{cw:04X} (DataReady={args.dataready} 合格={args.qualified})")
|
||||
print(f"[写] ControlWord@{base+16} = 0x{cw:04X} (DataReady={args.dataready} 合格={args.qualified} PrevReq={args.prev_req})")
|
||||
any_write = True
|
||||
|
||||
if any_write:
|
||||
|
||||
Reference in new issue
Block a user