本文整理汇总了Python中Packet.Packet.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Packet.__init__方法的具体用法?Python Packet.__init__怎么用?Python Packet.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet.Packet
的用法示例。
在下文中一共展示了Packet.__init__方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import __init__ [as 别名]
def __init__(self, byteCodeId=None, comResp=None, parameter=None):
if comResp != None:
#super().__init__(b"\x55", b"\xAA", byteCodeId)
Packet.__init__(self, b"\x55", b"\xAA", byteCodeId)
self.__parameter = parameter
self.__comResp = comResp
else:
length = len(byteCodeId)
if length == 12:
if byteCodeId[0]== b"\x55" and byteCodeId[1]== b"\xAA":
Packet.__init__(self, byteCodeId[0], byteCodeId[1], byteCodeId[2:4])
self.__parameter = byteCodeId[4:8]
self.__comResp = byteCodeId[8:10]
#print("com1:", self.__commandCode0)
#print("com2:", self.__commandCode1)
#print("deviceId:", self.__deviceId)
#print("parameter:", self.__parameter)
#print("comResp:", self.__comResp)
#print("check:", receivedByteArray[10:12])
#print("checkCalc:",self.getCheckSum())
if self.getCheckSum(byteCodeId[0:length-2]) != byteCodeId[length-2:length]:
raise SensorException(CHECKSUM_ERROR, COMMAND_PACK_ERROR)
else:
raise SensorException(PACKET_HEADER_ERROR, COMMAND_PACK_ERROR)
else:
raise SensorException(LENGTH_ERROR, COMMAND_PACK_ERROR)
示例2: __init__
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import __init__ [as 别名]
def __init__(self, byteCodeId=None, data=None):
if data != None:
Packet.__init__(self, b"\x5A", b"\xA5", byteCodeId)
self.__data = data
else:
length = len(byteCodeId)
if length >= 8:
if byteCodeId[0]== b"\x5A" and byteCodeId[1]== b"\xA5":
Packet.__init__(self, byteCodeId[0], byteCodeId[1], byteCodeId[2:4])
self.__data = byteCodeId[4:length-2]
#print("com1:", self.__commandCode0)
#print("com2:", self.__commandCode1)
#print("Id:", self.__deviceId)
#print("rawData:", self.__data)
#checkRec = bytearray(byteCode)[length-2] + bytearray(byteCode)[length-1]
#print("checkRec:", checkRec)
#print("checkRec:", receivedByteArray[length-2:length])
#checkCalc = bytearray(super.getCheckSum())[0]+ bytearray(super.getCheckSum())[1]
#print("checkCalc:", checkCalc)
#print("checkCalc:", self.getCheckSum())
#if self.getCheckSum() != receivedByteArray[length-1:length]:
#if checkRec != checkCalc:
if self.getCheckSum(byteCodeId[0:length-2]) != byteCodeId[length-2:length]:
raise SensorException(CHECKSUM_ERROR, DATA_PACK_ERROR)
else:
raise SensorException(PACKET_HEADER_ERROR,DATA_PACK_ERROR)
else:
raise SensorException(LENGTH_ERROR, DATA_PACK_ERROR)
示例3: __init__
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import __init__ [as 别名]
def __init__(self,main, data):
Packet.__init__(self, 06,data)
self.main = main
示例4: __init__
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import __init__ [as 别名]
def __init__(self, *arguments, **kw):
if len(arguments) == 0:
Packet.__init__(self)
else:
Packet.__init__(self, self.VERSION, arguments[0], self.__class__._id, 0, *arguments[1:], **kw)
示例5: __init__
# 需要导入模块: from Packet import Packet [as 别名]
# 或者: from Packet.Packet import __init__ [as 别名]
def __init__(self, main, data):
Packet.__init__(self, 11, data)
self.main = main
self.data = data