开发工具:
文件大小: 418kb
下载次数: 0
上传时间: 2006-02-23
详细说明: Gprs远程监控单机演示unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ScktComp, ComCtrls;type TForm1 = class(TForm) ServerSocket1: TServerSocket; Button1: TButton; Timer1: TTimer; Label10: TLabel; StatusBar1: TStatusBar; Memo1: TMemo; Memo2: TMemo; Label11: TLabel; Label12: TLabel; Label16: TLabel; Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit1: TEdit; CheckBox1: TCheckBox; Edit2: TEdit; Label4: TLabel; Label5: TLabel; GroupBox1: TGroupBox; RadioButton 1: TRadioButton; RadioButton2: TRadioButton; Button2: TButton; Button3: TButton; Button4: TButton; Label6: TLabel; Label7: TLabel; Timer2: TTimer; procedure ServerSocket1Accept(Sender: TObject; Socket: TCustomWinSocket); procedure ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure ServerSocket1ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Timer2Timer(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; ip, Port : string;implementationprocedure TForm1.ServerSocket1Accept(Sender: TObject; Socket: TCustomWinSocket);begin ip := Socket.RemoteAddress; Port := inttostr(Socket.RemotePort); StatusBar1.Panels[0].Text := ‘ 下位机DTU已成功连接!‘; StatusBar1.Panels[1].Text := ‘ 已连接IP及端口:‘+ip+‘:‘+port+‘ 时间:‘+TimeToStr(now);; Button1.Enabled := true;end;procedure TForm1.ServerSocket1ClientRead(Sender: TObject; Socket: TCustomWinSocket);var s, s_hex : string; i : integer;begin s := Socket.ReceiveText; memo2.Lines.Add(‘(TCP)来自: ‘ + Socket.RemoteAddress + ‘:‘+inttostr(Socket.RemotePort) +‘ 接收到:‘+inttostr(length(s))+‘(bytes) 数据如下:‘); if RadioButton1.Checked = true then begin for i:=1 to length(s) do s_hex := s_hex+inttohex(ord(s[i]),2)+ ‘ ‘; // memo2.Lines.Add(s_hex); end else memo2.Lines.Add(s);end;procedure TForm1.Button1Click(Sender: TObject);var i : integer; s_memo, s_hex: String;begin if (memo1.Text = ‘‘)then ShowMessage(‘发送数据不能为空!‘) else try begin if (RadioButton1.Checked = false) then begin for I := 0 to memo1.Lines.Count - 1 do ServerSocket1.Socket.Connections[0].SendText(memo1.lines[i]); //如果多台下位机同时与服务器相连,可选用不同的线程发送,既:Socket.Connections[0] end else begin try s_memo := StringReplace(memo1.text,‘ ‘,‘‘,[rfReplaceAll]); for i := 1 to length(s_memo) div 2 do s_hex := s_hex+char(strtoint(‘+copy(s_memo,(2*i-1),2))); ServerSocket1.Socket.Connections[0].SendText(s_hex); except ShowMessage(‘发送16进制(Hex编码)输入有错!‘); end; end; end; except ShowMessage(‘发送数据失败!‘); end;end;procedure TForm1.FormCreate(Sender: TObject);begin Button1.Enabled := false; ServerSocket1.Service := ServerSocket1.Socket.LocalAddress; ServerSocket1.Active := true; StatusBar1.Panels[0].Text := ‘ 上位机TCP侦听端口:5050‘; memo1.Clear; memo2.Clear; Label11.Caption := DateToStr(now);end;procedure TForm1.Button2Click(Sender: TObject);begin Button1.Enabled := false; ServerSocket1.Active := false; ServerSocket1.Service := ServerSocket1.Socket.LocalAddress; ServerSocket1.Port := StrToInt(edit1.Text); ServerSocket1.Active := true; StatusBar1.Panels[0].Text := ‘ 上位机TCP侦听端口:‘+edit1.Text;end;procedure TForm1.CheckBox1Click(Sender: TObject);begin if CheckBox1.Checked = true then begin Label4.Enabled := false; Label5.Enabled := false; edit2.Enabled := false; Timer1.Enabled := true; Timer1.Interval := strtoint(edit2.Text); end; if CheckBox1.Checked = false then begin edit2.Enabled := true; Timer1.Enabled := false; Label4.Enabled := true; Label5.Enabled := true; end;end;procedure TForm1.Timer1Timer(Sender: TObject);begin if (memo1.Text <> ‘‘) and (Button1.Enabled = true) then Button1.Click;end;procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);begin StatusBar1.Panels[0].Text := ‘ 下位机TCP连接已断开!‘; StatusBar1.Panels[1].Text := ‘‘;end;procedure TForm1.Button3Click(Sender: TObject);begin close;end;procedure TForm1.Button4Click(Sender: TObject);begin memo1.Clear; memo2.Clear;end; ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.