设为首页
收藏本站
开启辅助访问
切换到窄版
登录
立即注册
中问网首页
我的收藏
站长博客
搜索
搜索
本版
帖子
用户
第一问答网
»
论坛
›
中问网
›
问答
›
哪位兄弟能不能帮我把这个函数转成delphi,多谢~ ...
1
2
/ 2 页
下一页
返回列表
发新帖
哪位兄弟能不能帮我把这个函数转成delphi,多谢~
[复制链接]
11
|
10
|
2021-1-27 07:04:30
|
显示全部楼层
|
阅读模式
u16CRC16(void*Buff_addr,u16len)
{
u8*dataPtr=(u8*)Buff_addr;
u16index=0;
u16crc=0;
while(len--)
{
crc=(u8)(crc>>8)|(crc>4;
crc^=(crc -->
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
献上妹子一张~
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
functionCRC16(varBuff_addr;len:Word):Word;
var
index,crc:Word;
dataPtr:PChar;
begin
dataPtr:=PChar(@Buff_addr);
index:=0;
crc:=0;
while(len>0)do
begin
crc:=Byte((crcshr8)or(crcshl8));
crc:=crcxorByte(dataPtr[index]);
Inc(index);
crc:=crcxorByte((crcand$ff)shr4);
crc:=crcxor(crcshl8)shl4;
crc:=crcxor((crcand$ff)shl4)shl1;
end;
Result:=crc;
end;
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
妹子丑,还带游泳圈。
你得给出u16,u8的定义,这两个显然是自定义类型或某类型的typedef
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
要修改下,如下:
functionCRC16(varBuff_addr;len:Word):Word;
var
index,crc:Word;
dataPtr:PChar;
begin
dataPtr:=PChar(@Buff_addr);
index:=0;
crc:=0;
while(len>0)do
begin
crc:=Byte(crcshr8)or(crcshl8);
crc:=crcxorByte(dataPtr[index]);
Inc(index);
crc:=crcxorByte(crcand$ff)shr4;
crc:=crcxor(crcshl8)shl4;
crc:=crcxor((crcand$ff)shl4)shl1;
end;
Result:=crc;
end;
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
多谢,我试下!
u16就是双字节unsignedshort;
u8unsignedchar;
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
还有点问题
原先的函数定义是
functionCRC16_Modbus(pByteInfo:PByte;iLength:integer);stdcall;external'CRC16Modbus.dll';
现在改成
functionCRC16(varBuff_addr;len:Word):Word;
编译报错,能不能兼容原来的定义?
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
引用6楼camdw的回复:
还有点问题
原先的函数定义是
functionCRC16_Modbus(pByteInfo:PByte;iLength:integer);stdcall;external'CRC16Modbus.dll';
现在改成
functionCRC16(varBuff_addr;len:Word):Word;
编译报错,能不能兼容原来的定义?
可以
functionCRC16_Modbus(pByteInfo:PByte;iLength:integer);stdcall;external'CRC16Modbus.dll';
或者
functionCRC16_Modbus(pByteInfo:PChar;iLength:integer);stdcall;external'CRC16Modbus.dll';
functionCRC16(pByteInfo:PChar;iLength:integer):Word;
回复
使用道具
举报
千问
|
2021-1-27 07:04:30
|
显示全部楼层
原来是这样调用的
var
Data:array[0..2048]ofByte;
iCount,iResult:Integer;
iResult:=CRC16_Modbus(@Data,iCount);
现在我想直接替换成
iResult:=CRC16(@Data,iCount);这种方式~基本不会delphi!
回复
使用道具
举报
1
2
/ 2 页
下一页
返回列表
发新帖
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
本版积分规则
发表回复
回帖后跳转到最后一页
千问
主题
0
回帖
4882万
积分
论坛元老
论坛元老, 积分 48824836, 距离下一级还需 -38824837 积分
论坛元老, 积分 48824836, 距离下一级还需 -38824837 积分
积分
48824836
加好友
发消息
回复楼主
返回列表
问答
热门排行