1 Star 0 Fork 10

why-mao/DreamSerial

forked from Neeil/DreamSerial 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DsPackage.py 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Wang, Neil 提交于 2015-08-25 16:28 . Init Release
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 25 11:33:15 2015
@author: fg086897
"""
__author__ = 'Neil Wang'
import ccitt_crc
class DsPackage(object):
access = 'reg'
def __init__(self, rw, access, address, length):
self.rw = rw
self.access = access
self.address = address
self.length = length
def generatePackage(self):
package = [0 for n in range(8)]
package[0] = 0xAA
if self.rw.lower() == 'r' :
package[1] &= 0x3F
elif self.rw.lower() == 'w':
package[1] |= 0x80
package.append([0 for n in range(self.length)])
else :
print('Please input access as "r" or "w"')
pass
if self.access == 'reg':
package[1] += 0x01
elif self.access == 'data':
package[1] += 0x03
else :
print('Please input access as "reg" or "data"')
pass
package[2] = self.address & 0xff
package[3] = (self.address >> 8) & 0xff
package[4] = self.length & 0xff
package[5] = (self.length >> 8 ) & 0xff
crc = ccitt_crc.ccitt_crc();
crcValue = crc.ccitt_crc_calc(package[1:-2])
package[-1] = (crcValue >> 8 ) & 0xff
package[-2] = crcValue & 0xff
return package
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/maoyikun2015/DreamSerial.git
git@gitee.com:maoyikun2015/DreamSerial.git
maoyikun2015
DreamSerial
DreamSerial
master

搜索帮助