|
Delphi Charon 1 Communication Example
An example of simple communication with common TCP/IP device written in Borland Delphi 5 demonstrates simple terminal equipped with NVT (Network Virtual Terminal) support with I/O extensions.
The application is very simple, that is for demonstrative purpose only and you can use it for own applications. Primary focus is on proper solution of TCP/IP parts, including detection of disconnection from server side.
You can control I/O pins by NVT commands in your application (in this example they were used for control of LEDs and for reading of input pins - it covers ON/OFF state of LEDs, too). It's useful, because you don't need to study documentation of NVT commands.
Main form source method description
- procedure ConnectBtnClick(Sender: TObject);
(* this routine handles press of button Connect/Disconnect, opens socket to the target etc. *)
- procedure ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
(* this is a callback method to inform the program that connection was succesful.
it enables some buttons, like Send text etc. and makes Charon to send <AYT> response *)
- procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
(* callback method, that logs TCP/IP errors on the screen *)
- procedure AYTBtnClick(Sender: TObject);
(* method, that sends the request to the Charon *)
- procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
(* callback method that parses received data from TCP/IP connection *)
- procedure WriteLEDBtnClick(Sender: TObject);
(* method providing set of outputs at Charon according to state of the checkboxes *)
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
(* callback method, that is called while program is terminating.
it cleans up the environment, closes socket etc. *)
- procedure ClearBtnClick(Sender: TObject);
(* this method clears the log window *)
- procedure ReadLEDBtnClick(Sender: TObject);
(* method that sends a request for Charon to return state of the input lines *)
- procedure SendBtnClick(Sender: TObject);
(* method that sends the string from input line to the Charon's serial output *)
- procedure FormCreate(Sender: TObject);
(* callback method that initializes form's data *)
- procedure FormDestroy(Sender: TObject);
(* callback method that destroys form's data *)
- procedure CloseBtnClick(Sender: TObject);
(* method that provides terminating of the program *)
- procedure Label4Click(Sender: TObject);
procedure Label6Click(Sender: TObject);
procedure Label7Click(Sender: TObject);
(* these three methods invoke WWW browser or e-mail client to respond to the advertisement user clicks *)
- procedure ClientSocketDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
(* callback method that provides disconnect handling, like setting buttons disabled etc. *)
- procedure HandleButtons( Active : boolean );
(* method that sets enabled/disabled state of many buttons - it simplifies the code by collecting
standard responses to one spot *)
Download of source and binary codes
-
dphi_ch1com_example.zip
\MainForm.pas, MainForm.dfm, Charon.dpr and other resources
\Program\Charon.exe, Charon.ini
|