在VB中可以
dim b(10) as byte
b(0)=100
b(1)=20
......
b(10)=134
mscommm1.output=b
在delphi中再这样写就会提示
[Error] Unit1.pas(36): Incompatible types: 'OleVariant' and 'Array'
那在delphi中该如何发送字节数组??用的同样都是微软的comm控件。mscomm1.output:='abcde';用8位的单片机接收时会收到97,0,98,0......实际发送的是16字节的字符。
dim b(10) as byte
b(0)=100
b(1)=20
......
b(10)=134
mscommm1.output=b
在delphi中再这样写就会提示
[Error] Unit1.pas(36): Incompatible types: 'OleVariant' and 'Array'
那在delphi中该如何发送字节数组??用的同样都是微软的comm控件。mscomm1.output:='abcde';用8位的单片机接收时会收到97,0,98,0......实际发送的是16字节的字符。
不要用把串口当作文件打开的方式,过于烦琐.
procedure TForm1.FormCreate(Sender: TObject);
begin
sp:=TComm.Create(self);
sp.CommName:='com1';
sp.BaudRate:=9600;
sp.Parity:= None;
sp.ByteSize:=_8;
sp.StopBits:=_1;
sp.StartComm;
end;procedure TForm1.Button1Click(Sender: TObject);
var
b:array[0..9] of shortint;
i:integer;
begin
for i:=0 to 9 do
b[i]:=i+48;
sp.WriteCommData(@b,10);
end;
结果接收到的是48,0,49,0.....
sp.writeCommData(PChar(tempStr),Length(tempStr));