哪位兄弟能不能帮我把这个函数转成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!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行