background image

MVI-ADMNET 

 'C' Programmable 

WATTCP API Functions 

Ethernet Module  

 

Page 78 of 90  

ProSoft Technology, Inc. 

December 13, 2006 

 

tcp_listen 

Syntax: 

int tcp_listen( tcp_Socket *sk, word lPort, longword ina, word port, 

dataHandler_t datahandler, word timeout ); 

Parameters: 

sk 

Pointer to the socket that has been initialized. 

lPort 

Local port number. 

datahandler 

Data Handler. Not used in this version. Use NULL for this parameter. 

ina 

Host IP Address. 

port 

Host port number. 

timeout 

Value used to set the period of time to wait for data. 0 is set to indicate no 
timeout. 

Description: 

This function is used for listening to an incoming message. 

port

 is an option 

parameter. Most of the time, port can be set to 0. The API will find an available 
port number for the socket. 

ina

 is a host IP address passed as a longword. 

Function resolve can be used to convert an IP address into a longword-formatted 
variable. 0 can be passed as an 

ina

 value if there is no specific IP Address to 

listen too. 

Example: 

tcp_Socket *socket; 

int port = 5656; 

 

   . . . 

 

tcp_listen(socket, port, 0L, 0, NULL, 0); 

See Also: 

ADM_send_socket

 (page 43) 

Summary of Contents for MVI ADMNET Series

Page 1: ...MVI ADMNET C Programmable Ethernet Module Developer s Guide December 13 2006...

Page 2: ...Technology Inc be responsible or liable for indirect or consequential damages resulting from the use or application of the product Reproduction of the contents of this manual in whole or in part witho...

Page 3: ...Installing and Configuring the Module 26 3 3 1 Using Side Connect Requires Side Connect Adapter MVI71 27 4 UNDERSTANDING THE MVI ADMNET API 31 4 1 API Libraries 31 4 1 1 Calling Convention 31 4 1 2 He...

Page 4: ...59 ip_timer_init 60 ip_timer_expired 61 set_timeout 62 chk_timeout 63 sockerr 64 sockstate 65 gethostid 66 ADMNET API Release Socket Functions 67 sock_exit 67 sock_abort 68 sock_close 69 ADMNET API S...

Page 5: ...le and the PLC refer to MVI ADM Developer s Guide This document assumes the reader is familiar with software development in the 16 bit DOS environment using the C programming language This document al...

Page 6: ...s Digital Mars and Borland compilers User programs may be executed automatically by loading them from either the CONFIG SYS file or an AUTOEXEC BAT file In addition to MVI ADMNET ADMTCP CFG is require...

Page 7: ...code and sample ladder logic Null Modem Cable Mini DIN to DB 9 Cable 2 2 Jumper Locations and Settings Each module has three jumpers Setup Port 1 Port 2 2 2 1 Setup Jumper The Setup jumper located at...

Page 8: ...Page 8 of 90 ProSoft Technology Inc December 13 2006 2 3 Connections 2 3 1 MVI ADMNET Communication Ports The MVI ADMNET module has three physical connectors two application ports and one debugging po...

Page 9: ...ed compilers 3 1 1 Configuring Digital Mars C 8 49 The following procedure allows you to successfully build the sample ADM code supplied by Prosoft Technology using Digital Mars C 8 49 After verifying...

Page 10: ...ck Project Rebuild All from the Main Menu to create the exe file The status of the build will appear in the Output window Porting Notes The Digital Mars compiler classifies duplicate library names as...

Page 11: ...executable file will be located in the directory listed in the Compiler Output Directory field If it is blank then the executable file will be located in the same folder as the project file The Projec...

Page 12: ...the Platform field choose DOS 5 In the Project Settings choose Release if you do not want debug information included in your build 6 Click Next 7 Select the first source file necessary for the project...

Page 13: ...C Programmable Ethernet Module ProSoft Technology Inc Page 13 of 90 December 13 2006 11 Choose Libraries lib from the List Files of Type field to view all library files 12 Click Next 13 Add any defin...

Page 14: ...2006 15 The Project window should now contain all the necessary source and library files as shown in the following window 16 Click Project Settings from the Main Menu 17 These settings were set when t...

Page 15: ...directory information as required by your project s directory structure 19 If the fields are left blank then it is assumed that all of the files are in the same directory as the project file The outpu...

Page 16: ...ge 16 of 90 ProSoft Technology Inc December 13 2006 21 Click Code Generation from the Topics field and ensure that the options match those shown in the following screen 22 Click Memory Models from the...

Page 17: ...ProSoft Technology Inc Page 17 of 90 December 13 2006 23 Click Linker from the Topics field and ensure that the options match those shown in the following screen 24 Click Packing Map File from the To...

Page 18: ...of the Directories tab that is C ADM_TOOL_MVI SAMPLES The Project Settings window can be accessed by clicking Project Settings from the Main Menu Porting Notes The Digital Mars compiler classifies dup...

Page 19: ...re assumes that you have successfully installed Borland C 5 02 on your workstation Downloading the Sample Program The sample code files are located in the ADM_TOOL_MVI ZIP file This zip file is availa...

Page 20: ...rnet Module Page 20 of 90 ProSoft Technology Inc December 13 2006 4 Click OK The Project window appears 5 Click Project Build All from the Main Menu to create the exe file The Building ADM window appe...

Page 21: ...ect Options window can be accessed by clicking Options Project Menu from the Main Menu Creating a New Borland C 5 02 ADM Project 1 Start Borland C 5 02 and then click File Project from the Main Menu 2...

Page 22: ...ated and press the Delete key Click Yes to delete the cpp file 9 Right click on the exe file listed in the Project window and choose the Add Node menu selection The following window appears 10 Click s...

Page 23: ...Ethernet Module ProSoft Technology Inc Page 23 of 90 December 13 2006 12 Choose Libraries lib from the Files of Type field to view all library files 13 The Project window should now contain all the ne...

Page 24: ...Environment Ethernet Module Page 24 of 90 ProSoft Technology Inc December 13 2006 14 Click Options Project from the Main Menu 15 Click Directories from the Topics field and fill in directory informat...

Page 25: ...16 Double click on the Compiler header in the Topics field and choose the Processor selection Confirm that the settings match those shown in the following screen 17 Click Memory Model from the Topics...

Page 26: ...image so that files may be deleted and added to the image without resulting in wasted space To install WINIMAGE unzip the winima40 zip file from the CD ROM in a sub directory on your PC running Win9x...

Page 27: ...stalling and configuring the module is to define whether the block transfer or side connect interface will be used If the block transfer interface is used remove the Compact Flash Disk from the module...

Page 28: ...d for a port s commands they are still reserved and should only be used for that purpose The read and write data contained in the last set of files possess the data transferred between the module and...

Page 29: ...ion parameters are set correctly the module s application LED OK LED should remain off and the backplane activity LED BP ACT should blink rapidly Refer to the Diagnostics and Troubleshooting of this m...

Page 30: ...MVI ADMNET C Programmable Setting Up Your Development Environment Ethernet Module Page 30 of 90 ProSoft Technology Inc December 13 2006...

Page 31: ...ides general information pertaining to application development for the MVI ADMNET module 4 1 API Libraries Each API provides a library of function calls The library supports any programming language t...

Page 32: ...another thread will be blocked until the previous thread has completed the function Note The MVI ADM DOS 6 XL operating system has a system tick of 5 milliseconds Therefore thread scheduling and timer...

Page 33: ...format 4 4 1 ADM Interface Structure The ADMNET interface structure functions mainly as a protocol UDP and TCP socket Pointers to structures are used so that the API can access lower level Ethernet co...

Page 34: ...t packet sent word window other guy s window int datalen number of bytes of data to send must be signed int unacked unacked data byte cwindow Van Jacobson s algorithm byte wwindow word vj_sa VJ s alg...

Page 35: ...bits longword usertimer ip_timer_set ip_timer_timeout dataHandler_t dataHandler eth_address hisethaddr peer s ethernet address longword hisaddr peer s internet address word hisport peer s UDP port lon...

Page 36: ...MVI ADMNET C Programmable Understanding the MVI ADMNET API Ethernet Module Page 36 of 90 ProSoft Technology Inc December 13 2006...

Page 37: ...API functions is supported for all of the modules in the MVI family The API library routines are categorized according to functionality as shown in the following table Function Category Function Name...

Page 38: ...on ADM_receive_socket Receive socket according to name assigned throughout initialization process as either UDP or TCP This function also takes care of opening socket connection Receive Socket ADM_rec...

Page 39: ...and dynamically generates a set of sockets according to numSK and assigns portNum buffSize then names each socket that the application will use in subsequent functions This function must be called bef...

Page 40: ...ocket must be used before this function IMPORTANT After the API has been opened ADM_close_sk should always be called for closing the socket 0 0 0 0 passes as ServerIPAddress to open socket as a server...

Page 41: ...ket Functions ADM_release_sockets Syntax int ADM_release_sockets void Parameters none Description This function is used by an application to release all sockets created by ADM_init_socket IMPORTANT Af...

Page 42: ...escription This function is used by an application to close socket opened by ADM_open_sk IMPORTANT After a socket has been opened this function should always be called to close socket but not release...

Page 43: ...hat will be sent to the ServerIPAddress sendLen Number of data specified to send ServerIPAddress IP address that will be used to send data to protocol Specified protocol to send over Ethernet USE_TCP...

Page 44: ...viously open using ADM_open_sk Return Value SK_SUCCESS API has successfully open socket SK_PROCESS_SOCKET Open process is still in SK_NOT_FOUND API could not find an initialize socket with the name pa...

Page 45: ...to a buffer to hold data that will be receive by the API readLen Length of data received by the API protocol Specified protocol to receive over Ethernet USE_TCP or USE_UDP Description To simplify a p...

Page 46: ...n return with client IP Description This function receives socket after ADM_open_sk is used skName must be a valid name that has been initialized with ADM_init_socket Return Value SK_SUCCESS Socket is...

Page 47: ...re of type ADMNETVERSIONINFO Description ADM_GetVersionInfo retrieves the current version of the ADMNET API library The information is returned in the structure admnet_verinfo The ADMVERSIONINFO struc...

Page 48: ...meters skName Name of the socket that has been initialized and used to receive data Description ADM_is_sk_open tests if connection is still valid or not Return Value SK_SUCCESS Socket is successfully...

Page 49: ...brary routines are categorized according to functionality as shown in in the following table Function Category Function Name Description Initialize Socket sock_init TCP IP system initialization tcp_ti...

Page 50: ...sent sock_flushnext Call before write the data out to make sure that after write the data out to the socket buffer will be flushed sock_puts Put string onto the buffer Send Socket sock_putc Put a char...

Page 51: ...red TCP IP configuration file and prepare a variable Return Value SK_SUCCESS API has successfully initialized variables SK_PORT_NOT_ALLOW API does not allow port number used SK_CANNOT_ALLOCATE_MEMOR Y...

Page 52: ...the ADMNET API System Functionality calls tcp_tick Syntax int tcp_tick sock_type skType Parameters skType Current socket Type or NULL for all sockets Description This function is used by an applicati...

Page 53: ...version Use NULL for this parameter Description This function opens a TCP socket connection to a host machine using parameters passed to it IPort is an option parameter Most of the time IPort can be...

Page 54: ...rameter Description This function opens a TCP socket connection to a host machine using parameters passed to it For this function there is no wait to resolve the IP address IPort is an option paramete...

Page 55: ...version Use NULL for this parameter Description This function opens a UDP socket connection to a host machine using parameters passed to it IPort is an option parameter Most of the time IPort can be...

Page 56: ...ription This function opens a UDP socket connection to a host machine using parameters passed to it For this function there is no wait to resolve the IP address that passes the function IPort is an op...

Page 57: ...nology Inc Page 57 of 90 December 13 2006 resolve Syntax longword resolve char name Parameters name String IP Address Description This function converts a string IP Address into a long Return Value lo...

Page 58: ...that will be used to setup socket mode mode The following is the available mode TCP_BINARY 0 default TCP_ASCII 1 tread as an ascii data UDP_CRC 0 checksum enable UDP_NOCRC 2 checksum disable TCP_NAGL...

Page 59: ...d Syntax int sock_established sock_type skType Parameters skType Current socket Type that will be used to check the connection Description This function is used check if the socket has been establishe...

Page 60: ..._init Syntax void ip_timer_init sock_type skType word second Parameters skType Current socket Type that will be used to check the connection second Number of second to set the timer 0 mean no timer ou...

Page 61: ..._timer_expired Syntax word ip_timer_expired sock_type skType Parameters skType Current socket Type that will be used to check the connection Description This function is used check if the timer has be...

Page 62: ...Page 62 of 90 ProSoft Technology Inc December 13 2006 set_timeout Syntax longword set_timeout word seconds Parameters seconds Number of second to set the timer Description This function is used set th...

Page 63: ...December 13 2006 chk_timeout Syntax word chk_timeout longword timeout Parameters timeout Number of timeout return from set_timerout Description This function is used check if the time is out Return Va...

Page 64: ...sockerr sock_type skType Parameters skType Current socket Type that will be used to check the connection Description This function returns ASCII error message if there is any Otherwise NULL is return...

Page 65: ...2006 sockstate Syntax char sockstate sock_type skType Parameters skType Current socket Type that will be used to check the connection Description This function returns ASCII message indicating current...

Page 66: ...ProSoft Technology Inc December 13 2006 gethostid Syntax char gethostid void Parameters None Description This function returns value of the IP address in host format Return Value String IP Address Ex...

Page 67: ...NET API Release Socket Functions This section describes the ADMNET API Release Socket Functions sock_exit Syntax void sock_exit void Parameters None Description This function is used by an application...

Page 68: ...sock_abort Syntax void sock_abort sock_type skType Parameters skType Current socket Type that will be used to abort the connection Description This function is used abort a connection This function is...

Page 69: ...ose Syntax void sock_close sock_type skType Parameters skType Current socket Type that will be used to close the connection Description This function is used to permanently close a connection This fun...

Page 70: ...will be used to send data data Pointer to a buffer that contains data that will be sent to a server len Length of the data specified to send Description This function writes data to the socket being...

Page 71: ...o a buffer that contains data that will be sent to a server len Length of data specified to send Description This function writes data to the socket being passed to the function The function will not...

Page 72: ...eters skType Current socket that will be used to flush all the data out of the buffer Description This function is used to flush all the data that is still in the buffer out to the socket This functio...

Page 73: ...shnext sock_type skType Parameters skType Current socket that will be used to flush all the data in the buffer out Description This function is used after the write function is called to ensure that t...

Page 74: ...e Socket that will be used to put string data to data Pointer to the string that will be sent Description This function sends a string to the socket Character new line n will be attached to the end o...

Page 75: ...sock_type skType byte character Parameters skType Socket that will be used to get string data from character A character that is used Description This function is used to put one character at a time t...

Page 76: ...t that will be used to receive data data Pointer to a buffer that contains data that is received len Length of the data specified to receive Description This function reads data from the socket being...

Page 77: ...to a buffer that contains data that is received to a server len Length of data specified to receive Description This function reads data to the socket being passed to the function The function will n...

Page 78: ...st port number timeout Value used to set the period of time to wait for data 0 is set to indicate no timeout Description This function is used for listening to an incoming message port is an option pa...

Page 79: ...o get string data from data Pointer to the string return len Specified length for the function to get the string Description This function is used for obtaining a string from the socket The len parame...

Page 80: ...ck_getc Syntax int sock_getc sock_type skType Parameters skType Socket that will be used to get string data from Description This function gets one character at a time from the socket Return Value Cha...

Page 81: ...ax int sock_dataready sock_type skType Parameters skType Current socket that will be used to check if data is ready to be read Description This function is used check if there is data ready to be read...

Page 82: ...ameters String Array of character string Description This function is used to strip out carriage return and line feed If there are more than one carriage return or line feed the first one will be repl...

Page 83: ...ng Array of character string IP Decimal representation of IP address Description This function builds ASCII representation of an IP address with a user supply string from decimal representation of the...

Page 84: ...ecember 13 2006 inet_addr Syntax longword inet_addr char String Parameters String Array of character string Description This function converts string dot address to host format Return Value Host IP ad...

Page 85: ...cessor and user data files as viewed through the processor configuration software and LED patterns on the processor 6 Details about the serial devices interfaced An after hours answering system allows...

Page 86: ...31 3 programming languages C for example and not furnished by ProSoft d improper installation unauthorized repair or modification e improper testing or causes external to the product such as but not l...

Page 87: ...TION IN CONTRACT OR TORT INCLUDING NEGLIGENCE AND STRICT LIABILITY SUCH AS BUT NOT LIMITED TO LOSS OF ANTICIPATED PROFITS OR BENEFITS RESULTING FROM OR ARISING OUT OF OR IN CONNECTION WITH THE USE OR...

Page 88: ...MVI ADMNET C Programmable Support Service Warranty Ethernet Module Page 88 of 90 ProSoft Technology Inc December 13 2006...

Page 89: ...Project 19 Building an Existing Digital Mars C 8 49 ADM Project 10 C Calling Convention 31 chk_timeout 63 Configuring Borland C 5 02 19 Configuring Digital Mars C 8 49 9 Connections 8 Creating a New...

Page 90: ...ck_gets 79 80 sock_init 51 67 sock_mode 58 sock_putc 74 75 sock_puts 74 75 sock_read 76 77 sock_write 70 71 sockerr 64 sockstate 65 Support Service Warranty 85 T tcp_listen 78 tcp_open 53 tcp_open_fas...

Reviews: