准备向串口发送数据二进制代码如下:0101010110101010000000010000000100000010一个五个字节的数据:十六进制代码为0x55,0xaa,0x01,0x01,0x02;
串口下面是一个dos程序.它是一个字节一个字节地读.如它读了第一个字节为0x55就再读第二个字节,看是不是等于0xaa,如果正确,就取第三个字节和第四个字节.
但是我使用spcomm(delphi)时,发送数据是按word来发送.我把它组合写成了:
var
i:integer;
config :boolean;
sum:integer;
begin
sbuf[1] := word(23830);
sbuf[2] := word(257);
sbuf[3] := word(512);
config := True;
begin
for i :=1 to 3 do
Begin
if not fcom.writeCommData(@sbuf[i],1) then //1表示按1个word来发送.
Begin
config := false;
break;
End;
end;
if not config then
messagedlg('发送失败',mterror,[mbyes],0);
End;
请问这错在哪里.请哪位高手贴出相应代码.
www.delphibox.com有spcomm组件下载
串口下面是一个dos程序.它是一个字节一个字节地读.如它读了第一个字节为0x55就再读第二个字节,看是不是等于0xaa,如果正确,就取第三个字节和第四个字节.
但是我使用spcomm(delphi)时,发送数据是按word来发送.我把它组合写成了:
var
i:integer;
config :boolean;
sum:integer;
begin
sbuf[1] := word(23830);
sbuf[2] := word(257);
sbuf[3] := word(512);
config := True;
begin
for i :=1 to 3 do
Begin
if not fcom.writeCommData(@sbuf[i],1) then //1表示按1个word来发送.
Begin
config := false;
break;
End;
end;
if not config then
messagedlg('发送失败',mterror,[mbyes],0);
End;
请问这错在哪里.请哪位高手贴出相应代码.
www.delphibox.com有spcomm组件下载
我只用过VC下面的串口通信,用微软的MSComm32.ocx控件,也没有用过spComm组件,
在www.delphibox.com也上不去。
楼主可以用用MSComm32.ocx,这方面网上的资料很多的。
s1:=chr($55)+chr($aa)+chr($01)+chr($01)+chr($02);
Comm1.WriteCommData(pchar(s1),length(s1));
s1:=chr($55)+chr($aa)+chr($01)+chr($01)+chr($02);
Comm1.WriteCommData(pchar(s1),length(s1));
要不就这样啊
var
sbuf: array[1..3] of byte;
i:integer;
config :boolean;
sum:integer;begin
sbuf[1] :=$55;
sbuf[2] :=$aa;
sbuf[3] := $01;
config := True;
begin
for i :=1 to 3 do
Begin
if not fcom.writeCommData(@sbuf[i],1) then //1表示按1个word来发送.
Begin
config := false;
break;
End;
end;
if not config then
messagedlg('发送失败',mterror,[mbyes],0);
End;end;