
This directory includes the example program that shows you how to control 
NPort's ports with 'TCP Socket' mode.

To test the program, you should first set the NPort testing port to 'TCP Server' 
mode, otherwise, the example program may not function as expected. Please refer 
to the NPort User's Manual for configuration instructions.

Be aware that you need to install TCP/IP development tools/libraries on the 
system you are using.


==============================================
Requirements of developing NPort secure driver
==============================================
NPort's SSL function is based on OpenSSL version 0.9.8a.

If you want to develop your own secure applications, please download the source 
file "openssl-0.9.8a.tar.gz" from http://www.openssl.org/source/.

On Linux platform, you have to link SSL library and include <openssl/ssl.h> in 
your source code. For detailed information, please reference the "INSTALL" file 
in "openssl-0.9.8a.tar.gz".

On Win32 platform, you have to link "libeay32.lib","ssleay32.lib" and include 
<openssl/ssl.h> in your source code. For detailed information, please reference 
the "INSTALL.W32" file in "openssl-0.9.8a.tar.gz".

==============================================
Requirements of developing NPort IPv6 driver
==============================================
On Win32 platform, if you are using Microsoft Visual Studio 6.0,
you must install Microsoft Plateform SDK October 2002,
and run it's command "Register PSDK Direcotry with Visual Studio".
If you are using Microsoft Visual Studio 2005, IPv6 has been already supported.

On Linux or UNIX plateform, see the plateform's description about IPv6 support.

=======================================
TCP Socket Library Macro definition
=======================================
1. SSL_ON
   Turn on SSL secure mode.
    
2. SSL_VER2 , SSL_VER3
   You can choose which version of SSL library you want to use. If you do not 
   define any of the following macro's, the APIs in the library will support 
   both SSLv2 and SSLv3 by default.

   SSL_VER2 - use SSL version 2 to connect with NPort.
   SSL_VER3 - use SSL version 3 to connect with NPort.
   
3. IPV6_ON
   Turn on IPv6 support. 
    
=======================================
TCP Socket Library function description
=======================================
1. ssio_init(void)
   Initiates data table before using any TCP Socket functions.
   This function must be called once before calling any other ssio_ APIs, e.g., 
   ssio_open, ssio_close, etc.

   Args:  none
   Return: == 0 : O.K.
           -1   : init fail.

2. ssio_open(char *server_ip, int cmdport, int dataport, int ssl_enable)
   Open NPort serial port.
   Args:  char *server_ip - IP address of NPort
             e.g. 192.168.2.1
          int  cmdport - TCP port number of NPort for command TX/RX
             number range from 1 to 65535.
          int  dataport - TCP port number of NPort for data TX/RX
             number range from 1 to 65535.   
          int  ssl_enable - enable SSL or not
             0: disable SSL, 1: enable SSL  
   Return: >= 0 : file handle ID (open success).
           -1   : No such serial port or serial port is not opened.
           -2   : Bad parameter
           -200 : Socket initialize error
           -201 : Max connection reached
           -300 : SSL initialization error
           -301 : SSL handshake fail

3. ssio_close(SOCKET fd)
   Close NPort serial port
   Args:  SOCKET  fd - file handle ID returned from ssio_open()
   Return: 0 : O.K.

4. ssio_ioctl(SOCKET fd, int baud, int mode)
   Set serial port baud rate and character mode.
   Args:  SOCKET  fd - file handle ID returned from ssio_open()
          int     baud  -  0: 300      1: 600      2: 1200
                           3: 2400     4: 4800     5: 7200
                           6: 9600     7: 19200    8: 38400
                           9: 57600   10: 115200  11: 230400
                          12: 460800  13: 921600  14: 150
                          15: 134     16: 110     17: 75
                          18: 50
          int     mode  - (bit 0,1)   0x00 -   5 data bits
                                      0x01 -   6 data bits
                                      0x10 -   7 data bits
                                      0x11 -   8 data bits
                          (bit 2)     0x00 -   1 stop bit
                                      0x04 -   1.5/2 stop bits
                          (bit 3,4,5) 0x00 -   none parity
                                      0x08 -   odd parity
                                      0x18 -   even parity
                                      0x28 -   mark parity
                                      0x38 -   space parity
   Return: 0    : O.K.
           -203 : Communication with NPort error
           -204 : No such command port 

5. ssio_baud(SOCKET fd, long baud)
   Set port baud rate.
   Args:  SOCKET  fd - file handle ID returned from ssio_open()
          long  baud - desired baud rate
   Return: 0    : O.K.
           -203 : Communication with NPort error
           -204 : No such command port 

6. ssio_flowctrl(SOCKET fd, int mode)
   Set port flow control.
   Args:  SOCKET  fd - file handle ID returned from ssio_open()
          int   mode - bit 0: CTS flow control
                       bit 1: RTS flow control
                       bit 2: Tx XON/XOFF flow control
                       bit 3: Rx XON/XOFF flow control
                       (0 = OFF, 1 = ON)
   Return: 0    : O.K.
           -203 : Communication with NPort error
           -204 : No such command port 

7. ssio_lctrl(SOCKET fd, int mode)
   Set port line control.
   Args:  SOCKET  fd - file handle ID returned from ssio_open()
          int   mode - bit 0: DTR output state
                       bit 1: RTS output state
                       (0 = OFF,  1 = ON)
   Return: 0    : O.K.
           -203 : Communication with NPort error
           -204 : No such command port 

8. ssio_lstatus(SOCKET fd)
   Get port line status.
   Args:  SOCKET  fd - file handle ID returned from ssio_open()
   Return: >=0  : line status: bit 0: DSR 
                               bit 1: CTS
                               bit 2: DCD
                               (1 - ON, 0 - OFF)
           -203 : Communication with NPort error
           -204 : No such command port 

9. ssio_flush(SOCKET fd, int func)
   Flush input/output buffer data.
   Args:  SOCKET  fd - file handle ID returned from ssio_open()
          int   func - 0 : flush input buffer
                       1 : flush output buffer
                       2 : flush input/output buffer
   Return: 0    : O.K.
           -203 : Communication with NPort error
           -204 : No such command port 

10. ssio_write(SOCKET fd, char *buf, int len)
    Write data to NPort serial port.
    Args:  SOCKET  fd - file handle ID returned from ssio_open()
           char  *buf - write out data buffer pointer
           int    len - write out data length
    Return: >= 0 : length of data written
            -1   : write error

11. ssio_read(SOCKET fd, char *buf, int len)
    Read data from NPort serial port.
    Args:  SOCKET  fd - file handle ID returned from ssio_open()
           char  *buf - read data buffer pointer
           int    len - read data buffer length
    Return: >= 0 : length of the data read
            -1   : read error

12. ssio_break(SOCKET fd, int time)
    Send out a break signal.
    Args:  SOCKET  fd - file handle ID returned from ssio_open()
           int   time - break time in milli-second
    Return: 0    : O.K.
            -203 : Communication with NPort error
            -204 : No such command port 

13. ssio_oqueue(SOCKET fd)
    Get size of data quened in output buffer.
    Args:  SOCKET  fd - file handle ID returned from ssio_open()
    Return: >= 0 : output buffer data queue size
            -203 : Communication with NPort error
            -204 : No such command port 

14. ssio_iqueue(SOCKET fd)
    Get size of data quened in input buffer.
    Args:  SOCKET  fd - file handle ID returned from ssio_open()
    Return: >= 0 : input buffer data queue size
            -203 : Communication with NPort error
            -204 : No such command port 
            
15. ssio_breakcnt(SOCKET fd)
    Get break signal count.
    Args:  SOCKET  fd - file handle ID returned from ssio_open()
    Return: >= 0 : break signal count
            -203 : Communication with NPort error
            -204 : No such command port 
            
16. ssio_data_status(SOCKET fd)
    Get port data status.
    Args:  SOCKET  fd - file handle ID returned from ssio_open() 
    Return: = 0 : no error happened  
            > 0 : data status:   bit 0: parity error
                                 bit 1: framing error
                                 bit 2: overrun error
                                 bit 3: overflow error
                                 (1 - ON, 0 - OFF)       
            -203 : Communication with NPort error
            -204 : No such command port
