gprs远程监控单机演示软件

时间:2009-03-15 02:52:39
【文件属性】:

文件名称:gprs远程监控单机演示软件

文件大小:418KB

文件格式:EXE

更新时间:2009-03-15 02:52:39

控件 源码 网络通信类 资源

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; RadioButton1: 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;


网友评论

  • 很好解决了编写GPRS软件的问题。
  • 嗯,挺好的软件,要是有相关代码就好了
  • 是上层数据传输,要是有底层的就更好了