>还有假如我要发送大于128的字节收回的都是0,怎么办?
接受问题,发送时对的.
试一下如下测试程序,在delphi5下是没问题的.
unit u_testcomm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleCtrls, MSCommLib_TLB;
type
TForm1 = class(TForm)
MSComm1: TMSComm;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
//发送
var
buffer_send:Variant;
begin
buffer_send:=VarArrayCreate([0,4], varbyte);
buffer_send[0]:=78;
buffer_send[1]:=56;
buffer_send[2]:=34;
buffer_send[3]:=12;
buffer_send[4]:=4;
mscomm1.output:=buffer_send;
end;
//接受,首先属性InputMode设置成comInputModebinary.
procedure TForm1.MSComm1Comm(Sender: TObject);
var
buffer_receive:Variant;
b:array of byte;
i:integer;
begin
buffer_receive:=mscomm1.input;
setlength(b,MSComm1.InBufferCount);
for i:=low(b) to high(b) do b:=buffer_receive;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MSComm1.CommPort:=2;
MSComm1.Settings:='4800,n,8,1';
MSComm1.RThreshold:=5
// 设触发 MSComm1Comm时间的字节数
if MSComm1.PortOpen=False then MSComm1.PortOpen:=true;
MSComm1.InputMode:=comInputModebinary;
end;
end.