串口传输问题,请教. ( 积分: 17 )

  • 主题发起人 主题发起人 xiongshao
  • 开始时间 开始时间
X

xiongshao

Unregistered / Unconfirmed
GUEST, unregistred user!
我想通过mscomm传输文件.把声音文件导入,打开了,该怎么传输呀,下面是我写的,一传就关闭程序了...谁有源程序让我看看吧


procedure TForm1.Button2Click(Sender: TObject);

var
i :integer;
FromF: file;
NumRead: Integer;
Buf: array[1..2048] of char;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(FromF, OpenDialog1.FileName);
Reset(FromF, 1); { Record size = 1 }
Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF))
+ ' bytes...');
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
for i:=1 to 2048 do
mscomm1.Output:=buf;
until (NumRead = 0)
end;
CloseFile(FromF);
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var Buf: array[1..2048] of olevariant;
i:integer;
ToF: file;
NumWritten: Integer;
buffer: array[1..2048] of variant ;
begin
for i:=1 to 2048 do
begin
if mscomm1.CommEvent=2 then
begin
buf:=mscomm1.input;

buffer:=buf;
BlockWrite(ToF, Buf,SizeOf(Buf), NumWritten);
end;
分不多了...
 
我想通过mscomm传输文件.把声音文件导入,打开了,该怎么传输呀,下面是我写的,一传就关闭程序了...谁有源程序让我看看吧


procedure TForm1.Button2Click(Sender: TObject);

var
i :integer;
FromF: file;
NumRead: Integer;
Buf: array[1..2048] of char;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(FromF, OpenDialog1.FileName);
Reset(FromF, 1); { Record size = 1 }
Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF))
+ ' bytes...');
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
for i:=1 to 2048 do
mscomm1.Output:=buf;
until (NumRead = 0)
end;
CloseFile(FromF);
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var Buf: array[1..2048] of olevariant;
i:integer;
ToF: file;
NumWritten: Integer;
buffer: array[1..2048] of variant ;
begin
for i:=1 to 2048 do
begin
if mscomm1.CommEvent=2 then
begin
buf:=mscomm1.input;

buffer:=buf;
BlockWrite(ToF, Buf,SizeOf(Buf), NumWritten);
end;
分不多了...
 
帮你顶,看了一下和spcomm的代码有点不一样;
我有spcomm代码
 
大哥,贴出来.参考一下呀...
 
后退
顶部