BxCmdLock.py 973 B

1234567891011121314151617181920212223242526272829303132333435
  1. from .BxCmd import baseBxCmd
  2. from .BxCmdCode import CMD_LOCK_UNLOCK
  3. class CmdLock(baseBxCmd):
  4. def __init__(self, flag, name):
  5. super().__init__(CMD_LOCK_UNLOCK.group, CMD_LOCK_UNLOCK.code)
  6. self.StoreMode = 0
  7. self.LockFlag = flag
  8. self.ProgramFileName = name
  9. def SetStoreMode(self, storeMode):
  10. self.StoreMode = storeMode
  11. def Build(self):
  12. result = bytearray()
  13. # 写入命令组
  14. result.append(self.Group())
  15. # 写入命令
  16. result.append(self.Cmd())
  17. # 写入响应标志
  18. result.append(0x01)
  19. # 写入保留值
  20. result.extend([0x00, 0x00])
  21. # 写入存储模式
  22. result.append(self.StoreMode)
  23. # 写入锁定标志
  24. result.append(self.LockFlag)
  25. # 写入程序文件名
  26. result.extend(self.ProgramFileName.encode('ascii'))
  27. return bytes(result)
  28. def NewCmdLock(flag, name):
  29. return CmdLock(flag, name)