雪
雪球
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用mscomm控件进行串口的操作,选择inputmode为1 - comInputModeBinary,发送十六进制如下:
Function outbox(const str:string):string; //输出数据打包 (固值输出,
//输出参数和读数据命令)
var
datastr:array of string;
n:byte;
i,j:integer;
instr:string;
outstr:string;
begin
n:=length(str);
n:=n div 2;
setlength(datastr,n+3);
datastr[0]:='FF'; //起始符
datastr[1]:='FE'; //设备地址
datastr[2]:='FE';
j:=0;
for i:=3 to n+2 do
begin
datastr:=copy(str,j*2+1,2);
j:=j+1;
end;
//datastr[n+3]:='00';
outstr:='';
for i:=0 to n+2 do
begin
[red]outstr:=outstr+chr(strtoint('$'+datastr));[/red]
end;
result:=outstr;
end;
发送数据时数据丢失,会出现这样的问题
发送:FF FE FE 04 04 00 2C 06 08 30 12 45 00 00 00 00 01 00 01 00 00 00 00 01 01 00 01 01 00 01 01 01 01 01 01 01 01 01 01 01 01 00 01 00 01 00 01 03 E8 AF 00
这组数据接收是正确的,但是如果发送:FF FE FE 04 04 00 2C 06 08 30 12 46 00 00 00 00 01 00 01 00 00 00 00 01 01 00 01 01 00 01 01 01 01 01 01 01 01 01 01 01 01 00 01 03 E8 00 01 00 01 A3 00,接收就是错误的,接收到的是FF FE FE 04 04 00 2C 06 08 30 12 46 00 00 00 00 01 00 01 00 00 00 00 01 01 00 01 01 00 01 01 01 01 01 01 01 01 01 01 01 01 00 01 03 00 01 00 01 00(E8 和A3数据丢失),这是怎么回事啊?是串口发送数据有问题吗?
Function outbox(const str:string):string; //输出数据打包 (固值输出,
//输出参数和读数据命令)
var
datastr:array of string;
n:byte;
i,j:integer;
instr:string;
outstr:string;
begin
n:=length(str);
n:=n div 2;
setlength(datastr,n+3);
datastr[0]:='FF'; //起始符
datastr[1]:='FE'; //设备地址
datastr[2]:='FE';
j:=0;
for i:=3 to n+2 do
begin
datastr:=copy(str,j*2+1,2);
j:=j+1;
end;
//datastr[n+3]:='00';
outstr:='';
for i:=0 to n+2 do
begin
[red]outstr:=outstr+chr(strtoint('$'+datastr));[/red]
end;
result:=outstr;
end;
发送数据时数据丢失,会出现这样的问题
发送:FF FE FE 04 04 00 2C 06 08 30 12 45 00 00 00 00 01 00 01 00 00 00 00 01 01 00 01 01 00 01 01 01 01 01 01 01 01 01 01 01 01 00 01 00 01 00 01 03 E8 AF 00
这组数据接收是正确的,但是如果发送:FF FE FE 04 04 00 2C 06 08 30 12 46 00 00 00 00 01 00 01 00 00 00 00 01 01 00 01 01 00 01 01 01 01 01 01 01 01 01 01 01 01 00 01 03 E8 00 01 00 01 A3 00,接收就是错误的,接收到的是FF FE FE 04 04 00 2C 06 08 30 12 46 00 00 00 00 01 00 01 00 00 00 00 01 01 00 01 01 00 01 01 01 01 01 01 01 01 01 01 01 01 00 01 03 00 01 00 01 00(E8 和A3数据丢失),这是怎么回事啊?是串口发送数据有问题吗?