K
kkpp
Unregistered / Unconfirmed
GUEST, unregistred user!
最后一句换为字符串类型的变量就正确,但如何发送十六进制数据??
代码如下:
type bu = array[1..8] of byte;
var //读入客户请求并处理
theStr: string;
theStr2: string;
Buf: TMsg;
Count: Integer;
FromIP: string;
buf4:bu;
status4 : Integer ;
i: integer;
j:string;
buffer4:variant;
begin
If MSComm1.PortOpen = False Then MSComm1.PortOpen := True;
//MSComm1.PortOpen := True;
buf4[1] := $FB;
buf4[2] := $90; //与标志符为1的节点通信
buf4[3] := $1; //数据长度为1
buf4[4] := $81; //设置P1.3的灯亮命令
For i := 5 To 7 do
begin
buf4 := $55;
end;
//校验位的设定
status4 := buf4[3];
For i:= 4 To 7 do
status4 := status4 Xor buf4;
buf4[8] := status4;
//用于测试命令,以后将删除
//Dim s As String
// s = ""
// For i = 1 To 11
// s = s + Hex(Str(buf4(i))) + " "
//' Next i
//' MsgBox ("这是传送前的命令格式" + s)
//'
// '用于测试命令,以后将删除
// MSComm1.Output := buf4[1]; //
// For i:= 1 To 8 do
// MSComm1.Output := buf4; //
buffer4:=$FB;
MSComm1.Output := 'gdsagdsa';//
mSComm1.output := $FB900155;//
代码如下:
type bu = array[1..8] of byte;
var //读入客户请求并处理
theStr: string;
theStr2: string;
Buf: TMsg;
Count: Integer;
FromIP: string;
buf4:bu;
status4 : Integer ;
i: integer;
j:string;
buffer4:variant;
begin
If MSComm1.PortOpen = False Then MSComm1.PortOpen := True;
//MSComm1.PortOpen := True;
buf4[1] := $FB;
buf4[2] := $90; //与标志符为1的节点通信
buf4[3] := $1; //数据长度为1
buf4[4] := $81; //设置P1.3的灯亮命令
For i := 5 To 7 do
begin
buf4 := $55;
end;
//校验位的设定
status4 := buf4[3];
For i:= 4 To 7 do
status4 := status4 Xor buf4;
buf4[8] := status4;
//用于测试命令,以后将删除
//Dim s As String
// s = ""
// For i = 1 To 11
// s = s + Hex(Str(buf4(i))) + " "
//' Next i
//' MsgBox ("这是传送前的命令格式" + s)
//'
// '用于测试命令,以后将删除
// MSComm1.Output := buf4[1]; //
// For i:= 1 To 8 do
// MSComm1.Output := buf4; //
buffer4:=$FB;
MSComm1.Output := 'gdsagdsa';//
mSComm1.output := $FB900155;//