那位仁兄帮忙将下面三个BCB的函数转换成DELPHI的,不胜感激!void fill_head(BYTE *da, char id, char , int len)
{
da[0] = 0x1b;
da[1] = '$';
da[2] = 'S';
da[3] = 'Z';
da[4] = 'L';
da[5] = 'G';
da[6] = id;
da[7] = '1';
da[8] = 0x00;
da[9] = len;
da[10] = ;
}int get_sum(BYTE *da, int len)
{
int sum = 0;
for(int i=0; i<len+4; i++) sum = sum + da[YINDAO_LEN +i];
da[YINDAO_LEN + len + 4 + 0] = (sum>>8) & 0xff;
da[YINDAO_LEN + len + 4 + 1] = sum & 0xff;
int send_len = YINDAO_LEN + 4 + da[9] + 2;
return send_len;
}
unsigned int HEXtoBCD8(unsigned char hex_data)
{
unsigned int bcd_data;
unsigned char temp;
temp=hex_data%100;
bcd_data=((unsigned int)hex_data)/100<<8;
bcd_data=bcd_data|temp/10<<4;
bcd_data=bcd_data|temp%10;
return bcd_data;
}
void show_result(BYTE *inbuff, unsigned char id, char )
{
int sum = inbuff[3] + inbuff[4] + inbuff[5]+ inbuff[6];
if(
inbuff[0]== 'A' &&
inbuff[1]== 'C' &&
inbuff[2]== 'K' &&
inbuff[3]== id &&
inbuff[4]== '1' && //
inbuff[5]== &&
inbuff[6]== OK &&
sum == ((inbuff[7]<<8) | inbuff[8])
)
ShowMessage("ok!");
else ShowMessage("send ng!");
}
{
da[0] = 0x1b;
da[1] = '$';
da[2] = 'S';
da[3] = 'Z';
da[4] = 'L';
da[5] = 'G';
da[6] = id;
da[7] = '1';
da[8] = 0x00;
da[9] = len;
da[10] = ;
}int get_sum(BYTE *da, int len)
{
int sum = 0;
for(int i=0; i<len+4; i++) sum = sum + da[YINDAO_LEN +i];
da[YINDAO_LEN + len + 4 + 0] = (sum>>8) & 0xff;
da[YINDAO_LEN + len + 4 + 1] = sum & 0xff;
int send_len = YINDAO_LEN + 4 + da[9] + 2;
return send_len;
}
unsigned int HEXtoBCD8(unsigned char hex_data)
{
unsigned int bcd_data;
unsigned char temp;
temp=hex_data%100;
bcd_data=((unsigned int)hex_data)/100<<8;
bcd_data=bcd_data|temp/10<<4;
bcd_data=bcd_data|temp%10;
return bcd_data;
}
void show_result(BYTE *inbuff, unsigned char id, char )
{
int sum = inbuff[3] + inbuff[4] + inbuff[5]+ inbuff[6];
if(
inbuff[0]== 'A' &&
inbuff[1]== 'C' &&
inbuff[2]== 'K' &&
inbuff[3]== id &&
inbuff[4]== '1' && //
inbuff[5]== &&
inbuff[6]== OK &&
sum == ((inbuff[7]<<8) | inbuff[8])
)
ShowMessage("ok!");
else ShowMessage("send ng!");
}
procedure fill_head(var da:array of byte;id:char; :char; len:integer);
begin
da[0] := $1b;
da[1] := byte('$');
da[2] := byte('S');
da[3] := byte('Z');
da[4] := byte('L');
da[5] := byte('G');
da[6] := byte(id);
da[7] := byte('1');
da[8] := $00;
da[9] := byte(len);
da[10] := byte();
end;function get_sum(var da:array of byte; len:integer):integer;
var
sum:integer;
i:integer;
begin
sum := 0;
for i:=0 to len+3 do
sum := sum + da[YINDAO_LEN +i];
da[YINDAO_LEN + len + 4 + 0] := (sum shr 8) and $ff;
da[YINDAO_LEN + len + 4 + 1] := sum and $ff;
result := YINDAO_LEN + 4 + da[9] + 2;
end;
function HEXtoBCD8(hex_data:byte):dword;
var
bcd_data:dword;
temp:byte;
begin
temp:=hex_data mod 100;
bcd_data:=dword(hex_data) div 100 shl 8;
bcd_data:=bcd_data or temp div 10 shl 4;
bcd_data :=bcd_data or temp mod 10;
result:= bcd_data;
end;procedure show_result(var inbuff:array of byte; id:byte; :char);
var
sum:integer;
begin
sum := inbuff[3] + inbuff[4] + inbuff[5]+ inbuff[6];
if
(inbuff[0]= byte('A')) and
(inbuff[1]= byte('C')) and
(inbuff[2]= byte('K')) and
(inbuff[3]= id ) and
(inbuff[4]= byte('1')) and //
(inbuff[5]= byte()) and
(inbuff[6]= byte(OK)) and
(sum = ((inbuff[7] shl 8) or inbuff[8]))
then
ShowMessage('ok!')
else ShowMessage('send ng!');
end;
[00000000] IRP_MJ_WRITE Length: 0032, Data: 01 00 00 00 46 00 ……
正确的应该这样:
[00000000] IRP_MJ_WRITE Length: 0032, Data: 1B 24 53 5A 4C 47 ……
还望指教!
2.你用的delphi是什么版本的?如果是2007以上,要改上面所有的char为ansichar(我在bcb6下,测试了fill_head及HEXtoBCD8与BCB的一样结果)
1B 24 53 5A 4C 47 ...
呵呵,是我没有KEY那个procedure fill_head(var da:array of byte;id:char; :char; len:integer)中的VAR导致错误。