📄 unit1.~pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
txtReceive: TEdit;
Button1: TButton;
OpenDialog1: TOpenDialog;
txtTransfer: TEdit;
Button2: TButton;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
txtSize: TEdit;
txtName: TEdit;
txtLen: TEdit;
Button3: TButton;
rdCOM: TRadioGroup;
btnOpenPort: TButton;
ComboBox1: TComboBox;
Label4: TLabel;
Edit1: TEdit;
Button4: TButton;
Term: TMemo;
Function PortSet():Boolean;
Procedure RefreshStatus(SxLen:LongInt; SfLen:LongInt; SFname:PChar);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure btnOpenPortClick(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses FtProc,PComm;//声明
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
begin
if not OpenDialog1.Execute then exit;
lstrcpy(GxFname,PChar(OpenDialog1.FileName));
txtTransfer.Text := OpenDialog1.FileName;
//指定各项须使用的变量
GftCancel := False;
GProtocol := Combobox1.ItemIndex;
GDirection := FT_XMIT; //指定传输的动作
TFtProc.Create(false); //线程建立并执行
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GftCancel := False;
GProtocol := Combobox1.ItemIndex;
GDirection := FT_RECV; //指定接收的动作
TFtProc.Create(false); //线程建立并执行
end;
//以下是状态显示的回调函数
Procedure TForm1.RefreshStatus(SxLen:LongInt; SfLen:LongInt; SFname:PChar);
begin
//文件大小
txtSize.Text := IntToStr(SfLen);
//文件名称
txtName.Text := StrPas(SFName);
//已传输的文件位元组数
txtLen.Text := IntToStr(SxLen);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
sio_Close(Port);
//关闭程序
Application.Terminate;
end;
procedure TForm1.btnOpenPortClick(Sender: TObject);
var
Ret:Integer;
begin
//开启通讯端口
Port := rdCom.ItemIndex+1; //指定通讯端口
Ret := sio_Open(Port);
If ret <> SIO_OK Then
begin
ShowMessage('打开通讯端口错误');
sio_close (Port);
Exit;
end;
If Not PortSet() Then //参数设定
begin
sio_close(Port);
ShowMessage('通讯端口参数设定发生错误');
Exit;
End;
//降低DTR及RTS的电压
ret := sio_DTR(Port, 0);
ret := sio_RTS(Port, 0);
end;
//以下是通讯参数的函数实现
Function TForm1.PortSet():Boolean;
var
mode,Hw,Sw,ret:LongInt;
begin
//参数设定副程序
{Baud rate 115200
Data 8 bit
Parity none
Stop 1 bit
Flow control hardware //需要流控制
Character pacing 0 ms
Line pacing 0 ms
}
mode := P_NONE Or BIT_8 Or STOP_1;
Hw := 0 ; //没有硬件流量控制
Sw := 0 ; //没有软件流量控制
Result := False ;
//指定必要的参数
ret := sio_ioctl(Port, B115200, mode); //Setting
If ret <> SIO_OK Then
begin
ShowMessage('设定时发生错误');
Exit;
end;
//设定流量控制
ret := sio_flowctrl(Port, Hw or Sw); //Flow Control
If ret <> SIO_OK Then
begin
ShowMessage('流量设定时发生错误');
Exit;
end;
Result := True;
End;
procedure TForm1.Button4Click(Sender: TObject);
var s: string;
i: integer;
begin
s:='abcdefg';
for i := 1 to length(s) do
begin
sio_putch(1,Integer(s[i]));
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -