900-326b webenable ug

20
 Web Enabli ng Y our Device Server   Part Number 900-326 Revis ion B Jul y 2004

Upload: ian-krebs

Post on 04-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 1/20

 

Web Enabling Your Device Server  

Part Number 900-326Revis ion B July 2004

Page 2: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 2/20

Web Enabling Your Device Server ii

Copyright and Trademark

© 2003, Lantronix. All rights reserved. No part of the contents of this book may betransmitted or reproduced in any form or by any means without the written permissionof Lantronix. Printed in the United States of America.

Ethernet is a trademark of XEROX Corporation. UNIX is a registered trademark ofThe Open Group. Windows 95, Windows 98, Windows 2000, Windows NT, andWindows XP are trademarks of Microsoft Corp. Netscape is a trademark of NetscapeCommunications Corporation.

Contacts

Lantronix Corporate Headquarters 15353 Barranca ParkwayIrvine, CA 92618, USAPhone: 949-453-3990Fax: 949-453-3995

Technical Support Phone: 800-422-7044 or 949-453-7198

Fax: 949-450-7226Online: www.lantronix.com/support Email mailto:[email protected] 

Sales Offices For a current list of our domestic and international sales offices, go to the Lantronixweb site at http://www.lantronix.com/about/contact/index.html 

Page 3: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 3/20

Description and Specifications

Web Enabling Your Device Server iii

Contents

Copyright and Trademark _________________________________________________ii 

Contacts ______________________________________________________________ii 1: Overview 1-1 2: Background on Web Servers 2-1 3: Implementation 3-1 4: Creating Web Pages 4-1 5: Creating .COB Files 5-1 6: Downloading .COB Files to the Device Server 6-1 7: Connecting to the Device Server with Java 7-1 8: Summary 8-1 

Page 4: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 4/20

 

Web Enabling Your Device Server 1-1 

11::  OOvveer r vv iieeww Serial devices fit typically into just three basic categories: input-only devices, output-only devices, and input /output devices.

Input-only devices include measurement and monitor devices such as temperaturegauges, weather stations, heart monitors, etc. Output devices include displays (e.g.sign boards).

Input and output devices include controls and interactive devices such as robotics,PLCs, management equipment, terminal sessions.

Typically, an operator or technician interacts with these devices from another hard-wired serial device (a computer or a controller).

With the technological advances of recent years, it is to interact with these devicesfrom a remote location using a web browser over an Ethernet network. Low costhardware exists to convert the RS-232, RS-422, or RS-485 serial port into anEthernet interface, which is accessible by an IP-based application (i.e. a webbrowser) over an IP network from any place in the world. Obtaining access via anapplication to the serial port over a network is called serial tunneling. The serial datais encapsulated into TCP or UDP packets; these travel through any IP-basednetwork. The hardware performing this function is called a Device Server .

Since Device Servers are inherently network-aware, the ability to add functionality(web services, e-mail, network diagnostics) are easily within reach. This papercovers the detailed requirements of adding web services to your serial device.

First, connect the serial device to the network. This requires a Device Server such as

the Lantronix UDS-100 and the Lantronix Device Installer to ease configuration.Follow the documentation to configure the network and serial parameters of thedevice server. Connect the serial port of the Device Server to your serial equipmentusing the appropriate cable and connectors, and connect the Device Server to theEthernet network using a suitable cable.

Next, consider the desired web functionality of the serial device. Device functionalitycannot be changed but you can enhance the user interface. Regardless of thedevice functionality, a method is needed to query or control the device over thenetwork. To perform the required programming, use a browser-supported languagelike Java. To obtain a Java development kit, download one from the SunMicrosystems web site. This is required to develop the web-based application.

 All of the basic functionality and sample code is listed in this paper. (Copy and paste

as needed.)

Page 5: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 5/20

 

Web Enabling Your Device Server 2-1 

22::  BBaacckkggr r oouunndd oonn WWeebb SSeer r vveer r ss The CoBox family of products supports an internal web server used by the webprogrammer for storage and retrieval of documents, images, and Java applets. Thisarticle reviews the concepts and present the methods utilized to program the CoBoxweb server.

Web browsers, such as Microsoft Internet Explorer or Netscape Navigator, requestinformation from web servers by using a protocol known as Hypertext TransferProtocol (HTTP). HTTP allows the transfer of information between two differentcomputers: the browser computer (client) and the HTTP computer server. A clientsupporting HTTP 1.0, has three methods to interact with the server. These methods(GET, HEAD, and POST) are very basic. The GET method retrieves a particulardocument or file. The HEAD method retrieves only the “header” of the document. A

client will use HEAD to check whether a cached copy of the file has been changedsince the last access. POST is typically used with “forms” to send information to theserver. When the server receives data from a POST method, it typically passes thedata to another application for processing by a mechanism referred to as theCommon Gateway Interface (CGI).

Hypertext Markup Language (HTML) documents are static in nature. Programs suchas CGI and PHP typically perform functions on the server to dynamically build HTMLdocuments (e.g. querying a database for the lowest mortgage rate).

The Lantronix CoBox Family (includes the UDS, XPort, and WiPort) will be referred toas the Device Server in this paper. The Lantronix Device Servers support an HTTPserver. This service is used to transfer static documents or files to the requestingweb browser. The typical use of the HTTP server is for unit configuration.

Connecting to the CoBox Device Server brings up the unit’s configuration homepage. Then, the Device Server may be configured by this user-friendly interface.

Page 6: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 6/20

 

Web Enabling Your Device Server 3-1 

33::  IImmpplleemmeennttaatt iioonn The Device Server’s HTTP server has support for GET and HEAD methods. Thissupport is adequate for configuration and file service of help files. It does not supportthe POST method, or any “server side” required processing (i.e. no CGI support).

Customers may add their own web pages to the Device Server HTTP server using atool called web2cob available from Lantronix (discussed later). Customers requiringaccess to the serial port(s) are encouraged to use a Java applet.

Device Server products containing 512KB or more of flash memory support the HTTPserver. The flash memory area is divided into 64KB pages, which are available forweb sites. These areas are called WEB1 – WEB6 (for 512K flash) and WEB14 onthe UDS-100.

When a client makes a GET or HEAD request for a file, the HTTP server process firstlooks in WEB1 for the file. If the file is not found in WEB1, the process will look inWEB2, then WEB3 and so on. When the file is located, it is sent to the client.

The Lantronix configuration web pages are loaded into the highest numbered WEBsection. Since this is the last place the server will look for a file, users may add theirown configuration pages in any lower numbered web area. This way, when a file isrequested, users’ files are searched first.

The HTTP server process must be able to determine if the WEB area contains a validweb site. The web2cob.exe program is designed to create an archive of HTMLdocuments and other web files. Web2cob.exe also inserts a unique number into thearchive. The server process will test the unique number to determine if a valid website is loaded into that section of flash memory.

Note:  Since the flash memory is divided into pages, each web site or .COBfile cannot be larger than 64KB. It is the responsibility of the programmer tonot create files larger than 64KB.

Page 7: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 7/20

 

Web Enabling Your Device Server 4-1 

44::  CCr r eeaatt iinngg WWeebb PPaaggeess Several books and programs exist to help in the creation of HTML documents andJava applets. The details of this subject are beyond the scope of this document.However, an example may help clarify the subject.

To create a simple HTML document, use any text editor. Insert the following textinto the editor, and store the file as t1.html.

<HTML><BODY>Hel l o Wor l d!</ BODY></ HTML>

To test your new creation, open this file using your browser.

Page 8: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 8/20

 

Web Enabling Your Device Server 5-1 

55::  CCr r eeaatt iinngg ..CCOOBB FFii lleess In order to store files on the Device Server’s flash card, they have the correct format.Lantronix provides a utility called web2cob.exe to create the required the archive filefor the web site.

Syntax:

Web2cob. exe / d <di r ect ory> / o <out put _f i l e_name>

Where: “directory” is the directory that contains the files to be archived and“output_file_name” is the name of the archive to be created

Example:

Web2cob / d myf i l es / o web3. cob

To create your own .COB file:

1. From the Command or DOS prompt, create a new directory.

C: > mkdi r \ web

2. Copy the two supplied Lantronix files into the new directory

C: > copy web2cob. exe \ webC: > copy mi met ype. i ni \ web

3. Create a new directory under \web.

C: > mkdi r \ web\ source

4. Copy your HTML documents into \web\source.

C: > copy t 1. ht ml \ web\ sour ce

5. Create a .COB file.

C: > cd \ webC: > web2cob / d source / o web1. cob

6. Verify that the new file is smaller than 64KB.

C: > di r web1. cob

Page 9: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 9/20

 

Web Enabling Your Device Server 5-2

Page 10: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 10/20

 

Web Enabling Your Device Server 6-1 

66::  DDoowwnnllooaaddiinngg ..CCOOBB FFii lleess ttoo tthhee DDeevviiccee SSeer r vveer r  

To load a .COB file into the Device Server, a TFTP client program is required.Several TFTP programs are available that run on Microsoft Windows platforms. Forour example we will use the TFTP client built into Windows 2000, and Windows NT.

To load the .COB file into the Device Server:

1. From a command or DOS prompt on Windows 2000 or NT, enter:

C: > TFTP - i xxx. xxx. xxx. xxx PUT \ web\ web1. cob WEB1

Note: Substitute your Device Server’s IP address for the xxx.xxx.xxx.xxxabove.

2. Access your new web page from any browser using the new URL:

ht t p: / / xxx. xxx. xxx. xxx/ t 1. ht ml

xxx.xxx.xxx.xxx is the IP address of the Device Server.

Page 11: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 11/20

 

Web Enabling Your Device Server 7-1 

77::  CCoonnnneecctt iinngg ttoo tthhee DDeevviiccee SSeer r vveer r  wwii tthh JJaavvaa Writing a Java applet to communicate with a serial device attached to the DeviceServer is very straightforward. However, familiarity with Java programming and aJava compiler are required.

 As with any network application, open a communication channel to the remotedevice. In our example, a socket is opened and and two data streams are created toperform the actual sending and receiving of data.

The following example uses a new Java Class called tcpip. Copy the following codeinto a file called tcpip.java.

i mport j ava. *;i mport j ava. l ang. *;i mport j ava. net . *;i mport j ava. ut i l . * ;i mport j ava. i o. * ;

/ ** Thi s cl ass opens a TCP connecti on, and al l ows r eadi ng and wr i t i ng of byt e

arr ays.*/

publ i c cl ass tcpi p{

pr otect ed Socket s = nul l ;publ i c Dat aI nput St ream di s = nul l ;pr otect ed DataOut put St r eam dos = nul l ;

publ i c tcpi p( I net Address i pa, i nt port ){

Socket s1 = nul l ;t r y { / / Open t he socket

s1 = new Socket ( i pa. getHostAddr ess() , port ) ;}catch (I OExcept i on e) {

System. out . pr i nt l n( "Err or openi ng socket ") ;return;

}s = s1;t r y { / / Cr eate an i nput st r eam

  di s = new DataI nputStr eam( newBuf f eredI nput St r eam( s. getI nput St r eam( ) ) ) ;

}catch( Except i on ex) {

System. out . pr i nt l n( "Err or cr eati ng i nput st r eam") ;}t r y { / / Cr eat e an out put st r eam

  dos = new Dat aOut putSt r eam( newBuf f eredOut put Str eam( s. getOutput St r eam( ) ) ) ;}catch( Except i on ex) {

System. out . pr i nt l n( "Err or cr eat i ng out put st r eam") ;}

}

publ i c synchr oni zed voi d di sconnect ( ){

i f ( s ! = nul l ) {try {

Page 12: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 12/20

 

Web Enabling Your Device Server 7-2

s . c l ose( ) ;}

catch ( I OExcept i on e){}}

}

publ i c synchr oni zed voi d send( byt e[] t emp){

try {dos. wr i t e(t emp, 0, t emp. l engt h) ;dos . f l ush( ) ;

}catch( Except i on ex) {

System. out . pr i nt l n( "Er ror sendi ng dat a : " + ex. t oSt ri ng( ) ) ;}

}

publ i c synchr oni zed voi d send( byte[ ] t emp, i nt l en){

try {dos. wr i t e( t emp, 0, l en) ;dos . f l ush( ) ;

}catch( Except i on ex) {

System. out . pri nt l n( "Er ror sendi ng dat a : " + ex. t oSt ri ng( ) ) ;

}}

publ i c synchr oni zed voi d send( St r i ng gi ven){

/ / WARNI NG: t hi s r out i ne may not pr operl y conver t St r i ngs t o byt esi nt l engt h = gi ven. l ength() ;byte[] r etval ue = new byte[l engt h] ;char[ ] c = new char [ l engt h] ;gi ven. get Char s( 0, l engt h, c, 0) ;f or ( i nt i = 0; i < l ength; i ++) {

retval ue[ i ] = (byte)c [ i ] ;}send( r et val ue) ;

}

publ i c synchr oni zed byte[] r ecei ve( )

{byte[] r etval = new byte[0];

try {whi l e( di s. avai l abl e( ) == 0) ; / * Wai t f or dat a */

}catch ( I OExcept i on e){}try {

retval = new byt e[d i s . avai l abl e() ] ;}

catch ( I OExcept i on e){}try {

di s . read(r etval ) ;}

catch ( I OExcept i on e){}return(retval ) ;

}

publ i c i nt avai l abl e(){

i nt avai l ;

avai l = 0;try {

avai l = di s . avai l abl e( ) ;}

catch ( I OExcept i on e) {}

return(avai l ) ;

Page 13: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 13/20

 

Web Enabling Your Device Server 7-3

}}

 ________________________________________________________________________

Next, create the Text_io class as the application. Copy the following code

into a file called “Text_io.java”.

 ________________________________________________________________________i mpor t j ava. awt . *;i mpor t j ava. awt . event . *;i mpor t j ava. l ang. *;

publ i c cl ass Text _i o ext ends Panel i mpl ement s Runnabl e, Text Li st ener {pr i vat e t cpi p gt p;St r i ng ol dmessage = new St r i ng( "" ) ;

 Text Ar ea i nput _box = new Text Ar ea( "" , 10, 60, 3) ; Text Ar ea out put _box = new Text Ar ea( "" , 10, 60, 3) ; Thread t i mer ;

publ i c Text _i o( t cpi p t p) {gt p = t p;

setLayout ( new Gr i dBagLayout ( ) ) ;Gr i dBagConst r ai nt s c = new Gr i dBagConst r ai nt s( ) ;

c. i nset s = new I nset s( 5, 5, 5, 5) ;set Backgr ound( j ava. awt . Col or . l i ght Gr ay) ;set Si ze( 561, 380) ;

c. gr i dx = 0; c. gr i dy = 2; c. gr i dwi dt h = 1; c. gr i dhei ght =1;

c. wei ght x = 0. 0; c. wei ghty = 0. 0; c. anchor =Gr i dBagConst r ai nts. WEST;

c. f i l l = Gr i dBagConst r ai nt s. NONE;add( ( new Label ( "To Devi ce Ser ver : ( Type Her e- - - >) ") ) , c) ;

/ / i nput _boxi nput _box. addText Li st ener ( t hi s) ;c. gr i dx = 1; c. gr i dy = 2; c. gr i dwi dt h = 3; c. gr i dhei ght =

1;c. wei ght x = 0. 5; c. wei ghty = 0. 0; c. anchor =

Gr i dBagConst r ai nts. CENTER;c. f i l l = Gr i dBagConst r ai nt s. BOTH;add( i nput _box, c) ;

c. gr i dx = 0; c. gr i dy = 4; c. gr i dwi dt h = 1; c. gr i dhei ght =1;

c. wei ght x = 0. 0; c. wei ghty = 0. 0; c. anchor =Gr i dBagConst r ai nts. WEST;

c. f i l l = Gr i dBagConst r ai nt s. NONE;add( ( new Label ( "Fr om Devi ce Ser ver : ") ) , c) ;

c. gr i dx = 1; c. gr i dy = 4; c. gr i dwi dt h = 3; c. gr i dhei ght =1;

c. wei ght x = 0. 5; c. wei ghty = 0. 0; c. anchor =Gr i dBagConst r ai nts. CENTER;

c. f i l l = Gr i dBagConst r ai nt s. BOTH;

Page 14: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 14/20

 

Web Enabling Your Device Server 7-4

add( out put _box, c) ;out put _box. set Edi t abl e( f al se) ;t i mer = new Thr ead( t hi s) ;t i mer . s tar t ( ) ;

}

publ i c voi d r un( ) {i nt i ;byt e[ ] i n;

 Thread me = Thr ead. cur r entThread( ) ;whi l e ( t i mer == me) {

try { Thread. cur r entThread( ) . sl eep( 200) ;

}cat ch ( I nt er r upt edExcept i on e) { }

i f ( ( gt p ! = nul l ) && ( ( i = gt p. avai l abl e( ) ) > 0) ) {i n = gt p. r ecei ve( ) ;

/ * r emove non- pr i nt i ng bytes */f or ( i = 0; i < i n. l engt h; i ++) {

i f ( i n[ i ] < 0x20)

i n[ i ] = 0x20;}out put _box. append( ( new St r i ng( i n) ) ) ;

}}

}

publ i c voi d t ext Val ueChanged( Text Event e) {i nt l en, i ;St r i ng st r = new St r i ng( "" ) ;St r i ng message = i nput _box. getText ( ) ;l en = message. l engt h( ) - ol dmessage. l engt h( ) ;i f ( l en < 0) {

f or ( i = 0; i < - l en; i ++)st r += "\ b";

/ / Syst em. out . pr i nt l n( "Backspace") ;}el se i f ( l en > 0) {

st r = message. subst r i ng( ol dmessage. l engt h( ) ) ;/ / Syst em. out . pr i nt l n( "l en = "+st r . l engt h( ) +" st r =

"+str ) ;}ol dmessage = message;i f ( ( l en ! = 0) && ( gt p ! = nul l ) )

gt p. send( str ) ;}

}

 ________________________________________________________________________Next, create the actual applet that uses the tcpip and Text_io classes. Copy

the following code into a file called “Test.java”.

 ________________________________________________________________________

i mpor t j ava. awt . *;i mpor t j ava. awt . event . *;i mpor t j ava. appl et . Appl et ;

Page 15: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 15/20

 

Web Enabling Your Device Server 7-5

i mpor t j ava. net . *;i mpor t j ava. i o. *;i mpor t j ava. l ang. *;i mpor t j ava. t ext . *;i mport j ava. ut i l . * ;

publ i c cl ass Test ext ends Appl et {st at i c pr i vat e bool ean i sappl et = t r ue;st at i c pr i vat e I net Addr ess ar g_i p = nul l ;st at i c pr i vat e i nt ar g_por t = 0;

publ i c tcpi p gt p = nul l ; ;I net Addr ess r eader _i p = nul l ;i nt por t = 10001;

publ i c voi d i ni t ( ){

gt p = nul l ;r eader _i p = nul l ;por t = 10001;

}

publ i c voi d start ( ){

St r i ng st = new St r i ng( "TCP/ I P connect i on st at us: ") ;set Font ( new Font ( "Di al og", Font . BOLD, 16) ) ;setLayout ( new Gr i dBagLayout ( ) ) ;

Gr i dBagConst r ai nt s c = new Gr i dBagConst r ai nt s( ) ;c. gr i dx = 0; c. gr i dy = 0; c. gr i dwi dt h = 1; c. gr i dhei ght= 1;

c. anchor = Gr i dBagConst r ai nt s. CENTER;c. f i l l = Gr i dBagConst r ai nt s. BOTH;c. i nset s = new I nset s( 5, 5, 5, 5) ;set Backgr ound( Col or . yel l ow) ;

set Si ze( 600, 500) ;

/ * Ei t her get t he I P addr ess f r om t he HTTP ser ver i fwe' r e an appl et , or f r omt he commandl i ne (i f passed) .*/

i f ( i sappl et ) {try{

reader_ip = InetAddress.getByName(getCodeBase().getHost());

}cat ch ( UnknownHost Except i on e) {}

}el se {

r eader _i p = ar g_i p;i f ( ar g_por t ! = 0) {

por t = ar g_por t ;}

}/ * Open a socket t o the Devi ce Ser ver ' s ser i al por t*/

i f ( r eader _i p ! = nul l ) {i f ( gt p == nul l ) {

gt p = new t cpi p( r eader _i p, por t ) ;i f ( gt p. s == nul l ) {

st += "Connect i on FAI LED! " ;

Page 16: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 16/20

 

Web Enabling Your Device Server 7-6

gt p = nul l ;}

}}i f ( gt p == nul l ) {

st += "Not Connect ed" ;add( ( new Label ( st ) ) , c);r et ur n;

}st += "Connect ed" ;add( ( new Label ( st ) ) , c);

/ * You may now per f orm I O wi t h the Devi ce Server vi a* gt p. send( byt e[ ] dat a_out ) ;* byt e[ ] dat a_i n = gt p. r ecei ve( ) ;* f uncti ons.* I n our exampl e we' l l use two Text Boxes whi ch have* been ext ended to handl e I O t o t he Devi ce Ser ver .*Dat a typed i n t he upper t ext box wi l l be sent t o* t he Devi ce Ser ver , and dat a r ecei ved wi l l be

  *di spl ayed i n t he l ower t ext box.

*// ********************************************************// * St ar t of cust om appl i cat i on code *// * ADD YOUR CODE HERE *// ********************************************************/

c. gr i dx = 0; c. gr i dy = 2; c. gr i dwi dt h = 3; c. gr i dhei ght =1;c. anchor = Gr i dBagConst r ai nt s. WEST;add( ( new Text _i o( gt p) ) , c) ;

/ ********************************************************// * End of cust om appl i cat i on code *// ********************************************************/

}

publ i c voi d dest r oy( ){

i f ( gt p != nul l )gt p. di sconnect( ) ;

gt p = nul l ;}

publ i c voi d st op( ) {}

publ i c stati c voi d mai n( St r i ng[ ] ar gs) {Fr ame f r ame = new Fr ame( "TCP/ I P Test " ) ;

f r ame. addWi ndowLi st ener ( new Wi ndowAdapter ( ) {publ i c voi d wi ndowCl osi ng( Wi ndowEvent e) {

Syst em. exi t ( 0) ;}

}) ;i f ( ar gs. l engt h > 0) {

try{ar g_i p = I net Addr ess. getByName( ar gs[ 0] ) ;

}cat ch ( UnknownHost Except i on e) {}

Page 17: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 17/20

 

Web Enabling Your Device Server 7-7

i f ( ar gs. l engt h > 1) {try {

ar g_por t = I nt eger . val ueOf ( ar gs[ 1] ) . i nt Val ue( ) ;}cat ch ( Number For mat Except i on e) {}

}}

 Test ap = new Test ( ) ;f r ame. add( ap) ;ap. i ni t ( ) ;i sappl et = f al se;ap. s tar t ( ) ;f r ame. pack( ) ;f r ame. show( ) ;

}}

 ________________________________________________________________________

In our example we use two TextBoxes, which are in the Text_io class to handle IO toand from the Device Server. Data typed in the upper text box will be sent to theDevice Server, and data received will be displayed in the lower text box.

If you want to use your own code, you’ll need to add your application code at the tag/* ADD YOUR CODE HERE */ which is in the start() routine. You’ll also need toreplace the section of code between the custom code fences. The syntax for thesend and receive functions are listed below. Use gtp.send() to send data to the serialdevice, and gtp.receive() to read data from the serial device.

Syntax:

gt p. send( byt e[ ] ar r ay)byt e[ ] ar r ay = gt p. r ecei ve( )

Now you need to compile the Java source code into class files.

C: > j avac t cpi p. j avaC: > j avac Text_ i o. j avaC: > j avac Test . j ava

To test your Java application:

C: > j ava Test xxx. xxx. xxx. xxx 10001

Where xxx.xxx.xxx.xxx is the IP address of the CoBox or UDS, and 10001 is the TCPport number the CoBox or UDS is listening on. (10001 is the default port number.)

Page 18: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 18/20

Page 19: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 19/20

 

Web Enabling Your Device Server 7-9

3. Create a new .COB file, as described above, and load it into the Device Servervia TFTP.

C: > cd \ webC: > web2cob / d source / o web1. cobC: > TFTP - i xxx. xxx. xxx. xxx PUT \ web\ web1. cob WEB1

4. You can now access your new web page from any browser using the new URL:

ht t p: / / xxx. xxx. xxx. xxx/ t est . ht ml  

Where xxx.xxx.xxx.xxx is the IP address of the Device Server.

Page 20: 900-326B WebEnable UG

8/13/2019 900-326B WebEnable UG

http://slidepdf.com/reader/full/900-326b-webenable-ug 20/20

 

Web Enabling Your Device Server 8-1

88::  SSuummmmaar r yy The CoBox family supports an internal web server that is used for storage andretrieval of documents, images, and Java applets. An experienced web programmercan create custom web pages to interact with any serial device and present theinformation to a user in a user friendly web interface.