Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 35 of 37

Native Terminal Emulation Programmer's Guide: Appendix D: Native Sockets

Pages 307 to 320 of 340, from Native Terminal Emulation Programmer's Guide

The original document is the PDF (2.9 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.

For the Intermec 2435

Page 307

D

Native Sockets

The INTERMECR Data Collection Server (DCS) or gateway provides two-way message services for the wireless network but it does not generate the messages. These come from a host program running independently of the DCS or gateway. In fact, the host application runs on a separate physical host. NorandR Native is a simple command language for controlling terminals from a host application. Native sockets enables a host computer running a Native application to communicate with Native terminals through the DCS or gateway via a TCP/IP socket connection. The DCS or gateway supports Native sockets applications for Enterprise Wireless LANt systems. Contact your Intermec Representative for information about the version that provides Native sockets support. If you are converting to the DCS 301 from the 6950 Enterprise Gateway Server, the Wireless Network Access Server, or a serial controller, refer to the DCS 301 User’s Guide (P/N 070284). The manual contains information about modifying your host application to use a socket interface on the DCS 301.

Native Terminal Emulation Programmer’s Guide

287

Page 308

Appendix D, Native Sockets

Communication Basics You can write Native sockets programs for any host or workstation supporting Ethernet and TCP/IP. Initiate communication between the host and the DCS or gateway by configuring both with a common port number. The DCS or gateway uses the designated TCP port number to communicate with the host. You must meet two requirements to set up communication: 1 Configure the terminals and the DCS or gateway with a common host name, which defines the communication sessions. 2 Configure each terminal for the Native data stream and assign it a unique terminal number. As each terminal powers on, the host application opens a unique socket between the DCS or gateway and the host for the terminal. The DCS or gateway keeps an internal table mapping terminals to socket numbers. However, terminal numbers are not available to the application. It must use socket numbers to identify each terminal session. Sockets remain open until the host application closes the session or someone powers the terminal off and then on again, initiating a new session.

288

Native Terminal Emulation Programmer’s Guide

Page 309

Appendix D, Native Sockets

Host Programming Software developers must be familiar with sockets programming to use the Native sockets capability. Intermec Technologies does not provide programming support for internet stream sockets. A good reference on sockets programming is UNIX Network Programming by W. Richard Stevens, ISBN 0-13-94876-1.

Coding the Application See Chapter 6, “Terminal Commands,” for details about the Native command syntax. The application reads and writes directly to the terminals through the DCS or gateway. The Native protocol was originally written for early model INTERMEC controllers that supported serial host communications. Addition of the sockets communication capabilities to the DCS or gateway required use of a modified Native syntax. The following table provides a cross reference. Letter conventions are excerpted from Chapter 6, “Terminal Commands.” All commands terminate with a carriage return <cr>. The DCS or gateway implementation maintains the 1024-character maximum message length limitation documented in Chapter 5, “Data Collection Server and Gateway Commands.” Abbreviated Commands DCS or Gateway Native Syntax

Original Syntax

Command Set Terminal Parameters eDo/c

StDo/c

Sound Audio Annunciator

Bd

WtBd

Write Display *

D/ D/\

WtD/ WtD/\

Reset Terminal g

Gt

Terminal Firmware Version v

DtV

Echo Back Diagnostic

Not supported

DtE/

* All “D/” and “D/\” command extensions are supported except Send Multiple Write Displays, “D//”.

Note: The DCS 301 does not support the DtE (Echo-Back Diagnostic) command in a Native socket host.

Native Terminal Emulation Programmer’s Guide

289

Page 310

Appendix D, Native Sockets

Response Formats Chapter 6, “Terminal Commands,” lists response formats for each command. However, with Native sockets, the terminal numbers are not returned in the response string. For example, a keyboard response to a “Do/x”<cr> command is not in the form “tKrd<cr>”. A response with data from a bar code scanner is “Srbcm<cr>”. See the WtD/ (Write Display) command in Chapter 6. “Terminal Commands,” for descriptions of the parameters.

Error Messages Native command syntax is processed partly by the DCS or gateway, and partly by the terminal. For example, the WtD/ (Write Display) command has an options list o and message content x in the form “Do/x<cr>”. The DCS or gateway processes content preceding the forward slash, and the terminal processes content after the slash. Error responses from the DCS or gateway take the form “?x<cr>”, where x is a numeric error code from 0 to 11. For more information, see “Write Display Errors” on page 185. The terminal’s error responses depend on the specific command. See Chapter 6, “Terminal Commands,” for the command that produced the error.

290

Native Terminal Emulation Programmer’s Guide

Page 311

Appendix D, Native Sockets

Normal Communication Each terminal is identified by its number, and a separate host session is initiated for communication with it. This works regardless of the operating mode of the terminal (terminal emulation or Native).

Coding the Application Code does not need to be designed to handle multiple terminals. If two operators select the same application number, a copy of the application runs for each terminal. Syntax checking is not done on messages transmitted through the DCS or gateway to the terminal. Check the response to an asynchronous command for error notifications from the DCS or gateway.

Syntax for Terminals See Chapter 6, “Terminal Commands,” for details about Norand Native syntax.

WtD/ (Write Display) Command You may use any WtD/ command specified in Chapter 6, “Terminal Commands.” Intermec recommends that you familiarize yourself with these commands before writing any code. For WtD/ commands, the communication driver in the DCS or gateway adds the “W.” If the “W” is included here, the message is rejected. The DCS or gateway allows three additional abbreviated Native commands. The following table shows the commands you can send in Native mode, and provides a description of the normal responses from the terminal. Abbreviated Terminal Commands Feature

Description

“e” or “s” = StD Sends the “St” command. You need to send from the “D” on when issuing this. For example, if you were transmitting to terminal 002, sending “eD” would send “S002D”. The next response would be “CO”. “v” = DtV

Sending a “v” requests the version number of the terminal. That is, sending a “v” issues a DtV command to the terminal. The next message from that terminal should be its software version and terminal number. Internet socket applications return only a version number.

“g” = G or Gt

Sending a “g” resets the terminal. The next message from that terminal should be a power-up message.

Responses received from the terminals follow the responses listed in Chapter 6, “Terminal Commands.” (See this chapter for more information about the format of incoming messages.) In addition, the DCS or gateway can return codes in the terminal’s number field. They are explained under “Native Mode Responses” on the next page.

Native Terminal Emulation Programmer’s Guide

291

Page 312

Appendix D, Native Sockets

Native Mode Responses The DCS or gateway sends the following codes in the terminal number field returned to the application. Codes in Terminal Number Field Command

DCS or Gateway Native Syntax

800

No messages are available for the application. The application can perform housekeeping tasks or go back to waiting for a message (same as NUI_TIMEOUT).

998

The terminal has not passed a message for a predetermined length of time. The application can either ignore the message or act on it. For example, this code could be returned if the terminal is left unattended with the application running (same as NUI_DEAD).

999

The DCS or gateway wants it to terminate. If the application does not terminate within 15 seconds, it is terminated automatically. The application receives this message when the DCS or gateway shuts down or is reset, or if the DCS or gateway detects an error (same as NUI_STOP).

NUI_OK

The DCS or gateway completion was normal.

NUI_STOP

The DCS or gateway wants to terminate (same as 999 code).

NUI_DEAD

The associated terminal has not been passed a message for a predetermined length of time (same as 998 code).

NUI_TIMEOUT

No data available from the application to be read from the DCS or gateway (same as 800 code).

NUI_BAD

A fatal error occurred, which prevents continued execution.

NUI_BOOT

The associated terminal is powered on and can be used to reload data into the terminal. Or, it can be ignored.

Program interfaces return the terminal number and the DCS, gateway, or terminal response. If one of these codes is not set, the field contains the number of the terminal.

Configuration To use Native sockets, you must configure IP, RF communication, and terminal parameters for the DCS, gateway, and terminal. To configure these parameters, refer to the device’s user manual for instructions. When everything is configured correctly and the terminal is powered on, a unique connection (socket) is established between the terminal and your sockets-based Native emulation program. Commands to the terminals must be in the appropriate syntax for their Native mode (see Chapter 6, “Terminal Commands”). The parameter and diagnostic commands in Chapter 5, “Data Collection Server and Gateway Commands,” should be ignored. The following WtD/ (Write Display) command is a sample startup menu for a terminal with viewing screen size set to 16. DBCDNL1H2P15/01 - STDIO TEST 02 - DIRECT TEST

Note that this message does not have the “W” at the beginning, nor does it contain the terminal number. The communication driver in the DCS or gateway adds the “W” and the terminal number.

292

Native Terminal Emulation Programmer’s Guide

Page 313

Appendix D, Native Sockets

Demonstration Program Following is a “C” demonstration host program for Native sockets. The program uses internet sockets to send Native mode syntax to an INTERMEC terminal via the DCS or gateway. The program sends key presses made by a terminal user back to their display. /***************************************************************** ****************************************************************** ** ** ** nui_sock.c ** ** ** ** This is a demo program that uses sockets to send/receive data** ** to/from a Native Mode terminal via the nui_tlnt redirector ** ** application. ** ** ** ** Usage: ./nui_sock <portno> ** ** ** ****************************************************************** *****************************************************************/ #include <stdio.h> #include <errno.h> #ifdef WIN32 #include <windows.h> #define FD_SETSIZE 256 /* set to number of sockets to open */ #include <winsock.h> #else #include <sys/time.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #endif #define VERSION ”1.00” unsigned int listen_fd; unsigned short ipport; char work_buf[1024]; char tdata[4096]; unsigned char param[]=”eD/@ OG00”; int shut_down=0; /* true if program shutdown requested */ struct sockaddr_in cli_addr; struct hostent host_rec; fd_set read_fd_set; fd_set main_fd_set; /* ** linked list management stuff */ struct LIST { unsigned int fdin; unsigned int fdout; char host[32]; char ip[32]; char sic[8]; unsigned short port; unsigned msgcount;

Native Terminal Emulation Programmer’s Guide

293

Page 314

Appendix D, Native Sockets struct LIST *next; }; struct LIST *head; /* first pointer in linked list */ struct LIST *tail; /* last pointer in linked list */ struct LIST *curr; /* always points to current socket pointer */ int main(int argc,char **argv ); int process_port(void); int process_socket(void); int add_fd(unsigned int fd,char *host,char *ip); int delete_fd(unsigned int fd); /*****/ main(argc, argv) int argc; char *argv[]; { struct sockaddr_in serv_addr; int x=0; #ifdef WIN32 WSADATA WsaData; #endif /* ** check the command line arguments */ if(argc < 2) { printf(”\nnui_sock: Wrong number of arguments.”); printf(”\nnui_sock: Usage: nui_sock <portno>\n\n”); fflush(stdout); exit(1); } /* ** get the port number */ strcpy(work_buf,argv[1]); if(strlen(work_buf) < 1) { printf(”\nnui_sock: Invalid portno! Must be numeric and > 0.”); printf(”\nnui_sock: Usage: nui_sock <portno>\n\n”); fflush(stdout); exit(1); } ipport=atoi(work_buf); /* ** set up curses */ for(x=0;x<53;x++) { printf(”\n”); } fflush(stdout); printf(”\nnui_sock: Native Socket Demo - Version %s ”,VERSION); fflush(stdout); /* ** startup sockets */ #ifdef WIN32 x = WSAStartup (0x0101, &WsaData); if(x==SOCKET_ERROR) {

294

Native Terminal Emulation Programmer’s Guide

Page 315

Appendix D, Native Sockets printf(”\nnui_sock: can’t init winsock interface %d.”,errno); fflush(stdout); exit(1); }

#endif /* * Open a TCP socket (an Internet stream socket). */ FD_ZERO(&main_fd_set); if((listen_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror(”\nnui_sock: can’t open local socket”); exit(1); } /* * Fill in the structure ”serv_addr” with the address of the * server that we want to connect with. */ memset(&serv_addr,0x00,sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(ipport); if (bind(listen_fd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { perror(”\nnui_sock: can’t bind to local socket”); exit(1); } listen(listen_fd, 5); /* ** add this fd to our work list so we know when clients connect */ FD_SET(listen_fd, &main_fd_set); /* ** we are connected, lets see if this thing can work */ printf(”\nnui_sock: Listen on Port %d\n”,ipport); fflush(stdout); process_port(); /* ** shut down the system ** (traverse the ”connected” list to shutdown each terminal) */ curr = head; while(curr != NULL) { /* this will shutdown and reset the terminal */ delete_fd(curr->fdin); curr = curr->next; } shutdown(listen_fd,2); close(listen_fd); printf(”\nnui_sock: System Shutdown.”); fflush(stdout); exit(0); } /*****/ /* ** main function loop for handling the socket calls from the

Native Terminal Emulation Programmer’s Guide

295

Page 316

Appendix D, Native Sockets

** cradle server */ int process_port() { int hdrcnt=0; int x=0; int clilen=0; struct timeval seltime; int gotdata=0; struct hostent *host_rec; char host[32]; char *ip; int sockfd; int incount=0; /* ** use the select to see if anything is waiting */ for(;;) { if (shut_down) { break; /* user requested shutdown, so goodbye */ } memcpy((void *)&read_fd_set, (void *)&main_fd_set, sizeof(fd_set)); seltime.tv_usec = 0; seltime.tv_sec = 15; /* 15 second timeout */ gotdata=select(FD_SETSIZE,&read_fd_set,0,0,&seltime); if(gotdata > 0) { /* ** it is a new connection, connect it */ if(FD_ISSET(listen_fd,&read_fd_set)) { clilen = sizeof(cli_addr); sockfd = accept(listen_fd,(struct sockaddr *)&cli_addr,&clilen); if(sockfd < 0) { printf(”\nnui_sock: Accept error. Port=%d (%d)”,ipport,errno); fflush(stdout); } ip=inet_ntoa(cli_addr.sin_addr); host_rec=gethostbyaddr((char *) &cli_addr.sin_addr,4,AF_INET); strcpy(host,host_rec->h_name);

*/ printf(”\nnui_sock: HEARD <%s:%s>”,host,ip); fflush(stdout); FD_CLR(listen_fd,&read_fd_set); add_fd(sockfd,host,ip); /* add the connection to our fd list

/* send terminal control parameters */ strcpy(tdata,param); write(sockfd,tdata,strlen(tdata)); sleep(1); /* Wait, don’t send the next one too fast */ /* send first entry prompt */ sprintf(work_buf,”DBSCQDEL0H16P16/%-16.16s%-16.16s”,”Enter data now:”,” ”);

296

Native Terminal Emulation Programmer’s Guide

Page 317

Appendix D, Native Sockets

/* ** */ strcpy(tdata,work_buf); write(sockfd,tdata,strlen(tdata)); } else { look for an active descriptor and process accordingly

} } return(1); } curr = head; while(curr != NULL) { if(FD_ISSET(curr->fdin, &read_fd_set)) { if(!process_socket()) { /* this will shutdown/reset the terminal */ delete_fd(curr->fdin); curr = NULL; break; } } curr = curr->next; } }

/* ** This function reads data from the socket (response from the ** terminal) and writes to the socket (sends commands to the ** terminal). */ int process_socket() { int datacnt=0; /* ** read the data from the socket */ memset(tdata,0x00,sizeof(tdata)); datacnt=read(curr->fdin,tdata,sizeof(tdata)); if (datacnt < 1) { printf(”\nnui_sock: Bad message. fd=%d, datacnt=%d”,curr->fdin,datacnt); fflush(stdout); return(0); } /* ** we have a data message, process it */ if(tdata[0]==’K’ && tdata[1]==’Q’) /* stop and reset this terminal */ { printf(”\nnui_sock: Terminal requested stop.”); fflush(stdout); return(0); } if(tdata[0]==’K’ && tdata[1]==’X’) {

Native Terminal Emulation Programmer’s Guide

297

Page 318

Appendix D, Native Sockets

/* Stop this application and reset all connected terminals */ printf(”\nnui_sock: Program stop requested.”); fflush(stdout); shut_down = 1; return(0); } if(tdata[strlen(tdata) - 1] == 13) /* don’t forget to strip cr */ tdata[strlen(tdata) - 1] = 0;

/* ** I’m not doing anything with the incomming data but sending it ** back, thus I build my new output message from the input ** message */ sprintf(work_buf,”DBSCQDEL0H16P16/%-16.16s%-16.16s%-16.16s%-16.16s”,”Enter data now:”,” ”,”Previous data:”,&tdata[1]); strcpy(tdata,work_buf); /* ** write the data to the socket */ write(curr->fdin,tdata,strlen(tdata)); return(1); } /* ** This function adds a new socket File Descriptor to our ** linked list of connected FDs (which are actually terminals). */ int add_fd(unsigned int fd, char *host, char *ip) { struct LIST *ptr; ptr = (struct LIST *)malloc(sizeof(struct LIST)); if(ptr == NULL) { printf(”\nnui_sock: add_fd Cannot allocate buf ptr.”); fflush(stdout); return(-1); } ptr->fdin = fd; strcpy(ptr->ip,ip); strcpy(ptr->host,host); ptr->next = NULL; if(tail != NULL) { tail->next = ptr; tail=ptr; } else { head = ptr; tail = ptr; } FD_SET(fd, &main_fd_set); return(1); } /* ** This function removes a socket File Descriptor from our ** linked list and sends a reset to the terminal to shut ** it down properly through the nui_tlnt program. */

298

Native Terminal Emulation Programmer’s Guide

Page 319

Appendix D, Native Sockets int delete_fd(unsigned int fd) { struct LIST *before; struct LIST *ptr; int foundflag = 0; ptr = head; before = NULL; while(ptr != NULL) { if(ptr->fdin == fd) { foundflag = 1; break; } before = ptr; ptr = ptr->next; } if(!foundflag) { printf(”\nnui_sock: delete_fd Tried to delete an fd not in list!”); fflush(stdout); return(-1); } FD_CLR(ptr->fdin, &main_fd_set); if(ptr->fdin > 0) { /* ** sending a ’g’ will reset the terminal and close connection ** with nui_tlnt */ tdata[0]=’g’; /* reset this radio only */ tdata[1]=0; write(ptr->fdin,tdata,strlen(tdata)); sleep(1); /* don’t shutdown the socket too fast */ shutdown(ptr->fdin,2); /* shutdown this socket connection*/ close(ptr->fdin); } if(before != NULL) { before->next = ptr->next; if(ptr == tail) { tail = before; } } else { head = ptr->next; if(head == NULL) tail = NULL; } free(ptr); return(1); } /* ***** last line of program */

Native Terminal Emulation Programmer’s Guide

299

Page 320

Appendix D, Native Sockets

300

Native Terminal Emulation Programmer’s Guide